Skip to main content

The Assumptions Reference

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

Functions Index

constexpr autoassume (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())

Check a condition and, if false, abort test execution. More...

Description

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

Assumptions represent essential preconditions that must hold true for a test case to execute meaningfully. If an assumption fails, the test is immediately terminated, as continuing would render the results invalid or misleading.

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

Functions

assume()

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>
auto micro_os_plus::micro_test_plus::assume (const Expr_T & expr, const reflection::source_location & sl=reflection::source_location::current())
constexpr

Check a condition and, if false, abort test execution.

Template Parameters
Expr_TThe type of the custom expression.
(SFINAE)Enabled only if Expr_T is derived from detail::op or is convertible to bool.
Parameters
[in] exprLogical expression to evaluate.
[in] slOptional source location, defaulting to the current line.
Returns

An output stream to write optional messages.

The assume function template evaluates a logical condition or custom expression and reports the result within the µTest++ framework. It is designed to provide detailed diagnostics for test failures, including the actual and expected values, when using the provided comparators (eq(), ne(), lt(), le(), gt(), ge()) or custom operators.

The function template can be used with any expression that evaluates to a boolean or with custom comparators/operators derived from the local detail::op type. For complex checks performed outside the expect() logical expression (such as within if or try/catch statements), the result can be reported by calling expect(true) or expect(false).

The function returns an output stream, allowing optional messages to be appended to the test report.

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

Definition at line 188 of file micro-test-plus-inlines.h.


Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.