122#define ANY_WORLD_SIZE -1
124#define _internal_new_test(type, name, func_name, func_ptr, class_name, node_cnt) \
125 static void func_name(); \
126 static void (*func_ptr)() = func_name; \
127 static shamtest::details::TestStaticInit class_name( \
128 shamtest::details::Test{type, name, node_cnt, func_ptr}); \
129 static void func_name()
141#define NEW_TEST(type, name, node_cnt) \
142 _internal_new_test( \
145 __shamrock_unique_name(test_func_), \
146 __shamrock_unique_name(test_func_ptr_), \
147 __shamrock_unique_name(test_class_), \
160#define TEX_REPORT(src) shamtest::details::current_test.tex_output += src;
162#define STDSTRINGIFY(x) std::string(#x)
181 return "\"" + s +
"\" : ";
195#define REQUIRE_NAMED(name, a) \
197 using namespace shamtest::details; \
199 std::string assert_name = format_assert_name(name) + #a; \
201 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
203 shamtest::asserts().assert_bool_with_log( \
206 STDSTRINGIFY(a) + " evaluated to false\n\n" \
207 + " -> location : " + SourceLocation{}.format_one_line()); \
220#define REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, _a, _b, comp) \
222 auto _______a = _a; \
223 auto _______b = _b; \
224 using namespace shamtest::details; \
225 bool eval = comp(_______a, _______b); \
226 std::string assert_name = format_assert_name(name) + #_a " == " #_b; \
228 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
230 shamtest::asserts().assert_bool_with_log( \
233 assert_name + " evaluated to false\n\n" + " -> " #_a \
234 + shambase::format(" = {}", _______a) + "\n" + " -> " #_b \
235 + shambase::format(" = {}", _______b) + "\n" \
236 + " -> location : " + SourceLocation{}.format_one_line()); \
249#define REQUIRE_EQUAL_NAMED(name, a, b) \
250 REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, a, b, [](const auto &p1, const auto &p2) { \
263#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, _a, _b, prec, dist) \
267 using namespace shamtest::details; \
268 bool eval = dist((a) - (b)) < prec; \
269 std::string assert_name \
270 = format_assert_name(name) + #dist "(" #_a ") - (" #_b ") < " #prec; \
272 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
274 shamtest::asserts().assert_bool_with_log( \
277 assert_name + " evaluated to false\n\n" + shambase::format(" -> " #_a " = {}", a) \
278 + "\n" + shambase::format(" -> " #_b " = {}", b) + "\n" \
279 + shambase::format(" -> " #prec " = {}", prec) + "\n" \
280 + " -> location : " + SourceLocation{}.format_one_line()); \
292#define REQUIRE_FLOAT_EQUAL_NAMED(name, a, b, prec) \
293 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, a, b, prec, std::abs)
304#define REQUIRE(a) REQUIRE_NAMED("", a)
314#define REQUIRE_EQUAL_CUSTOM_COMP(a, b, comp) REQUIRE_EQUAL_CUSTOM_COMP_NAMED("", a, b, comp)
324#define REQUIRE_EQUAL(a, b) REQUIRE_EQUAL_NAMED("", a, b)
335#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST(name, a, b, prec, dist) \
336 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, dist)
346#define REQUIRE_FLOAT_EQUAL(a, b, prec) \
347 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, std::abs)
360#define REQUIRE_EXCEPTION_THROW(call, exception_type) \
366 shamtest::asserts().assert_bool_with_log( \
367 #exception_type " was not thrown", \
369 "Expected throw of type " #exception_type ", but nothing was thrown\n" \
371 + SourceLocation{}.format_one_line()); \
372 } catch (const exception_type &ex) { \
374 shamtest::asserts().assert_bool_with_log( \
375 "Found wanted throw of type " #exception_type, true, ""); \
376 } catch (const std::exception &e) { \
378 shamtest::asserts().assert_bool_with_log( \
379 #exception_type " was not thrown", \
381 "Expected throw of type " #exception_type ", but got " + std::string(e.what()) \
382 + "\n" + " -> location : " + SourceLocation{}.format_one_line()); \
385 shamtest::asserts().assert_bool_with_log( \
386 #exception_type " was not thrown", \
388 "Expected throw of type " #exception_type ", but got unknown exception\n" \
390 + 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.