|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Requirements are checks that stop the test case when they fail. More...
Functions | |
| template<class Expr_T> requires extension::checkable<Expr_T> | |
| detail::check_result && | micro_os_plus::micro_test_plus::test_case::require (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{}) |
| Checks a condition and, if false, stops the test case. | |
t.require (condition) checks a condition as expect() does, and also stops the test case when it fails. Use it when the rest of the test case depends on the condition, for example to check that a pointer is not null before using it.
A failed requirement is reported and counted like a failed expectation. What follows depends on the build:
| detail::check_result && micro_os_plus::micro_test_plus::test_case::require | ( | const Expr_T & | expr, |
| const reflection::source_location & | sl = reflection::source_location::current (), | ||
| detail::check_result && | result = detail::check_result{} ) |
The failure is reported and counted as for expect(); then, when exceptions are enabled, the rest of the test case body is skipped, and the run continues with the next test case, as ASSERT_* in GoogleTest, REQUIRE() in Catch2 and doctest, and BOOST_REQUIRE() in Boost.Test do. Without exceptions, the test execution is aborted with runner::abort().
The test case is stopped by throwing a private exception, at the end of the statement, after the optional message was appended. It is not derived from std::exception; a catch (...) in the test case body must rethrow it, and the body must not be noexcept.
| Expr_T | The type of the custom expression. |
| expr | Logical expression to evaluate. |
| sl | Optional source location, defaulting to the current line. |
| result | The check result, a temporary created by the caller as the default argument, which the applications do not pass; it is destroyed at the end of the statement. |
Initialises the detail::check_result received as the last argument, a temporary created by the caller, with the kind detail::check_kind::requirement, and returns a reference to it. The check result evaluates the condition when initialised, records a pass or fail when it is destroyed, and, if the condition is false, stops the test case by throwing detail::failed_requirement (caught by test_case::run()), or, without exceptions, aborts the test execution.
Definition at line 683 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::check_result::init(), is_misdirected(), report_misdirected(), micro_os_plus::micro_test_plus::detail::requirement, and micro_os_plus::micro_test_plus::detail::runnable_base::test_reporter().
Referenced by assume().