|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Functions for verifying exceptions in test cases. More...
Functions | |
| template<class Callable_T> requires std::invocable<Callable_T&> | |
| auto | micro_os_plus::micro_test_plus::nothrow (Callable_T &&func) |
| Checks whether a callable does not throw any exception, for expect() or require(). | |
| template<class Callable_T> requires std::invocable<Callable_T&> | |
| auto | micro_os_plus::micro_test_plus::throws (Callable_T &&func) |
| Checks whether a callable throws any exception, for expect() or require(). | |
| template<class Exception_T, class Callable_T> requires std::invocable<Callable_T&> | |
| auto | micro_os_plus::micro_test_plus::throws (Callable_T &&func) |
| Checks whether a callable throws a specific exception, for expect() or require(). | |
Three functions check what a callable throws, and are used as the conditions of expect() or require():
The exception is caught by the check, so it does not leave the test case. When the check fails, the report states why, for example:
A failed require() inside the callable is not an exception of the callable: it stops the test case, as it does elsewhere, and does not satisfy throws() or fail nothrow().
|
nodiscard |
| 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 check. |
The nothrow function template checks whether invoking the provided callable object does not result in the throwing of any exception. This is useful for ensuring that code under test does not unexpectedly signal error conditions.
The callable is invoked immediately, when the comparator is constructed; the result is reported when the comparator is passed to expect() or require(), which also accept optional messages.
Definition at line 116 of file exceptions-inlines.h.
References nothrow().
Referenced by nothrow().
|
nodiscard |
The callable is invoked once, immediately. The check passes if it throws an exception of any type.
| 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 check for exception throwing behaviour. |
The throws function template checks whether invoking the provided callable object results in the throwing of any exception. This is useful for ensuring that code under test properly signals error conditions.
The callable is invoked immediately, when the comparator is constructed; the result is reported when the comparator is passed to expect() or require(), which also accept optional messages.
Definition at line 97 of file exceptions-inlines.h.
|
nodiscard |
The callable is invoked once, immediately. The check passes if it throws an exception of type Exception_T or of a type derived from it, so throws<std::exception>() passes for any standard exception. An exception of another type, or no exception, fails the check, and the report states what was thrown.
| Exception_T | The type of the exception expected to be thrown. |
| 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 check for exception throwing behaviour. |
The throws function template checks whether invoking the provided callable object results in the throwing of a specific exception type. This is useful for testing error handling in code under test. Exceptions of other types are reported as failures.
The callable is invoked immediately, when the comparator is constructed; the result is reported when the comparator is passed to expect() or require(), which also accept optional messages.
Definition at line 78 of file exceptions-inlines.h.