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

Assumptions are conditions that must be satisfied for a test to proceed. More...

Functions

template<class Expr_T>
requires type_traits::checkable<Expr_T>
auto micro_os_plus::micro_test_plus::subtest::assume (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())
 Check a condition and, if false, abort test execution.

Detailed Description

When a required precondition does not hold, the test cannot execute meaningfully. If an assumption fails, the test is terminated immediately, as continuing would render the results invalid or misleading.

By explicitly defining assumptions, developers ensure that tests run only in appropriate contexts, improving the reliability and accuracy of outcomes. This mechanism is particularly valuable for guarding against invalid input, incomplete initialisation, and unsupported environments.

Function Documentation

◆ assume()

template<class Expr_T>
requires type_traits::checkable<Expr_T>
auto micro_os_plus::micro_test_plus::subtest::assume ( 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 = true. The reporter evaluates the condition, records a pass or fail when it is destroyed, and aborts execution if the condition is false.

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

346 {
347 return detail::deferred_reporter{ expr, true, sl, *this,
348 reporter ().expression () };
349 }
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=().