Skip to main content

reporter Class

Reporter to display test results, including operand values and types for failures. More...

Declaration

class micro_os_plus::micro_test_plus::reporter { ... }

Included Headers

Derived Classes

classreporter_human

Human (standard output) implementation of reporter. More...

classreporter_tap

TAP (Test Anything Protocol) implementation of reporter. More...

Public Constructors Index

reporter (std::unique_ptr< std::vector< std::string_view > > argvs)

Constructor for the reporter class. More...

Public Destructor Index

~reporter ()

Virtual destructor for the reporter class. More...

Public Operators Index

reporter &operator<< (bool v)

Output operator for boolean values. More...

reporter &operator<< (char c)

Output operator for a single character. More...

reporter &operator<< (const char *s)

Output operator for a constant character string. More...

reporter &operator<< (reporter &(*func)(reporter &))

Output operator to display the endl. More...

reporter &operator<< (std::nullptr_t)

Output operator for nullptr. More...

reporter &operator<< (std::string_view sv)

Output operator for std::string_view. More...

template <typename T>
reporter &operator<< (T *v)

Output operator to display any pointer. More...

template <class T>
reporter &operator<< (T v)

Output operator for arithmetic types, with type suffixes. More...

Public Member Functions Index

voidbegin_session (runner &runner)=0

Mark the beginning of a test session. More...

voidbegin_subtest (subtest &subtest)=0

Mark the beginning of a subtest. More...

voidbegin_suite (suite &suite)=0

Mark the beginning of a test suite. More...

voidend_session (runner &runner)=0

Mark the end of a test session. More...

voidend_subtest (subtest &subtest)=0

Mark the end of a subtest. More...

voidend_suite (suite &suite)=0

Mark the end of a test suite. More...

voidendline (void)

Inserts a line ending into the output buffer. More...

detail::expression_formatter &expression ()

Provides access to the expression formatter for this reporter. More...

voidfail (bool abort, std::string &message, const std::string &expression, bool has_expression, const reflection::source_location &location, subtest &subtest)

Report a failed condition. More...

voidflush (void)

Flush the current buffered content. More...

const char *get_comment_prefix (void)=0

Returns the comment-prefix string used by this reporter format. More...

voidpass (std::string &message, const std::string &expression, subtest &subtest)

Report a passed condition. More...

micro_test_plus::verbosityverbosity () const

Returns the current verbosity level. More...

voidwrite_buffer_to_stdout (void)

Output the current buffered content. More...

Protected Member Functions Index

autocolour_ (const bool cond) const

Selects the appropriate colour code based on a condition. More...

voidoutput_fail_prefix_ (std::string &message, const bool has_expression, const reflection::source_location &location, subtest &subtest)=0

Outputs the prefix for a failing condition. More...

voidoutput_fail_suffix_ (const reflection::source_location &location, bool abort, subtest &subtest)=0

Outputs the suffix for a failing condition. More...

voidoutput_pass_prefix_ (std::string &message, subtest &subtest)=0

Outputs the prefix for a passing condition. More...

voidoutput_pass_suffix_ (subtest &subtest)=0

Outputs the suffix for a passing condition. More...

voidwrite_buffer_to_file_ (void)
voidwrite_info_ (void)

Appends informational (non-result) text to the output buffer. More...

Protected Member Attributes Index

booladd_empty_line_ { true }

Controls whether to add an empty line between successful test cases. More...

std::unique_ptr< std::vector< std::string_view > >argvs_ {}

Owns the command-line arguments passed to the test runner. More...

std::stringbuffer_ {}

Output accumulation buffer. More...

detail::colourscolours_ {}

ANSI colour codes for output formatting. More...

detail::expression_formatterexpression_ { colours_ }

Expression formatter for pass and fail reporting. More...

FILE *output_file_ { nullptr }

Optional output file for redirecting test report output. More...

const char *output_file_path_ { nullptr }

Optional file path for redirecting test report output. More...

enum verbosityverbosity_ = verbosity::normal

The verbosity level for test reporting. More...

Description

Reporter to display test results, including operand values and types for failures.

The reporter class is responsible for formatting and presenting test results within the µTest++ framework. It provides a comprehensive suite of output operators for a wide range of data types, containers, and comparator expressions, enabling detailed and informative reporting of test outcomes.

For failed tests, the reporter prints the actual values of the operands along with their types, supporting precise diagnostics and efficient debugging. The class supports multiple verbosity levels and colour-coded output to distinguish between successful and failed tests, thereby enhancing the clarity and professionalism of test reports.

The reporter also offers methods for reporting the commencement and completion of test cases and suites, as well as for handling pass and fail conditions. Additional features include output stream manipulators, support for exception-related expressions, and configurable formatting options.

All members and methods are defined within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

Definition at line 185 of file reporter.h.

Public Constructors

reporter()

micro_os_plus::micro_test_plus::reporter::reporter (std::unique_ptr< std::vector< std::string_view > > argvs)

Constructor for the reporter class.

Parameters
argvs

Owning pointer to the command-line arguments vector; the reporter takes ownership via move.

Moves the supplied argument vector into argvs_ and scans it for the --verbose, --quiet, --silent, and --output-file= options, adjusting verbosity_ and optionally opening the output file. If the output file path is specified but the file cannot be opened, the process exits with a diagnostic error message. The internal string buffer is pre-allocated to reduce dynamic allocation overhead.

Declaration at line 194 of file reporter.h, definition at line 79 of file reporter.cpp.

79 reporter::reporter (std::unique_ptr<std::vector<std::string_view>> argvs)
80 {
81#if defined(MICRO_OS_PLUS_TRACE) \
82 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
83 trace::printf ("%s\n", __PRETTY_FUNCTION__);
84#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
85
86 std::string_view output_file_sv{};
87
88 argvs_ = std::move (argvs);
89
90 static constexpr std::string_view output_file_prefix{ "--output-file=" };
91 if (argvs_)
92 {
93 const auto& args = *argvs_;
94 for (size_t i = 0; i < args.size (); ++i)
95 {
96 if (args[i] == "--verbose")
97 {
99 }
100 else if (args[i] == "--quiet")
101 {
103 }
104 else if (args[i] == "--silent")
105 {
107 }
108 else if (args[i].starts_with (output_file_prefix))
109 {
110 output_file_sv = args[i].substr (output_file_prefix.size ());
111 }
112 else if (args[i]
113 == output_file_prefix.substr (
114 0, output_file_prefix.size () - 1))
115 {
116 if (i + 1 < args.size ())
117 {
118 output_file_sv = args[++i];
119 }
120 else
121 {
122 fprintf (stderr, "error: --output-file option requires a "
123 "file path argument\n");
124 exit (1);
125 }
126 }
127 }
128 }
129
130 if (!output_file_sv.empty ())
131 {
132 // .data() is safe: all string_views are views into argv[]
133 // entries, which are null-terminated C strings.
134 output_file_ = fopen (output_file_sv.data (), "w");
135 if (output_file_ == nullptr)
136 {
137#if defined(__GNUC__)
138#pragma GCC diagnostic push
139#if defined(__clang__)
140#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
141#endif
142#endif
143 fprintf (stderr, "error: Failed to open output file '%.*s'\n",
144 static_cast<int> (output_file_sv.size ()),
145 output_file_sv.data ());
146#if defined(__GNUC__)
147#pragma GCC diagnostic pop
148#endif
149 exit (1);
150 }
151 // The original string is zero terminated, so we can safely use .data()
152 // here.
153 output_file_path_ = output_file_sv.data ();
154 }
155
156 // Pre-allocate buffer to reduce dynamic allocations.
157 buffer_.reserve (128);
158 }

References argvs_, buffer_, output_file_, output_file_path_, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::verbose and verbosity_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::reporter_human, micro_os_plus::micro_test_plus::reporter_tap::reporter_tap, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<< and operator<<.

Public Destructor

~reporter()

micro_os_plus::micro_test_plus::reporter::~reporter ()
virtual

Virtual destructor for the reporter class.

If an output file was opened, it is flushed and closed, and a confirmation message naming the output file is written to stdout. If tracing is enabled, the function signature is output for diagnostic purposes.

Declaration at line 199 of file reporter.h, definition at line 167 of file reporter.cpp.

168 {
169#if defined(MICRO_OS_PLUS_TRACE) \
170 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
171 trace::printf ("%s\n", __PRETTY_FUNCTION__);
172#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
173
174 if (output_file_ != nullptr)
175 {
176 fflush (output_file_);
177 fclose (output_file_);
178
179#if defined(__GNUC__)
180#pragma GCC diagnostic push
181#if defined(__clang__)
182#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
183#endif
184#endif
185 printf ("Test output written to '%s'.\n", output_file_path_);
186#if defined(__GNUC__)
187#pragma GCC diagnostic pop
188#endif
189
190 output_file_ = nullptr;
191 output_file_path_ = nullptr;
192 }
193 }

References output_file_ and output_file_path_.

Public Operators

operator<<()

reporter & micro_os_plus::micro_test_plus::reporter::operator<< (bool v)

Output operator for boolean values.

Parameters
v

The boolean value to output.

Returns

Reference to the current reporter instance.

Definition at line 234 of file reporter.h.

Reference reporter.

operator<<()

reporter & micro_os_plus::micro_test_plus::reporter::operator<< (char c)

Output operator for a single character.

Parameters
c

The character to output.

Returns

Reference to the current reporter instance.

This operator overload appends the specified character to the internal output buffer of the reporter. It enables efficient streaming of individual characters into the reporter, supporting precise and flexible formatting of test output across all test cases and folders.

Declaration at line 216 of file reporter.h, definition at line 416 of file reporter.cpp.

417 {
418 buffer_.append (1, c);
419 return *this;
420 }

References reporter and buffer_.

operator<<()

reporter & micro_os_plus::micro_test_plus::reporter::operator<< (const char * s)

Output operator for a constant character string.

Parameters
s

The string to output.

Returns

Reference to the current reporter instance.

This operator overload appends the contents of the provided C-style string to the internal output buffer of the reporter. It enables efficient streaming of string literals and character arrays into the reporter, supporting clear and flexible formatting of test output across all test cases and folders.

Declaration at line 225 of file reporter.h, definition at line 431 of file reporter.cpp.

431 reporter::operator<<(const char* s)
432 {
433 buffer_.append (s);
434 return *this;
435 }

References reporter and buffer_.

operator<<()

reporter & micro_os_plus::micro_test_plus::reporter::operator<< (reporter &(*)(reporter &) func)

Output operator to display the endl.

Parameters
func

Function pointer to the stream manipulator.

Returns

Reference to the current reporter instance.

This operator overload enables manipulators, such as endl, to be used with the reporter stream in a manner similar to standard C++ streams. When a manipulator function is passed, it is invoked with the current reporter instance, allowing for seamless integration of stream operations and improved readability of test output across all test cases and folders.

Declaration at line 274 of file reporter.h, definition at line 386 of file reporter.cpp.

387 {
388 // Call the endl function.
389 (*func) (*this);
390 return *this;
391 }

Reference reporter.

operator<<()

reporter & micro_os_plus::micro_test_plus::reporter::operator<< (std::nullptr_t)

Output operator for nullptr.

Returns

Reference to the current reporter instance.

Definition at line 241 of file reporter.h.

References reporter and expression.

operator<<()

reporter & micro_os_plus::micro_test_plus::reporter::operator<< (std::string_view sv)

Output operator for std::string_view.

Parameters
sv

The string view to output.

Returns

Reference to the current reporter instance.

This operator overload appends the contents of the provided std::string_view to the internal output buffer of the reporter. It enables seamless streaming of string data into the reporter, supporting clear and efficient formatting of test output across all test cases and folders.

Declaration at line 207 of file reporter.h, definition at line 402 of file reporter.cpp.

402 reporter::operator<<(std::string_view sv)
403 {
404 buffer_.append (sv);
405 return *this;
406 }

References reporter and buffer_.

operator<<()

template <typename T>
reporter & micro_os_plus::micro_test_plus::reporter::operator<< (T * v)

Output operator to display any pointer.

Template Parameters
T

The type of the pointer.

Parameters
v

The pointer value to output.

Returns

Reference to the current reporter instance.

This operator overload enables the reporter to output pointer values in a consistent and readable format.

Null pointers are always rendered as the string "nullptr", regardless of the platform, avoiding platform-specific behaviour such as "(nil)" on Linux/glibc or "0x0" on macOS.

Non-null pointers are formatted as a hexadecimal address using snprintf with the p format specifier. The resulting string is appended to the internal output buffer, allowing pointer values to be included in test reports and diagnostics.

This approach provides clear and unambiguous representation of pointer addresses, which is particularly useful for debugging and verifying pointer-related test cases.

Declaration at line 265 of file reporter.h, definition at line 144 of file reporter-inlines.h.

145 {
146 if (v == nullptr)
147 {
148 // Explicitly render null pointers as "0x0" to avoid platform-specific
149 // representations such as "(nil)" on Linux/glibc.
150 buffer_.append ("0x0");
151 return *this;
152 }
153#if defined(__GNUC__)
154#pragma GCC diagnostic push
155#if defined(__clang__)
156#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
157#endif
158#endif
159 char buff[20];
160 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
161 buffer_.append (buff);
162#if defined(__GNUC__)
163#pragma GCC diagnostic pop
164#endif
165
166 return *this;
167 }

References reporter and buffer_.

operator<<()

template <class T>
reporter & micro_os_plus::micro_test_plus::reporter::operator<< (T v)

Output operator for arithmetic types, with type suffixes.

Template Parameters
T

The arithmetic type.

Parameters
v

The value to output.

Returns

Reference to the current reporter instance.

This template operator overload allows the reporter to output values of any arithmetic type (integral or floating-point) in a consistent and readable format. The value is formatted using the append_number_ helper function, which handles the conversion to a string representation with appropriate type suffixes where applicable (e.g., "f" for float, "l" for long double). This enables numeric values to be included in test reports and diagnostics in a clear and unambiguous manner, supporting the verification of test cases that involve arithmetic expressions and comparisons.

Declaration at line 253 of file reporter.h, definition at line 184 of file reporter-inlines.h.

185 {
187 return *this;
188 }

References reporter, micro_os_plus::micro_test_plus::detail::append_number_ and buffer_.

Public Member Functions

begin_session()

virtual void micro_os_plus::micro_test_plus::reporter::begin_session (runner & runner)

Mark the beginning of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

Definition at line 363 of file reporter.h.

begin_subtest()

virtual void micro_os_plus::micro_test_plus::reporter::begin_subtest (subtest & subtest)

Mark the beginning of a subtest.

Parameters
subtest

Reference to the subtest.

Returns

Nothing.

Definition at line 407 of file reporter.h.

Referenced by micro_os_plus::micro_test_plus::subtest::run.

begin_suite()

virtual void micro_os_plus::micro_test_plus::reporter::begin_suite (suite & suite)

Mark the beginning of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

Definition at line 385 of file reporter.h.

Referenced by micro_os_plus::micro_test_plus::static_suite::run.

end_session()

virtual void micro_os_plus::micro_test_plus::reporter::end_session (runner & runner)

Mark the end of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

Definition at line 374 of file reporter.h.

end_subtest()

virtual void micro_os_plus::micro_test_plus::reporter::end_subtest (subtest & subtest)

Mark the end of a subtest.

Parameters
subtest

Reference to the subtest.

Returns

Nothing.

Definition at line 418 of file reporter.h.

end_suite()

virtual void micro_os_plus::micro_test_plus::reporter::end_suite (suite & suite)

Mark the end of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

Definition at line 396 of file reporter.h.

Referenced by micro_os_plus::micro_test_plus::static_suite::run.

endline()

void micro_os_plus::micro_test_plus::reporter::endline (void)

Inserts a line ending into the output buffer.

Parameters

None.

Returns

Nothing.

This method appends a newline character to the internal output buffer of the reporter and immediately flushes the stream. This ensures that each line of test output is clearly separated and promptly displayed, enhancing the readability and organisation of test results across all test cases and folders.

Declaration at line 291 of file reporter.h, definition at line 221 of file reporter.cpp.

222 {
223 buffer_.append ("\n");
224 flush ();
225 }

References buffer_ and flush.

Referenced by micro_os_plus::micro_test_plus::reporter_human::operator<<.

expression()

detail::expression_formatter & micro_os_plus::micro_test_plus::reporter::expression ()
inline

Provides access to the expression formatter for this reporter.

Parameters

None.

Returns

Reference to the expression_formatter instance used by this reporter.

Returns a reference to the expression_formatter instance used by the reporter for formatting expressions in test reports. This allows the reporter to delegate the formatting of complex expressions to the expression_formatter, which provides a consistent and extensible way to convert various types of values and expressions into their string representations for output in test reports.

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

107 {
108 return expression_;
109 }

Reference expression_.

Referenced by micro_os_plus::micro_test_plus::subtest::assume, micro_os_plus::micro_test_plus::subtest::expect, fail, get_comment_prefix, operator<< and pass.

fail()

void micro_os_plus::micro_test_plus::reporter::fail (bool abort, std::string & message, const std::string & expression, bool has_expression, const reflection::source_location & location, subtest & subtest)

Report a failed condition.

Parameters
abort

Whether to abort execution after failure.

message

The message to display.

expression

The string representation of the expression.

has_expression

Whether the expression is a compound op to display.

location

The source location of the failure.

subtest

The subtest that owns this check.

Returns

Nothing.

Reports a test failure, formatting the output with source location and, when has_expression is true, the pre-formatted expression string.

Declaration at line 349 of file reporter.h, definition at line 463 of file reporter.cpp.

463 reporter::fail (bool abort, std::string& message,
464 const std::string& expression, bool has_expression,
465 const reflection::source_location& location,
467 {
468 output_fail_prefix_ (message, has_expression, location, subtest);
469
470 if (has_expression)
471 {
472 *this << expression;
473 }
474
475 output_fail_suffix_ (location, abort, subtest);
476 }

References expression, output_fail_prefix_ and output_fail_suffix_.

flush()

void micro_os_plus::micro_test_plus::reporter::flush (void)

Flush the current buffered content.

Parameters

None.

Returns

Nothing.

This method flushes the output buffer of the reporter by synchronising it with the standard output stream. This guarantees that all pending test output is immediately written and visible, ensuring prompt and reliable reporting of test results across all test cases and folders.

Declaration at line 318 of file reporter.h, definition at line 365 of file reporter.cpp.

366 {
367 fflush (stdout);
368 if (output_file_ != nullptr)
369 {
370 fflush (output_file_);
371 }
372 }

Reference output_file_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::begin_session, micro_os_plus::micro_test_plus::reporter_tap::begin_session, micro_os_plus::micro_test_plus::reporter_human::begin_subtest, micro_os_plus::micro_test_plus::reporter_tap::begin_subtest, micro_os_plus::micro_test_plus::reporter_human::begin_suite, micro_os_plus::micro_test_plus::reporter_tap::begin_suite, micro_os_plus::micro_test_plus::reporter_human::end_session, micro_os_plus::micro_test_plus::reporter_tap::end_session, micro_os_plus::micro_test_plus::reporter_human::end_subtest, micro_os_plus::micro_test_plus::reporter_tap::end_subtest, micro_os_plus::micro_test_plus::reporter_human::end_suite, micro_os_plus::micro_test_plus::reporter_tap::end_suite, endline, micro_os_plus::micro_test_plus::reporter_human::output_fail_suffix_, micro_os_plus::micro_test_plus::reporter_tap::output_fail_suffix_, micro_os_plus::micro_test_plus::reporter_human::output_pass_suffix_ and micro_os_plus::micro_test_plus::reporter_tap::output_pass_suffix_.

get_comment_prefix()

virtual const char * micro_os_plus::micro_test_plus::reporter::get_comment_prefix (void)

Returns the comment-prefix string used by this reporter format.

Parameters

None.

Returns

A null-terminated prefix string.

Definition at line 429 of file reporter.h.

References colour_, expression, verbosity, write_buffer_to_file_ and write_info_.

pass()

void micro_os_plus::micro_test_plus::reporter::pass (std::string & message, const std::string & expression, subtest & subtest)

Report a passed condition.

Parameters
message

The message to display.

expression

The string representation of the expression.

subtest

The subtest that owns this check.

Returns

Nothing.

Outputs a pass prefix, followed by either the provided message or, if the message is empty, the evaluated expression string itself. A pass suffix is then appended to complete the output.

Declaration at line 332 of file reporter.h, definition at line 444 of file reporter.cpp.

444 reporter::pass (std::string& message, const std::string& expression,
446 {
448
449 if (message.empty ())
450 {
451 *this << expression;
452 }
453
455 }

References expression, output_pass_prefix_ and output_pass_suffix_.

verbosity()

micro_test_plus::verbosity micro_os_plus::micro_test_plus::reporter::verbosity ()
inline

Returns the current verbosity level.

Parameters

None.

Returns

The active verbosity value.

Returns the verbosity level stored in verbosity_.

Declaration at line 440 of file reporter.h, definition at line 91 of file reporter-inlines.h.

92 {
93 return verbosity_;
94 }

References verbosity and verbosity_.

Referenced by get_comment_prefix and verbosity.

write_buffer_to_stdout()

void micro_os_plus::micro_test_plus::reporter::write_buffer_to_stdout (void)

Output the current buffered content.

info

Public because deferred_reporter_base calls this from its destructor when aborting, after the subtest instance is no longer accessible via the normal reporting path.

Parameters

None.

Returns

Nothing.

This method writes the contents of the internal output buffer to the standard output stream without appending a newline character. After outputting the buffer, it is cleared to prepare for subsequent output. This approach ensures that test results are presented promptly and efficiently, supporting clear and organised reporting across all test cases and folders.

Declaration at line 307 of file reporter.h, definition at line 237 of file reporter.cpp.

238 {
239 // Pass only the string, do not add an `\n` here.
240 printf ("%s", buffer_.c_str ());
241 }

Reference buffer_.

Referenced by micro_os_plus::micro_test_plus::reporter_tap::begin_subtest, micro_os_plus::micro_test_plus::reporter_human::end_subtest, micro_os_plus::micro_test_plus::reporter_tap::end_subtest, micro_os_plus::micro_test_plus::reporter_human::end_suite and micro_os_plus::micro_test_plus::reporter_tap::end_suite.

Protected Member Functions

colour_()

auto micro_os_plus::micro_test_plus::reporter::colour_ (const bool cond)
inline nodiscard protected

Selects the appropriate colour code based on a condition.

Parameters
cond

Boolean value indicating pass (true) or fail (false).

Returns

The corresponding ANSI colour code as a string.

Returns the ANSI colour code for pass or fail, depending on the boolean condition provided.

Declaration at line 463 of file reporter.h, definition at line 117 of file reporter-inlines.h.

117 reporter::colour_ (const bool cond) const
118 {
119 return cond ? colours_.pass : colours_.fail;
120 }

Reference colours_.

Referenced by get_comment_prefix.

output_fail_prefix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_fail_prefix_ (std::string & message, const bool has_expression, const reflection::source_location & location, subtest & subtest)
protected

Outputs the prefix for a failing condition.

Parameters
message

The message to display.

has_expression

Whether the failure is associated with an expression.

location

The source location of the failure.

subtest

The subtest that owns this check.

Returns

Nothing.

Definition at line 514 of file reporter.h.

Reference output_fail_prefix_.

Referenced by fail and output_fail_prefix_.

output_fail_suffix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_fail_suffix_ (const reflection::source_location & location, bool abort, subtest & subtest)
protected

Outputs the suffix for a failing condition.

Parameters
location

The source location of the failure.

abort

Whether to abort execution after failure.

subtest

The subtest that owns this check.

Returns

Nothing.

Definition at line 529 of file reporter.h.

Reference output_fail_suffix_.

Referenced by fail and output_fail_suffix_.

output_pass_prefix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_pass_prefix_ (std::string & message, subtest & subtest)
protected

Outputs the prefix for a passing condition.

Parameters
message

The message to display.

subtest

The subtest that owns this check.

Returns

Nothing.

Definition at line 488 of file reporter.h.

Reference output_pass_prefix_.

Referenced by output_pass_prefix_ and pass.

output_pass_suffix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_pass_suffix_ (subtest & subtest)
protected

Outputs the suffix for a passing condition.

Parameters
subtest

The subtest that owns this check.

Returns

Nothing.

Definition at line 499 of file reporter.h.

Reference output_pass_suffix_.

Referenced by output_pass_suffix_ and pass.

write_buffer_to_file_()

void micro_os_plus::micro_test_plus::reporter::write_buffer_to_file_ (void)
protected

Writes the contents of buffer_ to output_file_ using fprintf without appending a newline. If output_file_ is null, the call is a no-op.

Declaration at line 466 of file reporter.h, definition at line 250 of file reporter.cpp.

251 {
252 // Pass only the string, do not add an `\n` here.
253 if (output_file_ != nullptr)
254 {
255 fprintf (output_file_, "%s", buffer_.c_str ());
256 }
257 }

References buffer_ and output_file_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::end_subtest, micro_os_plus::micro_test_plus::reporter_tap::end_subtest, micro_os_plus::micro_test_plus::reporter_human::end_suite, micro_os_plus::micro_test_plus::reporter_tap::end_suite and get_comment_prefix.

write_info_()

void micro_os_plus::micro_test_plus::reporter::write_info_ (void)
protected

Appends informational (non-result) text to the output buffer.

Parameters

None.

Returns

Nothing.

Constructs and emits two informational lines: the first lists the programme name and any command-line arguments; the second identifies the compiler (Clang, GCC, or MSVC) together with the version string, floating-point availability on bare-metal targets, exception support, and any active debug or trace macros. Both lines are written to the output file when one is open, and to stdout unless verbosity is set to silent.

Declaration at line 477 of file reporter.h, definition at line 270 of file reporter.cpp.

271 {
272 if (argvs_ && !argvs_->empty ())
273 {
274 const auto& args = *argvs_;
275 std::string line;
276 line.reserve (256);
277 line.append (get_comment_prefix ());
278 line.append ("Running: ");
279
280 // Append only the file name part of argv[0].
281 const std::string_view arg0 = args[0];
282 const auto sep = arg0.rfind ('/');
283 line.append ((sep != std::string_view::npos) ? arg0.substr (sep + 1)
284 : arg0);
285
286 for (size_t i = 1; i < args.size (); ++i)
287 {
288 line.append (" ");
289 line.append (args[i]);
290 }
291 line.append ("\n");
292
293 if (output_file_ != nullptr)
294 fprintf (output_file_, "%s", line.c_str ());
295
296#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
299 printf ("%s", line.c_str ());
300#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
301 }
302
303 {
304 // Build the "Built with ..." line. For the output file the compiler
305 // version is omitted; for stdout it is appended via __VERSION__.
306 std::string line;
307 line.reserve (256);
308 line.append (get_comment_prefix ());
309 line.append ("Built with ");
310#if defined(__clang__)
311 line.append ("clang " __VERSION__);
312#elif defined(__GNUC__)
313 line.append ("GCC " __VERSION__);
314#elif defined(_MSC_VER)
315 line.append ("MSVC");
316 char msvc_ver[16];
317 snprintf (msvc_ver, sizeof (msvc_ver), " - %d", _MSC_VER);
318 line.append (msvc_ver);
319#else
320 line.append ("an unknown compiler");
321#endif
322#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
323 || defined(WIN32))
324 // This is relevant only on bare-metal.
325#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
326 line.append (", with FP");
327#else
328 line.append (", no FP");
329#endif
330#endif
331#if defined(__EXCEPTIONS)
332 line.append (", with exceptions");
333#else
334 line.append (", no exceptions");
335#endif
336#if defined(MICRO_OS_PLUS_DEBUG)
337 line.append (", with MICRO_OS_PLUS_DEBUG");
338#endif
339#if defined(MICRO_OS_PLUS_TRACE)
340 line.append (", with MICRO_OS_PLUS_TRACE");
341#endif
342
343 if (output_file_ != nullptr)
344 {
345 fprintf (output_file_, "%s\n", line.c_str ());
346 }
347
348#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
350 {
351 printf ("%s\n", line.c_str ());
352 }
353#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
354 }
355 }

Reference argvs_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::begin_session, micro_os_plus::micro_test_plus::reporter_tap::begin_session and get_comment_prefix.

Protected Member Attributes

add_empty_line_

argvs_

std::unique_ptr<std::vector<std::string_view> > micro_os_plus::micro_test_plus::reporter::argvs_ {}
protected

Owns the command-line arguments passed to the test runner.

Definition at line 596 of file reporter.h.

596 std::unique_ptr<std::vector<std::string_view>> argvs_{};

Referenced by reporter, micro_os_plus::micro_test_plus::reporter_human::operator<< and write_info_.

buffer_

colours_

expression_

detail::expression_formatter micro_os_plus::micro_test_plus::reporter::expression_ { colours_ }
protected

Expression formatter for pass and fail reporting.

Used in pass() and fail() to format expression values before appending the result to buffer_. Will also be used by detail::deferred_reporter to pre-format expressions at construction time.

Definition at line 563 of file reporter.h.

Referenced by expression.

output_file_

output_file_path_

const char* micro_os_plus::micro_test_plus::reporter::output_file_path_ { nullptr }
protected

Optional file path for redirecting test report output.

When non-null, write_buffer_to_file_() writes accumulated output to this path in addition to (or instead of) standard output.

Definition at line 581 of file reporter.h.

581 const char* output_file_path_{ nullptr };

Referenced by reporter and ~reporter.

verbosity_


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


Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.