dot-xx
A personal collection of small C++ modules
Loading...
Searching...
No Matches
dxx::selftest::UnitTest< TFunc > Class Template Referenceexport

Create an object of that class to declare a unit test. More...

Public Types

using Func = TFunc

Public Member Functions

constexpr UnitTest (std::string_view name, const TFunc &func)
 Declare a unit test. Uses a custom name instead of the source file name and line.
constexpr UnitTest (const TFunc &func, const std::source_location &sl=std::source_location::current())
 Declare a unit test. func needs to be a lambda local to the declaration.

Detailed Description

template<named_test_body TFunc>
class dxx::selftest::UnitTest< TFunc >

Create an object of that class to declare a unit test.

The test must be declared in the ::tests namespace (or a namespace inside of it). The test name is inferred from the namespace it is in and either manually specified case name or the case source location.

Anonymous namespaces do not contribute to the test name

In order for the test to name properly, it must be defined via a lambda that is in the same scope as the declaration (the name is deduced from the callable type)

Do not declare UnitTests constexpr or constinit! This may lead to breaking the order of initialization!

static const UnitTest test1 = [] { ... }; // Not counted as a test, compile-
// time error
namespace test::project::suite::case {
// Declares `/test/project/suite/case/file.cc:42` test
static const UnitTest test2 = [] { ... };
// Declares `/test/project/suite/case/my_case` test
static const UnitTest amogus{ "my_case", [] { ... } };
} // <-- namespace test::project::suite::case
Create an object of that class to declare a unit test.
Definition selftest.xx:69
constexpr UnitTest(std::string_view name, const TFunc &func)
Declare a unit test. Uses a custom name instead of the source file name and line.
Definition selftest.xx:78

TODO: Find a way to remove redundancy in naming and infer test name from the variable name!


The documentation for this class was generated from the following file:
  • /build-llvm-libcpp/_deps/dot-xx-selftest-src/src/selftest.xx