micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
Expectations

Expectations are checks whose results are reported. More...

Functions

template<class Expr_T , type_traits::requires_t< type_traits::is_op_v< Expr_T > or type_traits::is_convertible_v< Expr_T, bool > > = 0>
constexpr auto micro_os_plus::micro_test_plus::expect (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())
 Evaluate a generic condition and report the results.
 

Detailed Description

Expectations are checks whose results are reported.

Failed expectations report the failure but do not break the test (as opposed to assumptions).

Function Documentation

◆ expect()

template<class Expr_T , type_traits::requires_t< type_traits::is_op_v< Expr_T > or type_traits::is_convertible_v< Expr_T, bool > > = 0>
constexpr auto micro_os_plus::micro_test_plus::expect ( const Expr_T & expr,
const reflection::source_location & sl = reflection::source_location::current () )
constexpr

Evaluate a generic condition and report the results.

Template Parameters
Expr_TThe type of the custom expression.
Parameters
[in]exprLogical expression to evaluate.
[in]slOptional source location, by default the current line.
Returns
An output stream to write optional messages.

The expression can be any logical expression, but, in order to allow the framework to help identify the reason why the check failed (by displaying the actual vs. the expected values), the expression should use the provided eq(), ne(), lt(), le(), gt(), ge() comparators, or, if the custom operators namespace is included, to use the custom type operands.

The function template can be used only for expressions that evaluate to a boolean or use custom comparators/operators derived from the local detail::op type.

For generic checks performed with standard C/C++ if statements outside the expect() logical expression (like complex try/catch statements), the results can be reported with expect(true) or expect(false).

Example
mt::expect (compute_answer () == 42) << "answer is 42";

Definition at line 140 of file micro-test-plus.h.