Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions | Variables
shamtest.hpp File Reference

main include file for testing More...

#include "details/Test.hpp"
+ Include dependency graph for shamtest.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  shamtest::details::TestStaticInit
 helper class to statically register tests More...
 
struct  shamtest::TestConfig
 Configuration of the test runner. More...
 

Namespaces

namespace  shamtest
 namespace containing stuff related to the test library
 
namespace  shamtest::details
 implementation details of the test library
 

Macros

#define TestStart(type, name, func_name, node_cnt)
 Macro to declare a test.
 
#define TEX_REPORT(src)   shamtest::details::current_test.tex_output += src;
 Macro to write stuff to the tex test report.
 
#define STDSTRINGIFY(x)   std::string(#x)
 
#define REQUIRE_NAMED(name, a)
 Assert macro for test write the conditional, the name of the assert will be the condition Named variant.
 
#define REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, _a, _b, comp)
 Assert macro for test to test for equalities using a custom comparison function Named variant.
 
#define REQUIRE_EQUAL_NAMED(name, a, b)
 Assert macro for test to test for equalities Named variant.
 
#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, _a, _b, prec, dist)
 Assert macro for test, testing equality between two variables, with a given precision and a custom distance function.
 
#define REQUIRE_FLOAT_EQUAL_NAMED(name, a, b, prec)    REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, a, b, prec, std::abs)
 Assert macro for test, testing equality between two variables, with a given precision.
 
#define REQUIRE(a)   REQUIRE_NAMED("", a)
 Assert macro for test write the conditional, the name of the assert will be the condition.
 
#define REQUIRE_EQUAL_CUSTOM_COMP(a, b, comp)   REQUIRE_EQUAL_CUSTOM_COMP_NAMED("", a, b, comp)
 Assert macro for test to test for equalities using a custom comparison function.
 
#define REQUIRE_EQUAL(a, b)   REQUIRE_EQUAL_NAMED("", a, b)
 Assert macro for test to test for equalities.
 
#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST(name, a, b, prec, dist)    REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, dist)
 Assert macro for test, testing equality between two variables, with a given precision and a custom distance function.
 
#define REQUIRE_FLOAT_EQUAL(a, b, prec)    REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, std::abs)
 Assert macro for test, testing equality between two variables, with a given precision.
 
#define REQUIRE_EXCEPTION_THROW(call, exception_type)
 Assert macro for test, testing that a given call throws a specific exception type.
 

Functions

int shamtest::run_all_tests (int argc, char *argv[], TestConfig cfg)
 run all the tests
 
void shamtest::gen_test_list (std::string_view outfile)
 output test list to a file
 
shamtest::details::TestAssertListshamtest::asserts ()
 current test asserts
 
shamtest::details::TestDataListshamtest::test_data ()
 current test data
 
std::string & shamtest::test_tex_out ()
 Get current tex output from a test.
 
std::string shamtest::details::format_assert_name (std::string s)
 Format a string that is an assert name.
 

Variables

std::vector< Testshamtest::details::static_init_vec_tests {}
 Static init vector containing the list of all the tests in the code see : programming guide : Static init function registering.
 

Detailed Description

main include file for testing

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file shamtest.hpp.

Macro Definition Documentation

◆ REQUIRE

#define REQUIRE (   a)    REQUIRE_NAMED("", a)

Assert macro for test write the conditional, the name of the assert will be the condition.

Usage :

REQUIRE(a == 0)
#define REQUIRE(a)
Assert macro for test write the conditional, the name of the assert will be the condition.
Definition shamtest.hpp:292

Definition at line 292 of file shamtest.hpp.

◆ REQUIRE_EQUAL

#define REQUIRE_EQUAL (   a,
 
)    REQUIRE_EQUAL_NAMED("", a, b)

Assert macro for test to test for equalities.

Usage :

#define REQUIRE_EQUAL(a, b)
Assert macro for test to test for equalities.
Definition shamtest.hpp:312

Definition at line 312 of file shamtest.hpp.

◆ REQUIRE_EQUAL_CUSTOM_COMP

#define REQUIRE_EQUAL_CUSTOM_COMP (   a,
  b,
  comp 
)    REQUIRE_EQUAL_CUSTOM_COMP_NAMED("", a, b, comp)

Assert macro for test to test for equalities using a custom comparison function.

Usage :

#define REQUIRE_EQUAL_CUSTOM_COMP(a, b, comp)
Assert macro for test to test for equalities using a custom comparison function.
Definition shamtest.hpp:302

Definition at line 302 of file shamtest.hpp.

◆ REQUIRE_EQUAL_CUSTOM_COMP_NAMED

#define REQUIRE_EQUAL_CUSTOM_COMP_NAMED (   name,
  _a,
  _b,
  comp 
)
Value:
do { \
auto _______a = _a; \
auto _______b = _b; \
using namespace shamtest::details; \
bool eval = comp(_______a, _______b); \
std::string assert_name = format_assert_name(name) + #_a " == " #_b; \
if (eval) { \
shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
} else { \
shamtest::asserts().assert_bool_with_log( \
assert_name, \
eval, \
assert_name + " evaluated to false\n\n" + " -> " #_a \
+ shambase::format(" = {}", _______a) + "\n" + " -> " #_b \
+ shambase::format(" = {}", _______b) + "\n" \
+ " -> location : " + SourceLocation{}.format_one_line()); \
} \
} while (0)
implementation details of the test library
Definition DataNode.hpp:23
provide information about the source location
std::string format_one_line() const
format the location in a one liner

Assert macro for test to test for equalities using a custom comparison function Named variant.

Usage :

REQUIRE_EQUAL_CUSTOM_COMP_NAMED("assert name",a , b)
#define REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, _a, _b, comp)
Assert macro for test to test for equalities using a custom comparison function Named variant.
Definition shamtest.hpp:208

Definition at line 208 of file shamtest.hpp.

◆ REQUIRE_EQUAL_NAMED

#define REQUIRE_EQUAL_NAMED (   name,
  a,
 
)
Value:
REQUIRE_EQUAL_CUSTOM_COMP_NAMED(name, a, b, [](const auto &p1, const auto &p2) { \
return p1 == p2; \
})

Assert macro for test to test for equalities Named variant.

Usage :

REQUIRE_EQUAL_NAMED("assert_name", a , b)
#define REQUIRE_EQUAL_NAMED(name, a, b)
Assert macro for test to test for equalities Named variant.
Definition shamtest.hpp:237

Definition at line 237 of file shamtest.hpp.

◆ REQUIRE_EXCEPTION_THROW

#define REQUIRE_EXCEPTION_THROW (   call,
  exception_type 
)

Assert macro for test, testing that a given call throws a specific exception type.

Usage :

REQUIRE_EXCEPTION_THROW(function_that_throws(), exception_type)
#define REQUIRE_EXCEPTION_THROW(call, exception_type)
Assert macro for test, testing that a given call throws a specific exception type.
Definition shamtest.hpp:348
Parameters
callCall that is expected to throw the specified exception type
exception_typeException type that is expected to be thrown

Definition at line 348 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL

#define REQUIRE_FLOAT_EQUAL (   a,
  b,
  prec 
)     REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, std::abs)

Assert macro for test, testing equality between two variables, with a given precision.

Usage :

REQUIRE_FLOAT_EQUAL(a , b, 1e-9)
#define REQUIRE_FLOAT_EQUAL(a, b, prec)
Assert macro for test, testing equality between two variables, with a given precision.
Definition shamtest.hpp:334

Definition at line 334 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL_CUSTOM_DIST

#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST (   name,
  a,
  b,
  prec,
  dist 
)     REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, dist)

Assert macro for test, testing equality between two variables, with a given precision and a custom distance function.

Usage :

REQUIRE_FLOAT_EQUAL_CUSTOM_DIST(a , b, 1e-9, sycl::length)
#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST(name, a, b, prec, dist)
Assert macro for test, testing equality between two variables, with a given precision and a custom di...
Definition shamtest.hpp:323

Definition at line 323 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED

#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED (   name,
  _a,
  _b,
  prec,
  dist 
)
Value:
do { \
auto a = _a; \
auto b = _b; \
using namespace shamtest::details; \
bool eval = dist((a) - (b)) < prec; \
std::string assert_name \
= format_assert_name(name) + #dist "(" #_a ") - (" #_b ") < " #prec; \
if (eval) { \
shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
} else { \
shamtest::asserts().assert_bool_with_log( \
assert_name, \
eval, \
assert_name + " evaluated to false\n\n" + shambase::format(" -> " #_a " = {}", a) \
+ "\n" + shambase::format(" -> " #_b " = {}", b) + "\n" \
+ shambase::format(" -> " #prec " = {}", prec) + "\n" \
+ " -> location : " + SourceLocation{}.format_one_line()); \
} \
} while (0)

Assert macro for test, testing equality between two variables, with a given precision and a custom distance function.

Usage :

REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("assert name",a , b, 1e-9, sycl::length)
#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, _a, _b, prec, dist)
Assert macro for test, testing equality between two variables, with a given precision and a custom di...
Definition shamtest.hpp:251

Definition at line 251 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL_NAMED

#define REQUIRE_FLOAT_EQUAL_NAMED (   name,
  a,
  b,
  prec 
)     REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED(name, a, b, prec, std::abs)

Assert macro for test, testing equality between two variables, with a given precision.

Usage :

REQUIRE_FLOAT_EQUAL(a , b, 1e-9)

Definition at line 280 of file shamtest.hpp.

◆ REQUIRE_NAMED

#define REQUIRE_NAMED (   name,
 
)
Value:
do { \
using namespace shamtest::details; \
bool eval = a; \
std::string assert_name = format_assert_name(name) + #a; \
if (eval) { \
shamtest::asserts().assert_bool_with_log(assert_name, eval, ""); \
} else { \
shamtest::asserts().assert_bool_with_log( \
assert_name, \
eval, \
STDSTRINGIFY(a) + " evaluated to false\n\n" \
+ " -> location : " + SourceLocation{}.format_one_line()); \
} \
} while (0)

Assert macro for test write the conditional, the name of the assert will be the condition Named variant.

Usage :

REQUIRE_NAMED("assert name",a == 0)
#define REQUIRE_NAMED(name, a)
Assert macro for test write the conditional, the name of the assert will be the condition Named varia...
Definition shamtest.hpp:183

Definition at line 183 of file shamtest.hpp.

◆ STDSTRINGIFY

#define STDSTRINGIFY (   x)    std::string(#x)

Definition at line 150 of file shamtest.hpp.

◆ TestStart

#define TestStart (   type,
  name,
  func_name,
  node_cnt 
)
Value:
void test_func_##func_name(); \
void (*test_func_ptr_##func_name)() = test_func_##func_name; \
shamtest::details::TestStaticInit test_class_obj_##func_name( \
shamtest::details::Test{type, name, node_cnt, test_func_ptr_##func_name}); \
void test_func_##func_name()
helper class to statically register tests
Definition shamtest.hpp:42
Informations about a test.
Definition Test.hpp:26

Macro to declare a test.

Example :

TestStart(Unittest, "testname", testfuncname, 1) {
shamtest::asserts().assert_bool("what a reliable test", true);
}
shamtest::details::TestAssertList & asserts()
current test asserts
Definition shamtest.hpp:103
#define TestStart(type, name, func_name, node_cnt)
Macro to declare a test.
Definition shamtest.hpp:131
void assert_bool(std::string assert_name, bool v, SourceLocation loc=SourceLocation{})
Test if the supplied boolean is true.

Definition at line 131 of file shamtest.hpp.

◆ TEX_REPORT

#define TEX_REPORT (   src)    shamtest::details::current_test.tex_output += src;

Macro to write stuff to the tex test report.

Usage :

here i'm writing tex
)==")
#define TEX_REPORT(src)
Macro to write stuff to the tex test report.
Definition shamtest.hpp:148

Definition at line 148 of file shamtest.hpp.