123#define ANY_WORLD_SIZE -1
125#define _internal_new_test(type, name, func_name, func_ptr, class_name, node_cnt) \
126 static void func_name(); \
127 static void (*func_ptr)() = func_name; \
128 static shamtest::details::TestStaticInit class_name( \
129 shamtest::details::Test{type, name, node_cnt, func_ptr}); \
130 static void func_name()
142#define NEW_TEST(type, name, node_cnt) \
143 _internal_new_test( \
146 __shamrock_unique_name(test_func_), \
147 __shamrock_unique_name(test_func_ptr_), \
148 __shamrock_unique_name(test_class_), \
161#define TEX_REPORT(src) shamtest::details::current_test.tex_output += src;
163#define STDSTRINGIFY(x) std::string(#x)
182 return "\"" + s +
"\" : ";
196#define REQUIRE_NAMED(name, a) \
198 using namespace shamtest::details; \
200 std::string assert_name = format_assert_name(name) + #a; \
202 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
204 shamtest::asserts().assert_bool_with_log( \
207 STDSTRINGIFY(a) + " evaluated to false\n\n" \
208 + " -> location : " + SourceLocation{}.format_one_line()); \
221#define REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, _a, _b, comp) \
223 auto _______a = _a; \
224 auto _______b = _b; \
225 using namespace shamtest::details; \
226 bool eval = comp(_______a, _______b); \
227 std::string assert_name = format_assert_name(name) + #_a " == " #_b; \
229 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
231 shamtest::asserts().assert_bool_with_log( \
234 assert_name + " evaluated to false\n\n" + " -> " #_a \
235 + shambase::format(" = {}", _______a) + "\n" + " -> " #_b \
236 + shambase::format(" = {}", _______b) + "\n" \
237 + " -> location : " + SourceLocation{}.format_one_line()); \
250#define REQUIRE_EQUAL_NAMED(name, a, b) \
251 REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, a, b, [](const auto &p1, const auto &p2) { \
264#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, _a, _b, prec, dist) \
268 using namespace shamtest::details; \
269 bool eval = dist((a) - (b)) < prec; \
270 std::string assert_name \
271 = format_assert_name(name) + #dist "(" #_a ") - (" #_b ") < " #prec; \
273 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
275 shamtest::asserts().assert_bool_with_log( \
278 assert_name + " evaluated to false\n\n" + shambase::format(" -> " #_a " = {}", a) \
279 + "\n" + shambase::format(" -> " #_b " = {}", b) + "\n" \
280 + shambase::format(" -> " #prec " = {}", prec) + "\n" \
281 + " -> location : " + SourceLocation{}.format_one_line()); \
293#define REQUIRE_FLOAT_EQUAL_NAMED(name, a, b, prec) \
294 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, a, b, prec, std::abs)
305#define REQUIRE(a) REQUIRE_NAMED("", a)
315#define REQUIRE_EQUAL_CUSTOM_COMP(a, b, comp) REQUIRE_EQUAL_CUSTOM_COMP_NAMED("", a, b, comp)
325#define REQUIRE_EQUAL(a, b) REQUIRE_EQUAL_NAMED("", a, b)
336#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST(name, a, b, prec, dist) \
337 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, dist)
347#define REQUIRE_FLOAT_EQUAL(a, b, prec) \
348 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, std::abs)
361#define REQUIRE_EXCEPTION_THROW(call, exception_type) \
367 shamtest::asserts().assert_bool_with_log( \
368 #exception_type " was not thrown", \
370 "Expected throw of type " #exception_type ", but nothing was thrown\n" \
372 + SourceLocation{}.format_one_line()); \
373 } catch (const exception_type &ex) { \
375 shamtest::asserts().assert_bool_with_log( \
376 "Found wanted throw of type " #exception_type, true, ""); \
377 } catch (const std::exception &e) { \
379 shamtest::asserts().assert_bool_with_log( \
380 #exception_type " was not thrown", \
382 "Expected throw of type " #exception_type ", but got " + std::string(e.what()) \
383 + "\n" + " -> location : " + SourceLocation{}.format_one_line()); \
386 shamtest::asserts().assert_bool_with_log( \
387 #exception_type " was not thrown", \
389 "Expected throw of type " #exception_type ", but got unknown exception\n" \
391 + SourceLocation{}.format_one_line()); \
implementation details of the test library
std::string format_assert_name(std::string s)
Format a string that is an assert name.
TestResult current_test
Current test being run.
std::vector< Test > static_init_vec_tests
Static init vector containing the list of all the tests in the code see : programming guide : Static ...
namespace containing stuff related to the test library
std::string & test_tex_out()
Get current tex output from a test.
void gen_test_list(std::string_view outfile)
output test list to a file
shamtest::details::TestDataList & test_data()
current test data
shamtest::details::TestAssertList & asserts()
current test asserts
int run_all_tests(int argc, char *argv[], TestConfig cfg)
run all the tests
Configuration of the test runner.
std::optional< std::string > run_only
Run only regex to select tests.
bool run_long_tests
run also long tests
bool run_benchmark
run benchmarks
bool output_tex
Should output a tex report.
bool run_unittest
run unittests
bool full_output
Should display all logs including all asserts.
std::optional< std::string > json_output
Should output a json report.
bool print_test_list_exit
Should print test list and then exit.
bool run_validation
run validation tests
Class to hold the list of assertion related to a test.
List of data generated by a test.
TestStaticInit(Test t)
This constructor register the given arguments into static_init_vec_tests.
Informations about a test.
Provides macros for generating unique identifiers at compile time.