Assertions are used to validate the unit under test behaves as expected. They can be used inside test cases, sections, and asserting functions.
Evaluates a unary or binary boolean expression. If the expression evaluates to false, marks the test run as failed and aborts the run. Reports the values of the expression to the current reporter.
expr: A side effect free unary or binary boolean expression.
- Higher-order expressions can be reduced to binary by parenthesising them.
- If the expression contains parenthesized subexpressions, only the values of the first level of expressions will be reported.
REQUIRE(b);
REQUIRE(i == 42);
REQUIRE(a && b);
REQUIRE((a && b) || c);
Evaluates a potentially throwing expression. If the expression throws, marks the test run as failed and aborts the run.
expr: A potentially throwing expression
- During constexpr evaluation, evaluation of a throw expression always results in a compile error. Therefore, this macro only makes sense in a runtime context.
REQUIRE_NOTHROW(foo());
Evaluates a potentially throwing expression. If the expression doesn't throw, marks the test run as failed and aborts the run.
expr: A potentially throwing expression
- During constexpr evaluation, evaluation of a throw expression always results in a compile error. Therefore, this macro only makes sense in a runtime context.
REQUIRE_THROWS(foo());
Evaluates a potentially throwing expression. If the expression doesn't throw an object of the given type, marks the test run as failed and aborts the run.
expr: A potentially throwing expression
- During constexpr evaluation, evaluation of a throw expression always results in a compile error. Therefore, this macro only makes sense in a runtime context.
REQUIRE_THROWS_AS(std::runtime_error, foo());
Evaluates a unary or binary boolean expression. If the expression evaluates to false, marks the test run as failed and continues the run. Reports the values of the expression to the current reporter.
expr: A side effect free unary or binary boolean expression.
- Higher-order expressions can be reduced to binary by parenthesising them.
- If the expression contains parenthesized subexpressions, only the values of the first level of expressions will be reported.
CHECK(b);
CHECK(i == 42);
CHECK(a && b);
CHECK((a && b) || c);
Evaluates a potentially throwing expression. If the expression throws, marks the test run as failed and continues the run.
expr: A potentially throwing expression
- During constexpr evaluation, evaluation of a throw expression always results in a compile error. Therefore, this macro only makes sense in a runtime context.
CHECK_NOTHROW(foo());
Evaluates a potentially throwing expression. If the expression doesn't throw, marks the test run as failed and aborts the run.
expr: A potentially throwing expression
- During constexpr evaluation, evaluation of a throw expression always results in a compile error. Therefore, this macro only makes sense in a runtime context.
CHECK_THROWS(foo());
Evaluates a potentially throwing expression. If the expression doesn't throw an object of the given type, marks the test run as failed and continues the run.
expr: A potentially throwing expression
- During constexpr evaluation, evaluation of a throw expression always results in a compile error. Therefore, this macro only makes sense in a runtime context.
CHECK_THROWS_AS(std::runtime_error, foo());
Marks the test run as failed and aborts the run.
FAIL();
Marks the test run as failed and continues the run.
FAIL_CHECK();
Logs a successful assertion and continues the run.
SUCCEED();