|
dot-xx
A personal collection of small C++ modules
|
Main namespace of dxx::selftest module. More...
Classes | |
| class | LifetimeTester |
| A simple class for tracking object moves/copies during their lives in containers. More... | |
| struct | test_failure |
| The exception type used by test assertions. More... | |
| class | UnitTest |
| Create an object of that class to declare a unit test. More... | |
Concepts | |
| concept | named_test_body |
Typedefs | |
| using | TestBody = std::function<void()> |
| using | TestsMap = std::map<std::string, TestBody> |
Functions | |
| template<typename T> | |
| consteval std::string_view | function_name () |
| Forwards its own std::source_location::function_name(). | |
| template<typename T> | |
| consteval auto | get_test_name_cpp () |
| Gets the C++ name of the type's scope (if it starts with test::) and gets rid of the test:: part, e.g. for test::a::b::c it will return a::b::c. | |
| template<typename T> | |
| consteval auto | get_test_name_data () |
| Convertes get_test_name_cpp return value into a proper test "path" format. | |
| template<typename T> | |
| consteval std::optional< std::string_view > | get_test_name () |
| Get an optional string_view with the test name, or nullopt if not a test for some reason. | |
| void | test (bool condition, std::source_location st=std::source_location::current()) |
| Test assertion. Calls dxx::assert::always with test_failure. | |
| int | run_all (const std::unordered_set< std::string > &filters={}) |
| Run all tests that match a filter. | |
Variables | |
| constexpr auto | test_prefix = "T = test::"sv |
| constexpr std::array | anonymous_indicators |
| constexpr auto | view_buf |
| A helper for monadic optional operations. | |
| template<typename T> | |
| constexpr auto | test_name = get_test_name_data<T>() |
| A constexpr string_view returned by get_test_name should point to somewhere in the program memmory. This is that somewhere. | |
| constinit std::unique_ptr< TestsMap > | all_tests = nullptr |
| Storage for all unit tests. | |
Main namespace of dxx::selftest module.
|
consteval |
Forwards its own std::source_location::function_name().
Required because we want to use it as a constexpr variable and some compilers may skip specifying the template parameters for such. So we wrap it in a consteval function within which this value is not constexpr, but outside of which it can be used as such.
|
consteval |
Gets the C++ name of the type's scope (if it starts with test::) and gets rid of the test:: part, e.g. for test::a::b::c it will return a::b::c.
|
export |
Run all tests that match a filter.
The tests are declared by creating objects of unit_test, you would usually want to declare them as static const ... objects in a translation unit:
The test is successful if it does not produce exceptions. The test is failed if it produced an exception of type test_failure (or derived). If the test produces any other exception type, it is not caught by this function and will lead to program termination if not caught by code surrounding run_all.
Test names could be any strings, but the filtering mechanism expects them to follow the UNIX-like filename format: starting with "/" and using it to further create the test "tree". Each filter in filters is tested as follows:
|
inlineconstinitexport |
Storage for all unit tests.
constinit to ensure the smart pointer is initialized before the tests are
|
inlineconstexpr |
|
inlineconstexpr |
A helper for monadic optional operations.