131#define TestStart(type, name, func_name, node_cnt) \
132 void test_func_##func_name(); \
133 void (*test_func_ptr_##func_name)() = test_func_##func_name; \
134 shamtest::details::TestStaticInit test_class_obj_##func_name( \
135 shamtest::details::Test{type, name, node_cnt, test_func_ptr_##func_name}); \
136 void test_func_##func_name()
148#define TEX_REPORT(src) shamtest::details::current_test.tex_output += src;
150#define STDSTRINGIFY(x) std::string(#x)
169 return "\"" + s +
"\" : ";
183#define REQUIRE_NAMED(name, a) \
185 using namespace shamtest::details; \
187 std::string assert_name = format_assert_name(name) + #a; \
189 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
191 shamtest::asserts().assert_bool_with_log( \
194 STDSTRINGIFY(a) + " evaluated to false\n\n" \
195 + " -> location : " + SourceLocation{}.format_one_line()); \
208#define REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, _a, _b, comp) \
210 auto _______a = _a; \
211 auto _______b = _b; \
212 using namespace shamtest::details; \
213 bool eval = comp(_______a, _______b); \
214 std::string assert_name = format_assert_name(name) + #_a " == " #_b; \
216 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
218 shamtest::asserts().assert_bool_with_log( \
221 assert_name + " evaluated to false\n\n" + " -> " #_a \
222 + shambase::format(" = {}", _______a) + "\n" + " -> " #_b \
223 + shambase::format(" = {}", _______b) + "\n" \
224 + " -> location : " + SourceLocation{}.format_one_line()); \
237#define REQUIRE_EQUAL_NAMED(name, a, b) \
238 REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, a, b, [](const auto &p1, const auto &p2) { \
251#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, _a, _b, prec, dist) \
255 using namespace shamtest::details; \
256 bool eval = dist((a) - (b)) < prec; \
257 std::string assert_name \
258 = format_assert_name(name) + #dist "(" #_a ") - (" #_b ") < " #prec; \
260 shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
262 shamtest::asserts().assert_bool_with_log( \
265 assert_name + " evaluated to false\n\n" + shambase::format(" -> " #_a " = {}", a) \
266 + "\n" + shambase::format(" -> " #_b " = {}", b) + "\n" \
267 + shambase::format(" -> " #prec " = {}", prec) + "\n" \
268 + " -> location : " + SourceLocation{}.format_one_line()); \
280#define REQUIRE_FLOAT_EQUAL_NAMED(name, a, b, prec) \
281 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, a, b, prec, std::abs)
292#define REQUIRE(a) REQUIRE_NAMED("", a)
302#define REQUIRE_EQUAL_CUSTOM_COMP(a, b, comp) REQUIRE_EQUAL_CUSTOM_COMP_NAMED("", a, b, comp)
312#define REQUIRE_EQUAL(a, b) REQUIRE_EQUAL_NAMED("", a, b)
323#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST(name, a, b, prec, dist) \
324 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, dist)
334#define REQUIRE_FLOAT_EQUAL(a, b, prec) \
335 REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, std::abs)
348#define REQUIRE_EXCEPTION_THROW(call, exception_type) \
354 shamtest::asserts().assert_bool_with_log( \
355 #exception_type " was not thrown", \
357 "Expected throw of type " #exception_type ", but nothing was thrown\n" \
359 + SourceLocation{}.format_one_line()); \
360 } catch (const exception_type &ex) { \
362 shamtest::asserts().assert_bool_with_log( \
363 "Found wanted throw of type " #exception_type, true, ""); \
364 } catch (const std::exception &e) { \
366 shamtest::asserts().assert_bool_with_log( \
367 #exception_type " was not thrown", \
369 "Expected throw of type " #exception_type ", but got " + std::string(e.what()) \
370 + "\n" + " -> location : " + SourceLocation{}.format_one_line()); \
373 shamtest::asserts().assert_bool_with_log( \
374 #exception_type " was not thrown", \
376 "Expected throw of type " #exception_type ", but got unknown exception\n" \
378 + SourceLocation{}.format_one_line()); \
Namespace for internal details of the logs module.
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.
helper class to statically register tests
TestStaticInit(Test t)
This constructor register the given arguments into static_init_vec_tests
Informations about a test.