|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Expectations are checks whose outcomes are counted and reported. More...
Functions | |
| template<class Expr_T> requires extension::checkable<Expr_T> | |
| detail::check_result && | micro_os_plus::micro_test_plus::test_case::expect (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{}) |
| Evaluates a condition and reports the result. | |
t.expect (condition) checks a condition, counts the result, and reports it; when the check fails, the test case continues, so that all its checks are evaluated and reported in one run.
The condition is one of:
The values that would make the check pass by mistake do not compile: the string literals and the other character arrays and pointers, the function names, the pointers to functions and to members, and the wrappers of a bool (std::optional<bool> and the smart pointers to bool), whose condition tells whether a value is present, not what it is. The scoped enumerations do not compile either, since only a cast converts them. Write the comparison instead, such as mt::eq (flag.value (), true). With the deprecated definitions enabled, all of these are accepted, with a deprecation warning, except the wrappers of a bool and the scoped enumerations.
A message can be appended with <<, with any values that can be written, for example t.expect (x == 2) << "x is " << x;. The check is reported at the end of the statement, with the message, or, without one, with the condition.
Both checks fail; the human-readable reporter displays:
| detail::check_result && micro_os_plus::micro_test_plus::test_case::expect | ( | const Expr_T & | expr, |
| const reflection::source_location & | sl = reflection::source_location::current (), | ||
| detail::check_result && | result = detail::check_result{} ) |
| 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::expectation, and returns a reference to it. The check result evaluates the condition when initialised, and records a pass or fail when it is destroyed, at the end of the expression statement.
Definition at line 623 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::expectation, micro_os_plus::micro_test_plus::detail::check_result::init(), is_misdirected(), report_misdirected(), and micro_os_plus::micro_test_plus::detail::runnable_base::test_reporter().
Referenced by operator=().