MCPcopy Create free account
hub / github.com/boost-ext/ut / main

Function main

example/parameterized.cpp:31–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29} // namespace boost::inline ext::ut
30
31int main() {
32 using namespace boost::ut;
33
34 /// Language syntax
35 for (auto i : std::vector{1, 2, 3}) {
36 test("args / " + std::to_string(i)) = [i] { // 3 tests
37 expect(that % i > 0); // 3 asserts
38 };
39 }
40
41 /// Alternative syntax
42 "args"_test = [](auto arg) {
43 expect(arg > 0_i) << "all values greater than 0";
44 } | std::vector{1, 2, 3};
45
46 /// Alternative syntax
47#ifndef __EMSCRIPTEN__
48 "views"_test = [](auto arg) {
49 expect(arg > 0_i) << "all values greater than 0";
50 } | std::views::iota(1, 4);
51#endif
52
53 /// Alternative syntax
54 "types"_test = []<class T>() {
55 expect(std::is_integral_v<T>) << "all types are integrals";
56 } | std::tuple<bool, int>{};
57
58 /// Language syntax
59 std::apply(
60 []<class... TArgs>(TArgs... args) {
61 ((test("args and types / " + std::to_string(args)) =
62 [&] {
63 expect((std::is_integral_v<TArgs>) >> fatal);
64 expect(42_i == static_cast<int>(args) or args);
65 expect(type<TArgs> == type<int> or type<TArgs> == type<bool>);
66 }),
67 ...);
68 },
69 std::tuple{42, true});
70
71 /// Alternative syntax
72 "args and types"_test = []<class TArg>(TArg arg) {
73 expect((std::is_integral_v<TArg>) >> fatal);
74 expect(42_i == static_cast<int>(arg) or arg);
75 expect(type<TArg> == type<int> or type<TArg> == type<bool>);
76 } | std::tuple{42, true};
77
78 // Modifying test names when using alternative syntax
79 // When using the alternative syntax, the test names are extended based on the
80 // test parameters (to ensure uniqueness). Here, for simple built-in types,
81 // the parameter value is printed, while other types are simply enumerated.
82 // Without the `format_test_parameter` overload above, the test names for the
83 // test below would be:
84 // "parameterized test names (42, int)"
85 // "parameterized test names (true, bool)"
86 // "parameterized test names (3rd parameter, std::complex<double>)"
87 // However, since the overload for std::complex is available, the third test name becomes:
88 // "parameterized test names (1.5+2i, std::complex<double>)"

Callers

nothing calls this directly

Calls 2

testClass · 0.85
expectFunction · 0.85

Tested by

no test coverage detected