micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
Expectations

Expectations are checks whose outcomes are counted and reported. More...

Functions

template<class Expr_T>
requires type_traits::checkable<Expr_T>
auto micro_os_plus::micro_test_plus::subtest::expect (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())
 Evaluate a generic condition and report the results.

Detailed Description

During test execution, each condition outcome, whether passing or failing, is explicitly reported in test results. Unlike assumptions, a failed expectation does not terminate the test; execution continues, allowing multiple conditions to be checked within a single test case.

This approach enables comprehensive validation of code behaviour, because all relevant expectations can be evaluated and reported in one run. Using expectations provides detailed insight into which aspects of the code meet requirements and which do not, supporting thorough and efficient testing.

Function Documentation

◆ expect()

template<class Expr_T>
requires type_traits::checkable<Expr_T>
auto micro_os_plus::micro_test_plus::subtest::expect ( const Expr_T & expr,
const reflection::source_location & sl = reflection::source_location::current () )
Template Parameters
Expr_TThe type of the custom expression.
Constraints
Enabled only if Expr_T is derived from detail::op or is convertible to bool (enforced via a C++20 requires clause).
Parameters
[in]exprLogical expression to evaluate.
[in]slOptional source location, defaulting to the current line.
Returns
An output stream to write optional messages.

Constructs and returns a deferred_reporter<Expr_T> with abort = false. The reporter evaluates the condition and records a pass or fail when it is destroyed at the end of the expression statement.

Definition at line 330 of file test-inlines.h.

331 {
332 return detail::deferred_reporter{ expr, false, sl, *this,
333 reporter ().expression () };
334 }
class reporter & reporter(void) const noexcept
Definition test.cpp:187
detail::expression_formatter & expression()
Provides access to the expression formatter for this reporter.

References micro_os_plus::micro_test_plus::reporter::expression(), and micro_os_plus::micro_test_plus::detail::runnable< subtest >::reporter().

Referenced by operator=().