micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::throws_< Callable_T, Exception_T > Struct Template Reference

Operator struct template to check if an expression throws a specific exception. More...

#include <micro-os-plus/micro-test-plus.h>

Inheritance diagram for micro_os_plus::micro_test_plus::detail::throws_< Callable_T, Exception_T >:

Public Member Functions

constexpr throws_ (const Callable_T &func)
 Constructs an exception checking operator for the given callable.
constexpr operator bool () const
 Conversion operator to boolean.

Private Attributes

const bool value_ {}
 Stores the result of the callable invocation.

Detailed Description

template<class Callable_T, class Exception_T = void>
struct micro_os_plus::micro_test_plus::detail::throws_< Callable_T, Exception_T >

This specialisation 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.

Template Parameters
Callable_TThe type of the callable object to be invoked.
Exception_TThe type of the exception to check for (defaults to void for any exception).

Definition at line 644 of file detail.h.

Constructor & Destructor Documentation

◆ throws_()

template<class Callable_T, class Exception_T>
micro_os_plus::micro_test_plus::detail::throws_< Callable_T, Exception_T >::throws_ ( const Callable_T & func)
explicitconstexpr
Parameters
funcThe 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.

Definition at line 551 of file detail-inlines.h.

553 : callable_op_{ [&func]
554 {
555 try
556 {
557 func ();
558 }
559 catch (const Exception_T&)
560 {
561 return true;
562 }
563 catch (...)
564 {
565 return false;
566 }
567 return false;
568 }() }
569 {
570 }
constexpr callable_op_(bool value)
Constructs a callable operator with the pre-computed boolean result.
Operator struct template to check if an expression throws a specific exception.
Definition detail.h:645

References micro_os_plus::micro_test_plus::detail::callable_op_::callable_op_().

Referenced by micro_os_plus::micro_test_plus::detail::throws_< Callable_T, void >::throws_().

Member Function Documentation

◆ operator bool()

micro_os_plus::micro_test_plus::detail::callable_op_::operator bool ( ) const
nodiscardconstexprinherited
Parameters
None.
Returns
The result of the callable invocation.

Returns the pre-computed boolean result stored by the derived operator's constructor.

Definition at line 534 of file detail-inlines.h.

536 {
537 return value_;
538 }
const bool value_
Stores the result of the callable invocation.
Definition detail.h:621

References value_.

Member Data Documentation

◆ value_

const bool micro_os_plus::micro_test_plus::detail::callable_op_::value_ {}
privateinherited

Definition at line 621 of file detail.h.

621{};

Referenced by callable_op_(), and operator bool().


The documentation for this struct was generated from the following files: