Skip to main content

The deferred_reporter_base Class Reference

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

Declaration

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

Included Headers

Derived Classes

classdeferred_reporter<Expr_T>

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

Public Constructors Index

deferred_reporter_base (bool value, const reflection::source_location location)

Constructs a deferred reporter base. More...

Public Destructor Index

~deferred_reporter_base ()

Destructor for the deferred reporter base. More...

Public Operators Index

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

Appends a message to the reporter. More...

Public Member Functions Index

constexpr boolvalue () const

Retrieves the result value. More...

Protected Member Attributes Index

boolabort_ = false

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

const reflection::source_locationlocation_ {}

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

std::stringmessage_ {}

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

boolvalue_ {}

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

Description

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

The deferred_reporter_base class serves as the foundational component for deferred reporting within the framework. It is responsible for collecting expectation messages, typically passed via the operator<<(), into a string for later reporting.

This class maintains the result value, abort status, and the source location associated with the report. 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 1744 of file detail.h.

Public Constructors

deferred_reporter_base()

micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_reporter_base (bool value, const reflection::source_location location)

Constructs a deferred reporter base.

Parameters
value

The result value associated with the report.

location

The source location relevant to the report.

This constructor updates the current test suite's statistics based on the outcome of the test expression. If the evaluated value is true, the count of successful tests is incremented; otherwise, the count of failed tests is incremented. The source location is recorded for reporting purposes, enabling precise identification of the test case within the relevant file or folder.

Declaration at line 1753 of file detail.h, definition at line 218 of file micro-test-plus.cpp.

219 bool value, const reflection::source_location location)
220 : value_{ value }, location_{ location }
221 {
222 if (value_)
223 {
224 current_test_suite->increment_successful ();
225 }
226 else
227 {
228 current_test_suite->increment_failed ();
229 }
230 }

References micro_os_plus::micro_test_plus::current_test_suite, location_, value and value_.

Referenced by micro_os_plus::micro_test_plus::detail::deferred_reporter< Expr_T >::deferred_reporter.

Public Destructor

~deferred_reporter_base()

micro_os_plus::micro_test_plus::detail::deferred_reporter_base::~deferred_reporter_base ()

Destructor for the deferred reporter base.

The destructor ensures that if an abort condition is set and the test expression has failed, the test output is flushed and the process is terminated. This mechanism guarantees immediate feedback and halts further execution upon critical test failures, aiding in rapid identification and resolution of issues during test runs.

Declaration at line 1759 of file detail.h, definition at line 240 of file micro-test-plus.cpp.

241 {
242#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
243 printf ("%s\n", __PRETTY_FUNCTION__);
244#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
245
246 if (abort_ && !value_)
247 {
248 printf ("\n");
249 reporter.output ();
250 abort ();
251 }
252 }

References abort_, micro_os_plus::micro_test_plus::reporter and value_.

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 of an arithmetic type, it is first converted to a string using std::to_string before being appended. For all other types, the value is appended directly. This ensures that both numeric and string-like messages are handled appropriately and consistently.

Declaration at line 1770 of file detail.h, definition at line 90 of file details-inlines.h.

91 {
92 if constexpr (std::is_arithmetic_v<T>)
93 {
94 message_.append (std::to_string (msg));
95 }
96 else
97 {
98 message_.append (msg);
99 }
100 return *this;
101 }

Reference message_.

Public Member Functions

value()

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

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 associated with the report.

Definition at line 1786 of file detail.h.

1786 value () const
1787 {
1788 return value_;
1789 }

Reference value_.

Referenced by deferred_reporter_base.

Protected Member Attributes

abort_

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

location_

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

Stores the source location associated with the report.

Definition at line 1806 of file detail.h.

Referenced by deferred_reporter_base and micro_os_plus::micro_test_plus::detail::deferred_reporter< Expr_T >::~deferred_reporter.

message_

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

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

Definition at line 1812 of file detail.h.

1812 std::string message_{};

Referenced by micro_os_plus::micro_test_plus::detail::deferred_reporter< Expr_T >::~deferred_reporter and operator<<.

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 by Doxygen 1.14.0.