Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamtest.hpp File Reference

main include file for testing More...

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 ANY_WORLD_SIZE   -1
#define _internal_new_test(type, name, func_name, func_ptr, class_name, node_cnt)
#define NEW_TEST(type, name, node_cnt)
 Macro to declare a test.
#define TEX_REPORT(src)
 Macro to write stuff to the tex test report.
#define STDSTRINGIFY(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)
 Assert macro for test, testing equality between two variables, with a given precision.
#define REQUIRE(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)
 Assert macro for test to test for equalities using a custom comparison function.
#define REQUIRE_EQUAL(a, b)
 Assert macro for test to test for equalities.
#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 distance function.
#define REQUIRE_FLOAT_EQUAL(a, b, prec)
 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

◆ _internal_new_test

#define _internal_new_test ( type,
name,
func_name,
func_ptr,
class_name,
node_cnt )
Value:
static void func_name(); \
static void (*func_ptr)() = func_name; \
static shamtest::details::TestStaticInit class_name( \
shamtest::details::Test{type, name, node_cnt, func_ptr}); \
static void func_name()
helper class to statically register tests
Definition shamtest.hpp:43
Informations about a test.
Definition Test.hpp:26

Definition at line 124 of file shamtest.hpp.

◆ ANY_WORLD_SIZE

#define ANY_WORLD_SIZE   -1

Definition at line 122 of file shamtest.hpp.

◆ NEW_TEST

#define NEW_TEST ( type,
name,
node_cnt )
Value:
_internal_new_test( \
type, \
name, \
__shamrock_unique_name(test_func_), \
__shamrock_unique_name(test_func_ptr_), \
__shamrock_unique_name(test_class_), \
node_cnt)

Macro to declare a test.

Example :

NEW_TEST(Unittest, "testname", 1) {
REQUIRE(true);
}
#define NEW_TEST(type, name, node_cnt)
Macro to declare a test.
Definition shamtest.hpp:141
#define REQUIRE(a)
Assert macro for test write the conditional, the name of the assert will be the condition.
Definition shamtest.hpp:302

Definition at line 141 of file shamtest.hpp.

◆ REQUIRE

#define REQUIRE ( a)
Value:
#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:193

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

Usage :

REQUIRE(a == 0)

Definition at line 302 of file shamtest.hpp.

◆ REQUIRE_EQUAL

#define REQUIRE_EQUAL ( a,
b )
Value:
#define REQUIRE_EQUAL_NAMED(name, a, b)
Assert macro for test to test for equalities Named variant.
Definition shamtest.hpp:247

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:322

Definition at line 322 of file shamtest.hpp.

◆ REQUIRE_EQUAL_CUSTOM_COMP

#define REQUIRE_EQUAL_CUSTOM_COMP ( a,
b,
comp )
Value:
#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:218

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:312

Definition at line 312 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.cpp:20
std::string format_assert_name(std::string s)
Format a string that is an assert name.
Definition shamtest.hpp:175
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)

Definition at line 218 of file shamtest.hpp.

◆ REQUIRE_EQUAL_NAMED

#define REQUIRE_EQUAL_NAMED ( name,
a,
b )
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)

Definition at line 247 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:358
Parameters
callCall that is expected to throw the specified exception type
exception_typeException type that is expected to be thrown

Definition at line 358 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL

#define REQUIRE_FLOAT_EQUAL ( a,
b,
prec )
Value:
REQUIRE_FLOAT_EQUAL_CUSTOM_DIST_NAMED("", a, b, prec, std::abs)
#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:261

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:344

Definition at line 344 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL_CUSTOM_DIST

#define REQUIRE_FLOAT_EQUAL_CUSTOM_DIST ( name,
a,
b,
prec,
dist )
Value:

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:333

Definition at line 333 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)

Definition at line 261 of file shamtest.hpp.

◆ REQUIRE_FLOAT_EQUAL_NAMED

#define REQUIRE_FLOAT_EQUAL_NAMED ( name,
a,
b,
prec )
Value:
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 290 of file shamtest.hpp.

◆ REQUIRE_NAMED

#define REQUIRE_NAMED ( name,
a )
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)

Definition at line 193 of file shamtest.hpp.

◆ STDSTRINGIFY

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

Definition at line 160 of file shamtest.hpp.

◆ TEX_REPORT

#define TEX_REPORT ( src)
Value:
TestResult current_test
Current test being run.
Definition Test.cpp:22

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:158

Definition at line 158 of file shamtest.hpp.