Skip to main content

deferred_reporter Class

Deferred reporter class for a specific expression. More...

Declaration

class micro_os_plus::micro_test_plus::detail::deferred_reporter { ... }

Included Headers

Base class

classdeferred_reporter_base

Base class for a deferred reporter that collects messages into a string. More...

Public Constructors Index

template <class Expr_T>
deferred_reporter (const Expr_T &expr, bool abort, const reflection::source_location &location, subtest &subtest, expression_formatter &expression)

Constructs a deferred reporter for a specific expression. More...

Public Destructor Index

~deferred_reporter ()=default

Destructor for the deferred reporter. More...

Public Operators Index

template <class T>
auto &operator<< (const T &msg)

Appends a message to the reporter. More...

Public Member Functions Index

boolvalue () const

Retrieves the result value. More...

Protected Member Attributes Index

boolabort_ = false

Indicates whether the reporting should abort further processing. More...

std::stringdeferred_output_ {}

String to collect the expectation message passed via operator<<(). More...

boolhas_expression_ = false

Indicates whether the reporter has an associated expression. More...

const reflection::source_locationlocation_ {}

Stores the source location associated with the report. More...

subtest &subtest_

Reference to the test case invoking this report. More...

boolvalue_ {}

Stores the result value of the report. More...

Description

Deferred reporter class for a specific expression.

The deferred_reporter class extends deferred_reporter_base to provide deferred reporting functionality for a specific test expression within the framework.

This class is responsible for capturing the expression under evaluation, the abort status, and the source location. It is intended exclusively for internal use and is implemented in the include/micro-os-plus/micro-test-plus folder to ensure a structured and modular codebase.

Definition at line 219 of file deferred-reporter.h.

Public Constructors

deferred_reporter()

template <class Expr_T>
micro_os_plus::micro_test_plus::detail::deferred_reporter::deferred_reporter (const Expr_T & expr, bool abort, const reflection::source_location & location, subtest & subtest, expression_formatter & expression)

Constructs a deferred reporter for a specific expression.

Parameters
expr

The expression under evaluation.

abort

Indicates whether reporting should abort further processing.

location

The source location relevant to the report.

subtest

The subtest that owns this deferred report.

expression

The expression formatter to format the expression text.

This constructor initialises a deferred reporter for a specific expression, capturing the evaluation result, abort status, and source location.

The expression is evaluated and its boolean result is passed to the base class. The abort flag determines whether further test execution should be halted if the expectation fails. The source location provides contextual information for reporting purposes.

Declaration at line 234 of file deferred-reporter.h, definition at line 155 of file deferred-reporter-inlines.h.

156 const Expr_T& expr, bool abort,
158 expression_formatter& expression)
159 : deferred_reporter_base{ static_cast<bool> (expr), location, subtest }
160
161 {
162#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
163 trace::printf ("%s\n", __PRETTY_FUNCTION__);
164#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
165 abort_ = abort;
167
168 expression.clear ();
169
170 expression << expr;
171 }

References micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_reporter_base, micro_os_plus::micro_test_plus::detail::deferred_reporter_base::abort_, micro_os_plus::micro_test_plus::detail::expression_formatter::clear and micro_os_plus::micro_test_plus::detail::deferred_reporter_base::has_expression_.

Public Destructor

~deferred_reporter()

micro_os_plus::micro_test_plus::detail::deferred_reporter::~deferred_reporter ()
default

Destructor for the deferred reporter.

Definition at line 241 of file deferred-reporter.h.

Public Operators

operator<<()

template <class T>
auto & micro_os_plus::micro_test_plus::detail::deferred_reporter_base::operator<< (const T & msg)

Appends a message to the reporter.

Template Parameters
T

The type of the message to append.

Parameters
msg

The message to append.

Returns

Reference to the current reporter instance.

This operator overload enables the deferred reporter to accumulate expectation messages by appending the provided value to the internal message string.

If the argument is a char, it is appended directly as a character. If the argument is of another arithmetic type, it is converted to a string using a fixed-size buffer and std::to_chars to avoid dynamic memory allocation. For all other types, the value is appended directly.

Declaration at line 153 of file deferred-reporter.h, definition at line 106 of file deferred-reporter-inlines.h.

107 {
108 if constexpr (std::is_same_v<T, char>)
109 {
110 deferred_output_.push_back (msg);
111 }
112 else if constexpr (std::is_arithmetic_v<T>)
113 {
114 // Optimise to avoid dynamic memory allocation in std::to_string by
115 // using a fixed-size buffer and std::to_chars.
116#if defined(__GNUC__)
117#pragma GCC diagnostic push
118#if defined(__clang__)
119#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
120#endif
121#endif
122 char buf[64];
123 // 64 bytes is sufficient for the longest decimal representation
124 // of any standard arithmetic type (long double ~45 chars).
125 static_assert (sizeof (buf) >= 50,
126 "buf must be large enough for any arithmetic type");
127 auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), msg);
128 if (ec == std::errc{})
129 deferred_output_.append (buf, ptr);
130#if defined(__GNUC__)
131#pragma GCC diagnostic pop
132#endif
133 }
134 else
135 {
136 deferred_output_.append (msg);
137 }
138 return *this;
139 }

Reference micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_output_.

Public Member Functions

value()

bool micro_os_plus::micro_test_plus::detail::deferred_reporter_base::value ()
inline nodiscard

Retrieves the result value.

Parameters

None.

Return Values
true

The reported condition was met.

false

The reported condition was not met.

Returns the result value stored in value_.

Declaration at line 165 of file deferred-reporter.h, definition at line 85 of file deferred-reporter-inlines.h.

86 {
87 return value_;
88 }

Reference micro_os_plus::micro_test_plus::detail::deferred_reporter_base::value_.

Referenced by micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_reporter_base.

Protected Member Attributes

abort_

bool micro_os_plus::micro_test_plus::detail::deferred_reporter_base::abort_ = false
protected

Indicates whether the reporting should abort further processing.

Definition at line 177 of file deferred-reporter.h.

177 bool abort_ = false;

Referenced by deferred_reporter and micro_os_plus::micro_test_plus::detail::deferred_reporter_base::~deferred_reporter_base.

deferred_output_

std::string micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_output_ {}
protected

String to collect the expectation message passed via operator<<().

Definition at line 193 of file deferred-reporter.h.

193 std::string deferred_output_{};

Referenced by micro_os_plus::micro_test_plus::detail::deferred_reporter_base::~deferred_reporter_base and micro_os_plus::micro_test_plus::detail::deferred_reporter_base::operator<<.

has_expression_

bool micro_os_plus::micro_test_plus::detail::deferred_reporter_base::has_expression_ = false
protected

Indicates whether the reporter has an associated expression.

Definition at line 182 of file deferred-reporter.h.

182 bool has_expression_ = false;

Referenced by deferred_reporter and micro_os_plus::micro_test_plus::detail::deferred_reporter_base::~deferred_reporter_base.

location_

const reflection::source_location micro_os_plus::micro_test_plus::detail::deferred_reporter_base::location_ {}
protected

subtest_

subtest& micro_os_plus::micro_test_plus::detail::deferred_reporter_base::subtest_
protected

value_

bool micro_os_plus::micro_test_plus::detail::deferred_reporter_base::value_ {}
protected

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


Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.17.0.