Always assertions
Always assertions assert that every time the assertion is encountered, some condition is true. If a single counterexample to the asserted property is found, the assertion will fail. See the always properties documentation for further details.condition is true every time this macro is called, and that it is called at least once. The corresponding test property will be viewable in the Antithesis SDK: Always group of your triage report.
Parameters: See common parameters below.
Example
condition is true every time this macro is called. The corresponding test property will pass if the assertion is never encountered (unlike Always assertion types). This test property will be viewable in the “Antithesis SDK: Always” group of your triage report.
This function is similar to assertions in most assertions libraries that you may be familiar with.
Parameters: See common parameters below.
ALWAYS(left > right, message, details) etc.
Parameters: T is numeric. See also common parameters below.
Example
named_bools is true. Equivalent to ALWAYS(named_bools[0].second || named_bools[1].second || ..., message, details). If you use these macros for assertions about the behavior of booleans, you may help Antithesis find more bugs. Information about named_bools will automatically be added to the details parameter, and the keys will be the names of the bools.
Parameters: See common parameters below. Note that the NAMED_LIST utility macro is provided to pass the named_bools argument more conveniently.
Example
Sometimes assertions
Sometimes assertions assert that at least one time the assertion is encountered, some condition is true. If a single example of the asserted property is found, the assertion will pass. See why you should use sometimes properties for further details.condition is true at least one time that this macro was called. (If the assertion is never encountered, the test property will therefore fail.) This test property will be viewable in the “Antithesis SDK: Sometimes” group.
Parameters: See common parameters below.
Example
SOMETIMES(T left > T right, ...) etc.
Parameters:
SOMETIMES(named_bools[0].second && named_bools[1].second && ..., message, details). If you use these macros for assertions about the behavior of booleans, you may help Antithesis find more bugs. Information about named_bools will automatically be added to the details parameter, and the keys will be the names of the bools.
Parameters:
Note that the NAMED_LIST utility macro is provided to pass the named_bools argument more conveniently.
Common parameters
message
const char* that must be known at compile time. A human readable identifier used to aggregate assertions. Antithesis generates one test property per uniquemessage and this test property will be named message in triage reports.
This test property either passes or fails, which depends upon the evaluation of every assertion that shares its message. Different assertions in different parts of the code should have different message, but the same assertion should always have the same message even if it is moved to a different file.
details
Utility macros
The macroNAMED_LIST is provided to conveniently pass arguments to boolean assertions such as SOMETIMES_ALL and ALWAYS_SOME. It can also be used to pass the details argument.
NAMED_LIST(foo, bar, baz) expands to { { "foo", foo }, { "bar", bar }, { "baz", baz } }.
NAMED_LIST(dog.say("woof"), cat.say("meow")) expands to { { "dog.say(\"woof\")", dog.say("woof") }, { "cat.say(\"meow\")", cat.say("meow") } }.
The macro takes between 1 and 10 parameters (inclusive). Contact us if you require the macro to support more parameters.
Additional Considerations
Assertions can be added to template definitions. However, you should ensure that the assertion identifiermessage is distinct for each instantiation of the template.
We recommend using the __PRETTY_FUNCTION__ macro, which shows the actual name of the instantiated function or method. This should be used in message to ensure that each instantiation’s assertion has a unique identifier:
__PRETTY_FUNCTION__ can be included in the details associated with the assertion: