Skip to main content

reporter_human Class

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

Declaration

class micro_os_plus::micro_test_plus::reporter_human { ... }

Included Headers

Base class

classreporter

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

Public Constructors Index

reporter_human (const reporter_human &)=delete

Deleted copy constructor to prevent copying. More...

reporter_human (reporter_human &&)=delete

Deleted move constructor to prevent moving. More...

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

Constructor for the reporter_human class. More...

Public Destructor Index

~reporter_human () override

Destructor for the reporter_human 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_human &operator<< (detail::indent_t m)

Output operator for the indent_t manipulator. 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...

reporter_human &operator= (const reporter_human &)=delete

Deleted copy assignment operator to prevent copying. More...

reporter_human &operator= (reporter_human &&)=delete

Deleted move assignment operator to prevent moving. More...

Public Member Functions Index

voidbegin_session (runner &runner) override

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

voidbegin_subtest (subtest &subtest) override

Mark the beginning of a subtest. More...

voidbegin_suite (suite &suite) override

Mark the beginning of a suite. More...

voidend_session (runner &runner) override

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

voidend_subtest (subtest &subtest) override

Mark the end of a subtest. More...

voidend_suite (suite &suite) override

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) override

Returns an empty comment prefix string. 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) override

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

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

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

voidoutput_pass_prefix_ (std::string &message, subtest &subtest) override

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

voidoutput_pass_suffix_ (subtest &subtest) override

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

Human (standard output) implementation of reporter.

reporter_human provides the default concrete implementation of the reporter abstract interface, formatting and presenting test results using printf-based output. It accumulates output in an internal string buffer and writes it to the standard output stream, supporting colour-coded diagnostics and multiple verbosity levels.

Users who require custom output behaviour (e.g. redirecting to a serial port on bare-metal targets) may derive a new class from reporter and supply an instance via the reporter global pointer before calling initialize().

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 101 of file reporter-human.h.

Public Constructors

reporter_human()

micro_os_plus::micro_test_plus::reporter_human::reporter_human (const reporter_human &)
delete

Deleted copy constructor to prevent copying.

Definition at line 115 of file reporter-human.h.

Reference reporter_human.

reporter_human()

micro_os_plus::micro_test_plus::reporter_human::reporter_human (reporter_human &&)
delete

Deleted move constructor to prevent moving.

Definition at line 120 of file reporter-human.h.

Reference reporter_human.

reporter_human()

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

Constructor for the reporter_human class.

Parameters
argvs

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

Delegates construction to the reporter base class with the supplied argument vector. On POSIX platforms, if stdout is connected to a terminal (isatty()), colour output is enabled by selecting the red/green colour scheme. If tracing is enabled, the function signature is output for diagnostic purposes.

Declaration at line 110 of file reporter-human.h, definition at line 90 of file reporter-human.cpp.

91 std::unique_ptr<std::vector<std::string_view>> argvs)
92 : reporter{ std::move (argvs) }
93 {
94#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
95 trace::printf ("%s\n", __PRETTY_FUNCTION__);
96#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
97
98#if defined(__APPLE__) || defined(__linux__) || defined(__unix__)
99 if (isatty (fileno (stdout)))
100 {
102 }
103#endif
104 }

References micro_os_plus::micro_test_plus::reporter::reporter, micro_os_plus::micro_test_plus::reporter::colours_ and micro_os_plus::micro_test_plus::detail::colours_red_green.

Referenced by reporter_human, reporter_human, operator<<, operator= and operator=.

Public Destructor

~reporter_human()

micro_os_plus::micro_test_plus::reporter_human::~reporter_human ()

Destructor for the reporter_human class.

No resources are owned directly by reporter_human; the destructor performs no explicit clean-up. If tracing is enabled, the function signature is output for diagnostic purposes.

Declaration at line 139 of file reporter-human.h, definition at line 112 of file reporter-human.cpp.

113 {
114#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
115 trace::printf ("%s\n", __PRETTY_FUNCTION__);
116#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
117 }

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 153 of file reporter-human.h.

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 153 of file reporter-human.h, definition at line 422 of file reporter.cpp.

423 {
424 buffer_.append (1, c);
425 return *this;
426 }

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 153 of file reporter-human.h, definition at line 437 of file reporter.cpp.

437 reporter::operator<<(const char* s)
438 {
439 buffer_.append (s);
440 return *this;
441 }

operator<<()

reporter_human & micro_os_plus::micro_test_plus::reporter_human::operator<< (detail::indent_t m)

Output operator for the indent_t manipulator.

Parameters
m

The indentation manipulator produced by indent(n).

Returns

Reference to the current reporter instance.

This operator overload appends spaces to the internal output buffer corresponding to m.level two-space indentation levels. It enables structured, readable nesting of test output across all test cases and folders by allowing *this << indent(n) << "text" chaining.

Declaration at line 149 of file reporter-human.h, definition at line 138 of file reporter-human.cpp.

139 {
140 buffer_.append (m.level * indent_size, ' ');
141 return *this;
142 }

References reporter_human, micro_os_plus::micro_test_plus::reporter::buffer_, micro_os_plus::micro_test_plus::indent_size and micro_os_plus::micro_test_plus::detail::indent_t::level.

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 153 of file reporter-human.h, definition at line 392 of file reporter.cpp.

393 {
394 // Call the endl function.
395 (*func) (*this);
396 return *this;
397 }

References micro_os_plus::micro_test_plus::reporter::argvs_, get_comment_prefix, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::reporter::verbosity_.

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 153 of file reporter-human.h.

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 153 of file reporter-human.h, definition at line 408 of file reporter.cpp.

408 reporter::operator<<(std::string_view sv)
409 {
410 buffer_.append (sv);
411 return *this;
412 }

Reference micro_os_plus::micro_test_plus::reporter::reporter.

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 153 of file reporter-human.h, definition at line 145 of file reporter-inlines.h.

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

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 153 of file reporter-human.h, definition at line 185 of file reporter-inlines.h.

186 {
188 return *this;
189 }

operator=()

reporter_human & micro_os_plus::micro_test_plus::reporter_human::operator= (const reporter_human &)
delete

Deleted copy assignment operator to prevent copying.

Definition at line 126 of file reporter-human.h.

Reference reporter_human.

operator=()

reporter_human & micro_os_plus::micro_test_plus::reporter_human::operator= (reporter_human &&)
delete

Deleted move assignment operator to prevent moving.

Definition at line 133 of file reporter-human.h.

Reference reporter_human.

Public Member Functions

begin_session()

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

Mark the beginning of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

If verbosity is not silent, a blank line is printed to stdout before the build-information block emitted by write_info_(). A fixed "µTest++ human report" heading is then written both to the output file (if open) and to stdout. The add_empty_line_ flag is set so that subsequent suite output is visually separated.

Declaration at line 165 of file reporter-human.h, definition at line 155 of file reporter-human.cpp.

156 {
157#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
158 trace::printf ("%s\n", __PRETTY_FUNCTION__);
159#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
160
161#if defined(__GNUC__)
162#pragma GCC diagnostic push
163#if defined(__clang__)
164#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
165#endif
166#endif
167
169 {
170 printf ("\n");
171 }
172
173 write_info_ ();
174
175 const char* message = "µTest++ human report";
176 if (output_file_ != nullptr)
177 {
178 fprintf (output_file_, "%s\n", message);
179 }
180
182 {
183 printf ("%s\n", message);
184
185 flush ();
186 }
187
188 add_empty_line_ = true;
189
190#if defined(__GNUC__)
191#pragma GCC diagnostic pop
192#endif
193 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, micro_os_plus::micro_test_plus::reporter::flush, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::reporter::verbosity_ and micro_os_plus::micro_test_plus::reporter::write_info_.

begin_subtest()

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

Mark the beginning of a subtest.

Parameters
subtest

Reference to the subtest.

Returns

Nothing.

This method marks the beginning of a test case, setting the internal state to indicate that test output is now within a test case context. If there is pending output and the verbosity level is set to verbose, it ensures that output is properly separated and displayed, adding an empty line if necessary. The output buffer is cleared and the stream is flushed to guarantee that all previous output is visible before the new test case begins. This approach enhances the clarity and organisation of test results across all test cases and folders.

Declaration at line 205 of file reporter-human.h, definition at line 489 of file reporter-human.cpp.

490 {
491#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
492#if defined(__GNUC__)
493#pragma GCC diagnostic push
494#if defined(__clang__)
495#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
496#endif
497#endif
498 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, subtest.name ());
499#if defined(__GNUC__)
500#pragma GCC diagnostic pop
501#endif
502#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
503
504#if defined(__GNUC__)
505#pragma GCC diagnostic push
506#if defined(__clang__)
507#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
508#endif
509#endif
510
511 if (!buffer_.empty ())
512 {
513 // Each suite should start with an empty buffer.
514 fprintf (stderr,
515 "Buffer not empty at the beginning of a test case:\n%s\n",
516 buffer_.c_str ());
517 flush ();
518 abort ();
519 }
520
521 std::string indent (indent_size * subtest.nesting_depth (), ' ');
522
523 if (output_file_ != nullptr)
524 {
525 fprintf (output_file_, "%s• %s\n", indent.c_str (), subtest.name ());
526 }
527
529 {
531 {
532 printf ("\n");
533 }
534
535 printf ("%s• %s\n", indent.c_str (), subtest.name ());
536
537 add_empty_line_ = false;
538 }
539
540 flush ();
541
542#if defined(__GNUC__)
543#pragma GCC diagnostic pop
544#endif
545 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, micro_os_plus::micro_test_plus::reporter::buffer_, micro_os_plus::micro_test_plus::reporter::flush, micro_os_plus::micro_test_plus::indent, micro_os_plus::micro_test_plus::indent_size, micro_os_plus::micro_test_plus::detail::test_node::name, micro_os_plus::micro_test_plus::subtest::nesting_depth, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::reporter::verbosity_.

begin_suite()

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

Mark the beginning of a suite.

Parameters
suite

Reference to the suite.

Returns

Nothing.

This method marks the beginning of a test suite, ensuring that output is properly separated and clearly presented. If there is pending output, the stream is flushed and an empty line is added for clarity. For silent or quiet verbosity levels, output is suppressed. Otherwise, a message indicating the start of the test suite is displayed. This approach enhances the organisation and readability of test results across all test cases and folders.

Declaration at line 185 of file reporter-human.h, definition at line 298 of file reporter-human.cpp.

299 {
300#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
301#pragma GCC diagnostic push
302#if defined(__clang__)
303#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
304#endif
305 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
306#pragma GCC diagnostic pop
307#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
308
309#if defined(__GNUC__)
310#pragma GCC diagnostic push
311#if defined(__clang__)
312#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
313#endif
314#endif
315
317 {
319 {
320 printf ("\n");
321 }
322
323 if (output_file_ != nullptr)
324 {
325 fprintf (output_file_, "• %s\n", suite.name ());
326 }
327
328 printf ("• %s\n", suite.name ());
329
330 flush ();
331
332 add_empty_line_ = true;
333 }
334
335#if defined(__GNUC__)
336#pragma GCC diagnostic pop
337#endif
338 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, micro_os_plus::micro_test_plus::reporter::flush, micro_os_plus::micro_test_plus::detail::test_node::name, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::reporter::verbosity_.

end_session()

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

Mark the end of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

Prints a summary line to stdout (and to the output file if open) showing the total number of successful checks, failed checks, executed test cases, and test suites, together with the elapsed time when timing data is available. The line is prefixed with a green tick on success or a red cross on failure, using ANSI colour codes when colour output is enabled.

Declaration at line 175 of file reporter-human.h, definition at line 205 of file reporter-human.cpp.

206 {
207#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
208 trace::printf ("%s\n", __PRETTY_FUNCTION__);
209#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
210
211#if defined(__GNUC__)
212#pragma GCC diagnostic push
213#if defined(__clang__)
214#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
215#endif
216#endif
217
219 {
221 {
222 printf ("\n");
223 }
224
225 size_t total_suites_count = runner.total_suites_count ();
226
227 uint32_t milliseconds = 0;
228 uint32_t microseconds = 0;
230 {
231 runner.timings ().compute_elapsed_time (milliseconds,
232 microseconds);
233 }
234
235 char message_totals[300];
236 snprintf (message_totals, sizeof (message_totals),
237 "Total: %zu check%s passed, %zu failed, in %zu test "
238 "case%s, %zu test suite%s",
240 runner.totals ().successful_checks () == 1 ? "" : "s",
243 runner.totals ().executed_subtests () == 1 ? "" : "s",
244 total_suites_count, total_suites_count == 1 ? "" : "s");
245
246 char message_time[120] = "";
247 if (milliseconds > 0 || microseconds > 0)
248 {
249 snprintf (message_time, sizeof (message_time),
250 ", time: %" PRIu32 ".%03" PRIu32 " ms", milliseconds,
251 microseconds);
252 }
253
254 if (runner.totals ().was_successful ()) [[likely]]
255 {
256 if (output_file_ != nullptr)
257 {
258 fprintf (output_file_, "✓ %s%s\n", message_totals,
259 message_time);
260 }
261
262 printf ("%s✓%s %s%s\n", colours_.pass, colours_.none,
263 message_totals, message_time);
264 }
265 else
266 {
267 if (output_file_ != nullptr)
268 {
269 fprintf (output_file_, "✗ %s%s\n", message_totals,
270 message_time);
271 }
272
273 printf ("%s✗%s %s%s\n", colours_.fail, colours_.none,
274 message_totals, message_time);
275 }
276
277 flush ();
278 }
279
280#if defined(__GNUC__)
281#pragma GCC diagnostic pop
282#endif
283 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, micro_os_plus::micro_test_plus::reporter::colours_, micro_os_plus::micro_test_plus::detail::timestamps::compute_elapsed_time, micro_os_plus::micro_test_plus::detail::runner_totals::executed_subtests, micro_os_plus::micro_test_plus::detail::runner_totals::failed_checks, micro_os_plus::micro_test_plus::reporter::flush, micro_os_plus::micro_test_plus::detail::timestamps::has_timestamps, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::detail::runner_totals::successful_checks, micro_os_plus::micro_test_plus::runner::timings, micro_os_plus::micro_test_plus::runner::total_suites_count, micro_os_plus::micro_test_plus::detail::test_node::totals, micro_os_plus::micro_test_plus::reporter::verbosity_ and micro_os_plus::micro_test_plus::detail::runner_totals::was_successful.

end_subtest()

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

Mark the end of a subtest.

Parameters
subtest

Reference to the subtest.

Returns

Nothing.

This method marks the end of a test case, summarising its outcome and outputting the results with appropriate formatting and colour coding. If any checks have failed, a failure message is displayed, including the number of successful and failed checks. For passing test cases, a success message is shown with the total number of checks. The output is adjusted according to the verbosity level, and additional spacing is managed for clarity. The output buffer is cleared and the stream is flushed to ensure all results are immediately visible, supporting clear and organised reporting across all test cases and folders.

Declaration at line 215 of file reporter-human.h, definition at line 560 of file reporter-human.cpp.

561 {
562#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
563#if defined(__GNUC__)
564#pragma GCC diagnostic push
565#if defined(__clang__)
566#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
567#endif
568#endif
569 trace::printf ("%s '%s' i%zu\n", __PRETTY_FUNCTION__, subtest.name (),
571#if defined(__GNUC__)
572#pragma GCC diagnostic pop
573#endif
574#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
575
576#if defined(__GNUC__)
577#pragma GCC diagnostic push
578#if defined(__clang__)
579#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
580#endif
581#endif
582
583 // At this point, the buffer may contain output from the subtest, which
584 // should be displayed.
586 {
587 std::string indent (indent_size * subtest.nesting_depth (), ' ');
588 std::string indent2 (indent_size * (subtest.nesting_depth () + 1),
589 ' ');
590
592 {
593 printf ("\n");
594 }
595
596 if (subtest.totals ().was_successful ()) [[likely]]
597 {
598 // Successful subtest.
599
600 char message_totals[300];
601 snprintf (message_totals, sizeof (message_totals),
602 "%s - passed (%zu check%s)", subtest.name (),
604 subtest.totals ().successful_checks () == 1 ? "" : "s");
605
606 if (output_file_ != nullptr)
607 {
609
610 fprintf (output_file_, "%s✓ %s\n", indent.c_str (),
611 message_totals);
612 }
613
615 {
616 // With verbosity, show full TAP output accumulated in the
617 // buffer.
619
620 printf ("%s%s✓%s %s\n", indent.c_str (), colours_.pass,
621 colours_.none, message_totals);
622
623 add_empty_line_ = true;
624 }
625 else
626 {
627 printf ("%s%s✓%s %s\n", indent.c_str (), colours_.pass,
628 colours_.none, message_totals);
629
630 add_empty_line_ = false;
631 }
632 }
633 else
634 {
635 // Failed subtest.
636 char message_totals[300];
637 snprintf (message_totals, sizeof (message_totals),
638 "(%zu check%s passed, %zu failed)",
640 subtest.totals ().successful_checks () == 1 ? "" : "s",
642
643 if (output_file_ != nullptr)
644 {
646
647 fprintf (output_file_, "%s✗ %s - %sFAILED%s %s\n",
648 indent.c_str (), subtest.name (), colours_.fail,
649 colours_.none, message_totals);
650 }
651
653 {
654 if (!add_empty_line_)
655 {
656 printf ("\n");
657 }
658
659 printf ("%s• %s\n", indent.c_str (), subtest.name ());
660 }
661
662 // Show full output accumulated in the buffer for failed
663 // subtests, as it may contain useful information about the
664 // failure.
666
667 printf ("%s%s✗%s %s - %sFAILED%s %s\n", indent.c_str (),
668 colours_.fail, colours_.none, subtest.name (),
669 colours_.fail, colours_.none, message_totals);
670
671 add_empty_line_ = true;
672 }
673 }
674
675 flush ();
676
677 // Clear residual content when less verbose.
678 buffer_.clear ();
679
680#if defined(__GNUC__)
681#pragma GCC diagnostic pop
682#endif
683 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, micro_os_plus::micro_test_plus::reporter::buffer_, micro_os_plus::micro_test_plus::reporter::colours_, micro_os_plus::micro_test_plus::detail::runner_totals::failed_checks, micro_os_plus::micro_test_plus::reporter::flush, micro_os_plus::micro_test_plus::indent, micro_os_plus::micro_test_plus::indent_size, micro_os_plus::micro_test_plus::detail::test_node::name, micro_os_plus::micro_test_plus::subtest::nesting_depth, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::detail::runner_totals::successful_checks, micro_os_plus::micro_test_plus::detail::test_node::totals, micro_os_plus::micro_test_plus::verbose, micro_os_plus::micro_test_plus::reporter::verbosity_, micro_os_plus::micro_test_plus::detail::runner_totals::was_successful, micro_os_plus::micro_test_plus::reporter::write_buffer_to_file_ and micro_os_plus::micro_test_plus::reporter::write_buffer_to_stdout.

end_suite()

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

Mark the end of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

This method marks the end of a test suite, summarising the overall results and presenting them with appropriate formatting and colour coding. If the suite contains test cases and the verbosity is not set to quiet, an empty line is added for clarity. For suites with no failed checks and at least one successful check, a success message is displayed, including the number of checks and test cases. Otherwise, a failure message is shown, detailing the number of successful and failed checks, as well as the total number of test cases. The output is immediately flushed to ensure prompt and organised reporting across all test cases and folders.

Declaration at line 195 of file reporter-human.h, definition at line 353 of file reporter-human.cpp.

354 {
355#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
356#if defined(__GNUC__)
357#pragma GCC diagnostic push
358#if defined(__clang__)
359#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
360#endif
361#endif
362 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
363#if defined(__GNUC__)
364#pragma GCC diagnostic pop
365#endif
366#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
367
368#if defined(__GNUC__)
369#pragma GCC diagnostic push
370#if defined(__clang__)
371#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
372#endif
373#endif
374
375 uint32_t milliseconds = 0;
376 uint32_t microseconds = 0;
378 {
379 suite.timings ().compute_elapsed_time (milliseconds, microseconds);
380 }
381
382 char message_time[120] = "";
383 if (milliseconds > 0 || microseconds > 0)
384 {
385 snprintf (message_time, sizeof (message_time),
386 ", time: %" PRIu32 ".%03" PRIu32 " ms", milliseconds,
387 microseconds);
388 }
389
390 // At this point, the buffer may contain output from the test case, which
391 // should be displayed.
393 {
394 std::string indent (indent_size, ' ');
395
396 if (suite.totals ().executed_subtests () > 0)
397 {
398 printf ("\n");
399 }
400
401 if (suite.totals ().was_successful ()) [[likely]]
402 {
403 // Successful test suite.
404
405 char message_totals[300];
406 snprintf (message_totals, sizeof (message_totals),
407 "(%zu check%s in %zu test case%s)",
409 suite.totals ().successful_checks () == 1 ? "" : "s",
411 suite.totals ().executed_subtests () == 1 ? "" : "s");
412
413 if (output_file_ != nullptr)
414 {
416
417 fprintf (output_file_, "✓ %s - passed %s%s\n", suite.name (),
418 message_totals, message_time);
419 }
420
422 {
423 // With verbosity, show full TAP output accumulated in the
424 // buffer.
426 }
427
428 printf ("%s✓%s %s - passed %s%s\n", colours_.pass, colours_.none,
429 suite.name (), message_totals, message_time);
430 }
431 else
432 {
433 // Failed test suite.
434
435 char message_totals[300];
436 snprintf (message_totals, sizeof (message_totals),
437 "(%zu check%s passed, %zu "
438 "failed, in %zu test case%s)",
440 suite.totals ().successful_checks () == 1 ? "" : "s",
443 suite.totals ().executed_subtests () == 1 ? "" : "s");
444
445 if (output_file_ != nullptr)
446 {
448
449 fprintf (output_file_, "✗ %s - FAILED %s%s\n", suite.name (),
450 message_totals, message_time);
451 }
452
453 // Show full TAP output accumulated in the buffer for failed suite
454 // cases, as it may contain useful information about the failure.
456
457 printf ("%s✗%s %s - %sFAILED%s %s%s\n", colours_.fail,
458 colours_.none, suite.name (), colours_.fail, colours_.none,
459 message_totals, message_time);
460 }
461 }
462
463 flush ();
464
465 // Clear residual content when less verbose.
466 buffer_.clear ();
467
468 add_empty_line_ = true;
469
470#if defined(__GNUC__)
471#pragma GCC diagnostic pop
472#endif
473 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, micro_os_plus::micro_test_plus::reporter::buffer_, micro_os_plus::micro_test_plus::reporter::colours_, micro_os_plus::micro_test_plus::detail::timestamps::compute_elapsed_time, micro_os_plus::micro_test_plus::detail::runner_totals::executed_subtests, micro_os_plus::micro_test_plus::detail::runner_totals::failed_checks, micro_os_plus::micro_test_plus::reporter::flush, micro_os_plus::micro_test_plus::detail::timestamps::has_timestamps, micro_os_plus::micro_test_plus::indent, micro_os_plus::micro_test_plus::indent_size, micro_os_plus::micro_test_plus::detail::test_node::name, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::detail::runner_totals::successful_checks, micro_os_plus::micro_test_plus::suite::timings, micro_os_plus::micro_test_plus::detail::test_node::totals, micro_os_plus::micro_test_plus::verbose, micro_os_plus::micro_test_plus::reporter::verbosity_, micro_os_plus::micro_test_plus::detail::runner_totals::was_successful, micro_os_plus::micro_test_plus::reporter::write_buffer_to_file_ and micro_os_plus::micro_test_plus::reporter::write_buffer_to_stdout.

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 225 of file reporter.cpp.

226 {
227 buffer_.append ("\n");
228 flush ();
229 }

References micro_os_plus::micro_test_plus::reporter::buffer_ and micro_os_plus::micro_test_plus::reporter::flush.

Referenced by micro_os_plus::micro_test_plus::endl.

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 107 of file reporter-inlines.h.

108 {
109 return expression_;
110 }

Reference micro_os_plus::micro_test_plus::reporter::expression_.

Referenced by micro_os_plus::micro_test_plus::subtest::assume, micro_os_plus::micro_test_plus::subtest::expect, micro_os_plus::micro_test_plus::reporter::fail, micro_os_plus::micro_test_plus::reporter::get_comment_prefix, micro_os_plus::micro_test_plus::reporter::operator<< and micro_os_plus::micro_test_plus::reporter::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 469 of file reporter.cpp.

469 reporter::fail (bool abort, std::string& message,
470 const std::string& expression, bool has_expression,
471 const reflection::source_location& location,
473 {
474 output_fail_prefix_ (message, has_expression, location, subtest);
475
476 if (has_expression)
477 {
478 *this << expression;
479 }
480
481 output_fail_suffix_ (location, abort, subtest);
482 }

References micro_os_plus::micro_test_plus::reporter::expression, micro_os_plus::micro_test_plus::reporter::output_fail_prefix_ and micro_os_plus::micro_test_plus::reporter::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 371 of file reporter.cpp.

372 {
373 fflush (stdout);
374 if (output_file_ != nullptr)
375 {
376 fflush (output_file_);
377 }
378 }

Reference micro_os_plus::micro_test_plus::reporter::output_file_.

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

get_comment_prefix()

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

Returns an empty comment prefix string.

Parameters

None.

Returns

An empty string, as the human-readable format does not use a comment prefix.

Returns an empty string. The human reporter does not prefix comment lines; the write_info_() output appears as plain text.

Declaration at line 226 of file reporter-human.h, definition at line 693 of file reporter-human.cpp.

694 {
695 return "";
696 }

Referenced by operator<<.

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 450 of file reporter.cpp.

450 reporter::pass (std::string& message, const std::string& expression,
452 {
454
455 if (message.empty ())
456 {
457 *this << expression;
458 }
459
461 }

References micro_os_plus::micro_test_plus::reporter::expression, micro_os_plus::micro_test_plus::reporter::output_pass_prefix_ and micro_os_plus::micro_test_plus::reporter::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 92 of file reporter-inlines.h.

93 {
94 return verbosity_;
95 }

References micro_os_plus::micro_test_plus::reporter::verbosity and micro_os_plus::micro_test_plus::reporter::verbosity_.

Referenced by micro_os_plus::micro_test_plus::reporter::get_comment_prefix and micro_os_plus::micro_test_plus::reporter::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 241 of file reporter.cpp.

242 {
243 // Pass only the string, do not add an `\n` here.
244 printf ("%s", buffer_.c_str ());
245 }

Reference micro_os_plus::micro_test_plus::reporter::buffer_.

Referenced by micro_os_plus::micro_test_plus::reporter_tap::begin_subtest, end_subtest, micro_os_plus::micro_test_plus::reporter_tap::end_subtest, 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 118 of file reporter-inlines.h.

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

Reference micro_os_plus::micro_test_plus::reporter::colours_.

Referenced by micro_os_plus::micro_test_plus::reporter::get_comment_prefix.

output_fail_prefix_()

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

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.

This method outputs the prefix for a failing check result, applying the appropriate colour formatting and symbols to clearly indicate failure. If the output occurs within a subtest, additional indentation is applied for readability. The prefix includes a cross symbol (), an optional message, and the label "FAILED". The source location is appended in parentheses, showing the file or folder name and line number where the failure occurred. Colour formatting is reset after the prefix to maintain consistent output style across all test cases and folders.

Declaration at line 262 of file reporter-human.h, definition at line 751 of file reporter-human.cpp.

752 std::string& message, const bool has_expression,
754 {
755#if defined(__GNUC__)
756#pragma GCC diagnostic push
757#if defined(__clang__)
758#pragma clang diagnostic ignored "-Wsign-conversion"
759#elif defined(__GNUC__)
760#pragma GCC diagnostic ignored "-Wnarrowing"
761#pragma GCC diagnostic ignored "-Wsign-conversion"
762#endif
763#endif
764
765 size_t level = subtest.nesting_depth ();
766
767 *this << indent (level + 1);
768 *this << colours_.fail << "✗" << colours_.none << " ";
769 if (!message.empty ())
770 {
771 *this << message.c_str ();
772 *this << " ";
773 }
774 *this << colours_.fail << "FAILED" << colours_.none;
775 *this << " (" << reflection::short_name (location.file_name ()) << ":"
776 << location.line ();
777 if (has_expression)
778 {
779 *this << ", ";
780 }
781
782#if defined(__GNUC__)
783#pragma GCC diagnostic pop
784#endif
785 }

References micro_os_plus::micro_test_plus::reporter::colours_, micro_os_plus::micro_test_plus::reflection::source_location::file_name, micro_os_plus::micro_test_plus::indent, micro_os_plus::micro_test_plus::reflection::source_location::line, micro_os_plus::micro_test_plus::subtest::nesting_depth and micro_os_plus::micro_test_plus::reflection::short_name.

output_fail_suffix_()

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

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.

This method outputs the suffix for a failing check result by closing the location information, appending an "aborted..." message if the check was aborted, and then adding a newline to the output. The output stream is flushed to ensure immediate visibility. This approach guarantees that failure results are clearly separated, promptly reported, and easily distinguishable across all test cases and folders.

Declaration at line 276 of file reporter-human.h, definition at line 797 of file reporter-human.cpp.

798 [[maybe_unused]] const reflection::source_location& location, bool abort,
799 [[maybe_unused]] subtest& subtest)
800 {
801 *this << ")";
802 if (abort)
803 {
804 *this << " aborted...";
805 }
806 *this << endl;
807
808 flush ();
809 }

References micro_os_plus::micro_test_plus::endl and micro_os_plus::micro_test_plus::reporter::flush.

output_pass_prefix_()

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

Outputs the prefix for a passing condition.

Parameters
message

The message to display.

subtest

The subtest that owns this check.

Returns

Nothing.

This method outputs the prefix for a passing check result, applying the appropriate colour formatting and symbols to clearly indicate success. If the output occurs within a subtest, additional indentation is applied for readability. The prefix includes a tick symbol () and, if provided, an associated message. Colour formatting is reset after the prefix to maintain consistent output style across all test cases and folders.

The prefix/suffix methods help shorten the code generated by the template methods.

Declaration at line 238 of file reporter-human.h, definition at line 711 of file reporter-human.cpp.

712 {
713 size_t level = subtest.nesting_depth ();
714
715 *this << indent (level + 1);
716 *this << colours_.pass << "✓" << colours_.none << " ";
717 if (!message.empty ())
718 {
719 *this << message.c_str ();
720 }
721 }

References micro_os_plus::micro_test_plus::reporter::colours_, micro_os_plus::micro_test_plus::indent and micro_os_plus::micro_test_plus::subtest::nesting_depth.

output_pass_suffix_()

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

Outputs the suffix for a passing condition.

Parameters
subtest

The subtest that owns this check.

Returns

Nothing.

Completes pass output by appending endl and flushing buffered content to the configured sinks.

The prefix/suffix methods help shorten the code generated by the template methods.

Declaration at line 248 of file reporter-human.h, definition at line 732 of file reporter-human.cpp.

733 {
734 *this << endl;
735
736 flush ();
737 }

References micro_os_plus::micro_test_plus::endl and micro_os_plus::micro_test_plus::reporter::flush.

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 254 of file reporter.cpp.

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

References micro_os_plus::micro_test_plus::reporter::buffer_ and micro_os_plus::micro_test_plus::reporter::output_file_.

Referenced by end_subtest, micro_os_plus::micro_test_plus::reporter_tap::end_subtest, end_suite, micro_os_plus::micro_test_plus::reporter_tap::end_suite and micro_os_plus::micro_test_plus::reporter::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 274 of file reporter.cpp.

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

Referenced by begin_session, micro_os_plus::micro_test_plus::reporter_tap::begin_session and micro_os_plus::micro_test_plus::reporter::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 micro_os_plus::micro_test_plus::reporter::reporter and operator<<.

buffer_

colours_

detail::colours micro_os_plus::micro_test_plus::reporter::colours_ {}
protected

ANSI colour codes for output formatting.

Definition at line 542 of file reporter.h.

542 detail::colours colours_{};

Referenced by reporter_human, micro_os_plus::micro_test_plus::reporter::colour_, end_session, end_subtest, end_suite, output_fail_prefix_ and output_pass_prefix_.

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 micro_os_plus::micro_test_plus::reporter::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 micro_os_plus::micro_test_plus::reporter::reporter and micro_os_plus::micro_test_plus::reporter::~reporter.

verbosity_


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


Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.17.0.