Wire Sysio Wire Sysion 1.0.0
|
This page serves as a reference for macros that are not documented elsewhere. For now, these macros are separated into 2 rough categories, "assertion related macros" and "test case related macros".
CHECKED_IF
and CHECKED_ELSE
CHECKED_IF( expr )
is an if
replacement, that also applies Catch2's stringification machinery to the expr and records the result. As with if
, the block after a CHECKED_IF
is entered only if the expression evaluates to true
. CHECKED_ELSE( expr )
work similarly, but the block is entered only if the expr evaluated to false
.
Example:
CHECK_NOFAIL
CHECK_NOFAIL( expr )
is a variant of CHECK
that does not fail the test case if expr evaluates to false
. This can be useful for checking some assumption, that might be violated without the test necessarily failing.
Example output:
SUCCEED
SUCCEED( msg )
is mostly equivalent with INFO( msg ); REQUIRE( true );
. In other words, SUCCEED
is for cases where just reaching a certain line means that the test has been a success.
Example usage:
STATIC_REQUIRE
STATIC_REQUIRE( expr )
is a macro that can be used the same way as a static_assert
, but also registers the success with Catch2, so it is reported as a success at runtime. The whole check can also be deferred to the runtime, by defining CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
before including the Catch2 header.
Example:
METHOD_AS_TEST_CASE
METHOD_AS_TEST_CASE( member-function-pointer, description )
lets you register a member function of a class as a Catch2 test case. The class will be separately instantiated for each method registered in this way.
REGISTER_TEST_CASE
REGISTER_TEST_CASE( function, description )
let's you register a function
as a test case. The function has to have void()
signature, the description can contain both name and tags.
Example:
Note that the registration still has to happen before Catch2's session is initiated. This means that it either needs to be done in a global constructor, or before Catch2's session is created in user's own main.
ANON_TEST_CASE
ANON_TEST_CASE
is a TEST_CASE
replacement that will autogenerate unique name. The advantage of this is that you do not have to think of a name for the test case,`the disadvantage is that the name doesn't necessarily remain stable across different links, and thus it might be hard to run directly.
Example:
DYNAMIC_SECTION
DYNAMIC_SECTION
is a SECTION
where the user can use operator<<
to create the final name for that section. This can be useful with e.g. generators, or when creating a SECTION
dynamically, within a loop.
Example: