|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Operator struct template to check if an expression throws a specific exception. More...
#include "micro-os-plus/micro-test-plus.h"
Public Types | |
| using | op_type = op |
| Marker identifying the framework expression types. | |
Public Member Functions | |
| template<class Callable_T> requires std::invocable<Callable_T&> | |
| throws_op (Callable_T &&func) | |
| Constructs an exception checking operator for the given callable. | |
| constexpr | operator bool () const |
| Conversion operator to boolean. | |
| throw_outcome | outcome (void) const noexcept |
| Retrieves what the invocation threw. | |
| const std::string & | what (void) const noexcept |
| Retrieves the what() of the std::exception thrown. | |
Private Attributes | |
| throw_outcome | outcome_ { throw_outcome::none } |
| Stores what the invocation threw, when the check failed. | |
| const bool | value_ {} |
| Stores the result of the callable invocation. | |
| std::string | what_ {} |
| Stores the what() of the std::exception thrown, when the check failed. | |
This primary template checks whether invoking the given callable throws an exception of the specified type. The check is performed at construction time, with the result cached for reporting and composition. Use this when a test must verify that an operation raises an expected exception of a particular type.
The callable is used only by the constructor, so it is a parameter of the constructor, not of the struct; all checks of the same exception type share one struct, and one formatter instantiation.
| Exception_T | The type of the exception to check for (defaults to void for any exception). |
|
inherited |
Detected by the extension::is_op concept, and inherited by all types derived from op.
Definition at line 128 of file extension.h.
|
explicit |
| Callable_T | The type of the callable object to be invoked; it must be invocable without arguments, as an lvalue, so a mutable lambda is accepted. |
| func | The callable object to be invoked. |
Invokes func inside a try/catch block. If func throws an exception of type Exception_T, the result is true; if it throws any other exception the result is false; if no exception is thrown the result is false. The result is passed to the callable_op base class constructor, with what was thrown, if the result is false, to be written in the report: nothing, a std::exception, with its what(), or another exception.
The failed_requirement thrown to stop the test case after a failed require() in func is not an exception of func, and is rethrown.
Definition at line 1188 of file detail-inlines.h.
References micro_os_plus::micro_test_plus::detail::callable_op::callable_op(), micro_os_plus::micro_test_plus::detail::none, micro_os_plus::micro_test_plus::detail::std_exception, and micro_os_plus::micro_test_plus::detail::unknown_exception.
Referenced by micro_os_plus::micro_test_plus::detail::throws_op< void >::throws_op().
|
nodiscardconstexprinherited |
Returns the result computed by the constructor of the derived operator; the callable is not invoked again.
Definition at line 1136 of file detail-inlines.h.
References value_.
|
inlinenodiscardnoexceptinherited |
Returns what was recorded when the check failed.
Definition at line 1147 of file detail-inlines.h.
References outcome_.
Referenced by callable_op().
|
inlinenodiscardnoexceptinherited |
Returns the text recorded when a std::exception was thrown.
Definition at line 1157 of file detail-inlines.h.
References what_.
Referenced by callable_op().
|
privateinherited |
Copied from the callable_result by the constructor.
Definition at line 1461 of file detail.h.
Referenced by callable_op(), and outcome().
|
privateinherited |
Computed once, by the derived operator constructor, which invokes the callable.
Definition at line 1453 of file detail.h.
Referenced by callable_op(), and operator bool().
|
privateinherited |
Moved from the callable_result by the constructor; empty in the usual case, so nothing is allocated.
Definition at line 1471 of file detail.h.
Referenced by callable_op(), and what().