![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
Arene Base provides a unit testing support library, compatible with gtest, which provides CONSTEXPR_TEST and CONSTEXPR_TYPED_TEST macros which mirror the TEST and TYPED_TEST macros defined by GoogleTest. These macros provide an alternative approach to using STATIC_ASSERT_XXX macros when writing compile-time tests. Additionally, this support library provides CONSTEXPR_ASSERT, an assertion macro that replaces ones from GoogleTest.
The CONSTEXPR test macros invoke the entire test body at compile-time and again at run-time. The compile-time invocation provides evidence of compile-time correctness and constexpr invocability while the run-time invocation provides evidence of run-time correctness. The run-time invocation further enables collection of run-time code coverage data.
If you don't need to invoke the entire test body at compile time, consider using [STATIC_ASSERT_XXX](static_assertions) macros.
Here is a simple example of changing a run-time evaluated test using TEST to a compile-time test using CONSTEXPR_TEST.
GoogleTest assertion macros (e.g. ASSERT_EQ) cannot be used within a CONSTEXPR_TEST. Instead, a single CONSTEXPR_ASSERT assertion macro is available.
Use of CONSTEXPR_TYPED_TEST is analogous to CONSTEXPR_TEST.
As the test bodies of CONSTEXPR_TEST and CONSTEXPR_TYPED_TEST must be invocable at compile-time, they cannot refer to non-constexpr values. This includes the this pointer to the test fixture.