test.unit ≡
The simple unit test framework allows defining test cases that can be
conditionally included at compile time. Test cases are identified by
tags and can be selected to be built/executed using two values specified
via compiler --define option:
- tag - identifies a specific test to be included
- mask - specifies a bit mask of tests to be included
A test is included in the build/execution if its tag is equal to specified tag, or if its tag is included in the bit mask. If both tag and mask are zero, which is the default, all tests are included.
Test tags are constructed from three parts:
- 12 bit test identifier
- 4 bit group identifier
- 16 bit flags
Only the test identifier is required. Group identifier and flags are optional and set to 0 by default.
Typical usage scenarios are:
isolate a specific test to build/execute:
--define tag=5build/execute tests from a specific group, for example to make build/simulation smaller:
--define mask=0x2FFFbuild/execute a cross section of all tests with specified flag(s):
--define mask=0x4FFFF
Verbosity of the test framework output is controlled by boolean value
verbose that can be defined via compiler
--define command line option. With verbose output the
framework prints information about all skipped and executed test cases.
By default only information about failed test case(s) is printed.
template <auto Test, auto Group = 0, auto Flags = 0> inline void check(() -> bool fn) §
Add a test case that returns true for success and
false for failure.
Parameters
-
auto TestTest id
-
auto Group = 0
Optional test group id, by default 0
-
auto Flags = 0
Optional test flags, by default 0
Arguments
-
() -> bool fn
Test case function
template <auto Test, auto Group = 0, auto Flags = 0> inline void test((tag_t) -> void fn) §
Add a test case that takes tag argument and uses the assert helpers to indicate failures.
Parameters
-
auto TestTest id
-
auto Group = 0
Optional test group id, by default 0
-
auto Flags = 0
Optional test flags, by default 0
Arguments
-
(tag_t) -> void fn
Test case function
template <typename Fixture> inline auto fixture() §
Use the specified Fixture class to implement a test. A
fixture used with test function must implement a public
method void run(tag_t tag) and use asserts to indicate test
failure. A fixture used with check must implement a public
method bool run() that returns true for
success and false for failure.
Example
class Foo { public: void run(unit::tag_t tag) { unit::assert_equal(tag, 4, 2 + 2); } }
unit::test<1>(unit::fixture
Parameters
-
typename FixtureFixture class