Skip to main content

reporter_tap Class

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

Declaration

class micro_os_plus::micro_test_plus::reporter_tap { ... }

Included Headers

Base class

classreporter

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

Public Constructors Index

reporter_tap (const reporter_tap &)=delete

Deleted copy constructor to prevent copying. More...

reporter_tap (reporter_tap &&)=delete

Deleted move constructor to prevent moving. More...

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

Constructor for the reporter_tap class. More...

Public Destructor Index

~reporter_tap () override

Destructor for the reporter_tap 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_tap &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_tap &operator= (const reporter_tap &)=delete

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

reporter_tap &operator= (reporter_tap &&)=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 test 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 the TAP 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

TAP (Test Anything Protocol) implementation of reporter.

reporter_tap provides a concrete implementation of the reporter abstract interface that formats test results according to the Test Anything Protocol (TAP). It accumulates output in an internal string buffer and writes it to the standard output stream.

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 93 of file reporter-tap.h.

Public Constructors

reporter_tap()

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

Deleted copy constructor to prevent copying.

Definition at line 107 of file reporter-tap.h.

Reference reporter_tap.

reporter_tap()

micro_os_plus::micro_test_plus::reporter_tap::reporter_tap (reporter_tap &&)
delete

Deleted move constructor to prevent moving.

Definition at line 112 of file reporter-tap.h.

Reference reporter_tap.

reporter_tap()

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

Constructor for the reporter_tap 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. If tracing is enabled, the function signature is output for diagnostic purposes.

Declaration at line 102 of file reporter-tap.h, definition at line 75 of file reporter-tap.cpp.

76 std::unique_ptr<std::vector<std::string_view>> argvs)
77 : reporter{ std::move (argvs) }
78 {
79#if defined(MICRO_OS_PLUS_TRACE) \
80 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
81 trace::printf ("%s\n", __PRETTY_FUNCTION__);
82#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
83 }

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

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

Public Destructor

~reporter_tap()

micro_os_plus::micro_test_plus::reporter_tap::~reporter_tap ()

Destructor for the reporter_tap class.

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

Declaration at line 131 of file reporter-tap.h, definition at line 91 of file reporter-tap.cpp.

92 {
93#if defined(MICRO_OS_PLUS_TRACE) \
94 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
95 trace::printf ("%s\n", __PRETTY_FUNCTION__);
96#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
97 }

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 145 of file reporter-tap.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 145 of file reporter-tap.h, definition at line 416 of file reporter.cpp.

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

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 145 of file reporter-tap.h, definition at line 431 of file reporter.cpp.

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

operator<<()

reporter_tap & micro_os_plus::micro_test_plus::reporter_tap::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 four-space indentation levels. It enables structured, readable nesting of suite output across all test cases and folders by allowing *this << indent(n) << "text" chaining.

Declaration at line 141 of file reporter-tap.h, definition at line 111 of file reporter-tap.cpp.

112 {
113 buffer_.append (m.level * indent_size, ' ');
114 return *this;
115 }

References reporter_tap, 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 145 of file reporter-tap.h, definition at line 386 of file reporter.cpp.

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

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 145 of file reporter-tap.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 145 of file reporter-tap.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 }

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 145 of file reporter-tap.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 }

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

185 {
187 return *this;
188 }

operator=()

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

Deleted copy assignment operator to prevent copying.

Definition at line 118 of file reporter-tap.h.

Reference reporter_tap.

operator=()

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

Deleted move assignment operator to prevent moving.

Definition at line 125 of file reporter-tap.h.

Reference reporter_tap.

Public Member Functions

begin_session()

void micro_os_plus::micro_test_plus::reporter_tap::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, emits a blank line to stdout and then calls write_info_() to output build and environment information. The TAP version header "TAP version 14" is then written to both the output file (if open) and stdout. The add_empty_line_ flag is cleared so that the first suite header is not separated by an extra blank line.

Declaration at line 157 of file reporter-tap.h, definition at line 129 of file reporter-tap.cpp.

130 {
131#if defined(MICRO_OS_PLUS_TRACE) \
132 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
133 trace::printf ("%s\n", __PRETTY_FUNCTION__);
134#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
135
136#if defined(__GNUC__)
137#pragma GCC diagnostic push
138#if defined(__clang__)
139#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
140#endif
141#endif
142
144 {
145 printf ("\n");
146 }
147
148 write_info_ ();
149
150 const char* message = "TAP version 14";
151 if (output_file_ != nullptr)
152 {
153 fprintf (output_file_, "%s\n", message);
154 }
155
157 {
158 printf ("%s\n", message);
159
160 flush ();
161 }
162
163 add_empty_line_ = false;
164
165#if defined(__GNUC__)
166#pragma GCC diagnostic pop
167#endif
168 }

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_tap::begin_subtest (subtest & subtest)
virtual

Mark the beginning of a subtest.

Parameters
subtest

Reference to the subtest.

Returns

Nothing.

Validates that the output buffer is empty at subtest start; if not, the buffer is written to stdout, the stream is flushed, and execution is aborted. A "# Subtest: <name>" comment line (indented according to nesting depth) is written to the output file and, under normal or verbose verbosity, to stdout as well.

Declaration at line 197 of file reporter-tap.h, definition at line 464 of file reporter-tap.cpp.

465 {
466#if defined(MICRO_OS_PLUS_TRACE) \
467 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
468#pragma GCC diagnostic push
469#if defined(__clang__)
470#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
471#endif
472 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, subtest.name ());
473#pragma GCC diagnostic pop
474#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
475
476#if defined(__GNUC__)
477#pragma GCC diagnostic push
478#if defined(__clang__)
479#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
480#endif
481#endif
482
483 if (!buffer_.empty ())
484 {
485 // Each suite should start with an empty buffer.
487 flush ();
488 abort ();
489 }
490
491 std::string indent (indent_size * subtest.nesting_depth (), ' ');
492
493 char message_subtest[120];
494 snprintf (message_subtest, sizeof (message_subtest), "%s# Subtest: %s",
495 indent.c_str (), subtest.name ());
496
497 if (output_file_ != nullptr)
498 {
499 fprintf (output_file_, "%s\n", message_subtest);
500 }
501
503 {
505 {
506 printf ("\n");
507 }
508
509 printf ("%s\n", message_subtest);
510
511 flush ();
512
513 add_empty_line_ = false;
514 }
515
516#if defined(__GNUC__)
517#pragma GCC diagnostic pop
518#endif
519 }

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::normal, micro_os_plus::micro_test_plus::reporter::output_file_, micro_os_plus::micro_test_plus::verbose, micro_os_plus::micro_test_plus::reporter::verbosity_ and micro_os_plus::micro_test_plus::reporter::write_buffer_to_stdout.

begin_suite()

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

Mark the beginning of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

Emits a "# Subtest: <name>" comment line to mark the start of a TAP subtest block for the suite. The line is written to the output file when one is open. Under normal or verbose verbosity, it is also written to stdout, preceded by a blank line when add_empty_line_ is set.

Declaration at line 177 of file reporter-tap.h, definition at line 271 of file reporter-tap.cpp.

272 {
273#if defined(MICRO_OS_PLUS_TRACE) \
274 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
275#pragma GCC diagnostic push
276#if defined(__clang__)
277#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
278#endif
279 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
280#pragma GCC diagnostic pop
281#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
282
283#if defined(__GNUC__)
284#pragma GCC diagnostic push
285#if defined(__clang__)
286#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
287#endif
288#endif
289
290 char message_subtest[120];
291 snprintf (message_subtest, sizeof (message_subtest), "# Subtest: %s",
292 suite.name ());
293
294 if (output_file_ != nullptr)
295 {
296 fprintf (output_file_, "%s\n", message_subtest);
297 }
298
300 {
302 {
303 printf ("\n");
304 }
305
306 printf ("%s\n", message_subtest);
307
308 flush ();
309
310 add_empty_line_ = true;
311 }
312
313#if defined(__GNUC__)
314#pragma GCC diagnostic pop
315#endif
316 }

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_tap::end_session (runner & runner)
virtual

Mark the end of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

Emits the TAP plan line (1..N, where N is the total number of test suites) followed by a comment line summarising successful checks, failed checks, executed test cases, elapsed time, and suite count. Both lines are written to the output file when one is open. When verbosity is set to quiet, the plan is replaced by 1..0 to produce a valid skipped-test TAP document.

Declaration at line 167 of file reporter-tap.h, definition at line 180 of file reporter-tap.cpp.

181 {
182#if defined(MICRO_OS_PLUS_TRACE) \
183 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
184 trace::printf ("%s\n", __PRETTY_FUNCTION__);
185#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
186
187#if defined(__GNUC__)
188#pragma GCC diagnostic push
189#if defined(__clang__)
190#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
191#endif
192#endif
193
194 size_t total_suites_count = runner.total_suites_count ();
195
196 uint32_t milliseconds = 0;
197 uint32_t microseconds = 0;
199 {
200 runner.timings ().compute_elapsed_time (milliseconds, microseconds);
201 }
202
203 char message_summary[32];
204 snprintf (message_summary, sizeof (message_summary), "1..%zu",
205 total_suites_count);
206
207 char message_totals[160];
208 snprintf (message_totals, sizeof (message_totals),
209 "total: %zu check%s passed, %zu failed, in %zu test "
210 "case%s, %zu test suite%s",
212 runner.totals ().successful_checks () == 1 ? "" : "s",
215 runner.totals ().executed_subtests () == 1 ? "" : "s",
216 total_suites_count, total_suites_count == 1 ? "" : "s");
217
218 char message_time[120] = "";
219 if (milliseconds > 0 || microseconds > 0)
220 {
221 snprintf (message_time, sizeof (message_time),
222 ", time: %" PRIu32 ".%03" PRIu32 " ms", milliseconds,
223 microseconds);
224 }
225
226 if (output_file_ != nullptr)
227 {
228 fprintf (output_file_, "%s\n# { %s%s }\n", message_summary,
229 message_totals, message_time);
230 }
231
233 {
235 {
236 printf ("\n");
237 }
238
240 {
241 printf ("%s\n", message_summary);
242 }
243 else
244 {
245 // With quiet verbosity, there are no ok/not ok lines, so the TAP
246 // plan should look like a skipped test.
247 printf ("1..0\n");
248 }
249
250 printf ("# { %s%s }\n", message_totals, message_time);
251
252 flush ();
253 }
254
255#if defined(__GNUC__)
256#pragma GCC diagnostic pop
257#endif
258 }

References micro_os_plus::micro_test_plus::reporter::add_empty_line_, 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::quiet, 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 and micro_os_plus::micro_test_plus::reporter::verbosity_.

end_subtest()

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

Mark the end of a subtest.

Parameters
subtest

Reference to the subtest.

Returns

Nothing.

Emits the TAP plan line for the subtest's checks followed by an ok/not ok result line that includes the subtest index, name, pass/fail status, and check counts. Any output accumulated in buffer_ is flushed to the output file and, when verbosity is verbose or the subtest failed, to stdout as well. The buffer is cleared on exit.

Declaration at line 207 of file reporter-tap.h, definition at line 531 of file reporter-tap.cpp.

532 {
533#if defined(MICRO_OS_PLUS_TRACE) \
534 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
535#pragma GCC diagnostic push
536#if defined(__clang__)
537#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
538#endif
539 trace::printf ("%s '%s' i%zu +%zu -%zu in xc%zu, xs%zu | cs%zu\n",
540 __PRETTY_FUNCTION__, subtest.name (),
547#pragma GCC diagnostic pop
548#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
549
550#if defined(__GNUC__)
551#pragma GCC diagnostic push
552#if defined(__clang__)
553#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
554#endif
555#endif
556
557 std::string indent (indent_size * subtest.nesting_depth (), ' ');
558 std::string indent2 (indent_size * (subtest.nesting_depth () + 1), ' ');
559
560 char message_summary[40];
561 snprintf (message_summary, sizeof (message_summary), "%s1..%zu",
562 indent2.c_str (),
565
566 char message_totals[120];
567 if (subtest.totals ().was_successful ()) [[likely]]
568 {
569 snprintf (message_totals, sizeof (message_totals),
570 "%sok %zu - %s # { passed, %zu check%s }", indent.c_str (),
573 subtest.totals ().successful_checks () == 1 ? "" : "s");
574 }
575 else
576 {
577 snprintf (message_totals, sizeof (message_totals),
578 "%snot ok %zu - %s # { FAILED, %zu check%s "
579 "passed, %zu failed }",
580 indent.c_str (), subtest.own_index (), subtest.name (),
582 subtest.totals ().successful_checks () == 1 ? "" : "s",
584 }
585
586 if (output_file_ != nullptr)
587 {
589
590 fprintf (output_file_, "%s\n%s\n", message_summary, message_totals);
591 }
592
593 // At this point, the buffer may contain output from the subtest, which
594 // should be displayed.
596 {
598 {
599 printf ("\n");
600 }
601
602 if (subtest.totals ().was_successful ()) [[likely]]
603 {
604 // Successful subtest.
606 {
607 // With verbosity, show full TAP output accumulated in the
608 // buffer.
610
611 printf ("%s\n", message_summary);
612 }
613 else
614 {
615 // Without verbosity, show only the summary line
616 // and count only subtests, not checks, as the TAP output is
617 // not shown.
618 printf ("%s1..%zu\n", indent2.c_str (),
620 }
621
622 printf ("%s\n", message_totals);
623 }
624 else
625 {
626 // Failed subtest.
627
628 // Show full TAP output accumulated in the buffer for failed
629 // subtests, as it may contain useful information about the
630 // failure.
632
633 printf ("%s\n%s\n", message_summary, message_totals);
634 }
635
636 flush ();
637 }
638
639 buffer_.clear ();
640
641 add_empty_line_ = true;
642
643#if defined(__GNUC__)
644#pragma GCC diagnostic pop
645#endif
646 }

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::detail::runnable_base::children_subtests_count, micro_os_plus::micro_test_plus::detail::runner_totals::executed_checks, 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::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::runnable_base::own_index, 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_tap::end_suite (suite & suite)
virtual

Mark the end of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

Emits the TAP plan line for the suite's subtests followed by an ok/not ok result line that includes the suite index, name, pass/fail status, check counts, subtest count, and elapsed time. Any output accumulated in buffer_ is flushed to the output file and, when verbosity is verbose or the suite failed, to stdout as well. The buffer is cleared on exit.

Declaration at line 187 of file reporter-tap.h, definition at line 328 of file reporter-tap.cpp.

329 {
330#if defined(MICRO_OS_PLUS_TRACE) \
331 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
332#pragma GCC diagnostic push
333#if defined(__clang__)
334#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
335#endif
336 trace::printf (
337 "%s '%s' +%zu -%zu in xc%zu, xs%zu | cs%zu\n", __PRETTY_FUNCTION__,
342
343#pragma GCC diagnostic pop
344#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
345
346#if defined(__GNUC__)
347#pragma GCC diagnostic push
348#if defined(__clang__)
349#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
350#endif
351#endif
352
353 uint32_t milliseconds = 0;
354 uint32_t microseconds = 0;
356 {
357 suite.timings ().compute_elapsed_time (milliseconds, microseconds);
358 }
359
360 std::string indent (indent_size, ' ');
361
362 char message_summary[40];
363 snprintf (message_summary, sizeof (message_summary), "%s1..%zu",
365 char message_totals[120];
366 if (suite.totals ().was_successful ()) [[likely]]
367 {
368 snprintf (message_totals, sizeof (message_totals),
369 "ok %zu - %s # { passed, %zu check%s in %zu "
370 "test case%s",
373 suite.totals ().successful_checks () == 1 ? "" : "s",
375 suite.totals ().executed_subtests () == 1 ? "" : "s");
376 }
377 else
378 {
379 snprintf (message_totals, sizeof (message_totals),
380 "not ok %zu - %s # { FAILED, %zu check%s "
381 "passed, %zu failed, in %zu test case%s",
384 suite.totals ().successful_checks () == 1 ? "" : "s",
387 suite.totals ().executed_subtests () == 1 ? "" : "s");
388 }
389
390 char message_time[120] = "";
391 if (milliseconds > 0 || microseconds > 0)
392 {
393 snprintf (message_time, sizeof (message_time),
394 ", time: %" PRIu32 ".%03" PRIu32 " ms", milliseconds,
395 microseconds);
396 }
397
398 if (output_file_ != nullptr)
399 {
401
402 fprintf (output_file_, "%s\n%s%s }\n", message_summary, message_totals,
403 message_time);
404 }
405
406 // At this point, the buffer may contain output from the test case, which
407 // should be displayed.
409 {
411 {
412 printf ("\n");
413 }
414
415 if (suite.totals ().was_successful ()) [[likely]]
416 {
417 // Successful test suite.
418
420 {
421 // With verbosity, show full TAP output accumulated in the
422 // buffer.
424 }
425
426 printf ("%s\n%s%s }\n", message_summary, message_totals,
427 message_time);
428 }
429 else
430 {
431 // Failed test suite.
432
433 // Show full TAP output accumulated in the buffer for failed suite
434 // cases, as it may contain useful information about the failure.
436
437 printf ("%s\n%s%s }\n", message_summary, message_totals,
438 message_time);
439 }
440
441 flush ();
442 }
443
444 buffer_.clear ();
445
446 add_empty_line_ = true;
447
448#if defined(__GNUC__)
449#pragma GCC diagnostic pop
450#endif
451 }

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::detail::runnable_base::children_subtests_count, micro_os_plus::micro_test_plus::detail::timestamps::compute_elapsed_time, micro_os_plus::micro_test_plus::detail::runner_totals::executed_checks, 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::runnable_base::own_index, 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 221 of file reporter.cpp.

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

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

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

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

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

get_comment_prefix()

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

Returns the TAP comment prefix string "# ".

Parameters

None.

Returns

The string "# ", used to prefix comment lines in TAP output.

Returns "# ". The TAP reporter prefixes all comment lines, including the informational lines emitted by write_info_(), with the TAP comment marker.

Declaration at line 218 of file reporter-tap.h, definition at line 657 of file reporter-tap.cpp.

658 {
659 return "# ";
660 }

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

92 {
93 return verbosity_;
94 }

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

Referenced by begin_subtest, micro_os_plus::micro_test_plus::reporter_human::end_subtest, end_subtest, micro_os_plus::micro_test_plus::reporter_human::end_suite and 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 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_tap::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 YAML diagnostics preamble. Colour formatting and line structure are arranged to conform to TAP14 diagnostics output.

Declaration at line 254 of file reporter-tap.h, definition at line 712 of file reporter-tap.cpp.

713 std::string& message, const bool has_expression,
714 [[maybe_unused]] const reflection::source_location& location,
716 {
717 size_t level = subtest.nesting_depth ();
718 *this << indent (level + 1) << "not ok "
719 << static_cast<int> (subtest.current_subtest_index ());
720
721 if (!message.empty ())
722 {
723 *this << " - " << message.c_str ();
724 }
725 *this << endl;
726
727 // https://testanything.org/tap-version-14-specification.html
728 // 2-space indentation for YAML diagnostics.
729 *this << indent (level + 1) << " ---";
730 if (has_expression)
731 {
732 *this << endl;
733 *this << indent (level + 1) << " condition: ";
734 }
735 }

References micro_os_plus::micro_test_plus::detail::runnable_base::current_subtest_index, micro_os_plus::micro_test_plus::endl, micro_os_plus::micro_test_plus::indent and micro_os_plus::micro_test_plus::subtest::nesting_depth.

output_fail_suffix_()

void micro_os_plus::micro_test_plus::reporter_tap::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.

Completes TAP14 YAML diagnostics for a failing check, optionally appends an "aborted..." marker, emits source filename/line fields, closes the YAML block, and flushes the stream.

Declaration at line 268 of file reporter-tap.h, definition at line 744 of file reporter-tap.cpp.

745 const reflection::source_location& location, bool abort,
747 {
748 size_t level = subtest.nesting_depth ();
749 if (abort)
750 {
751 *this << " aborted...";
752 }
753 *this << endl;
754
755 // https://testanything.org/tap-version-14-specification.html
756 // 2-space indentation for YAML diagnostics.
757
758 *this << indent (level + 1) << " at:" << endl;
759 *this << indent (level + 1)
760 << " filename: " << reflection::short_name (location.file_name ())
761 << endl;
762 *this << indent (level + 1) << " line: " << location.line () << endl;
763
764 *this << indent (level + 1) << " ..." << endl;
765
766 flush ();
767 }

References micro_os_plus::micro_test_plus::endl, micro_os_plus::micro_test_plus::reflection::source_location::file_name, micro_os_plus::micro_test_plus::reporter::flush, 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_pass_prefix_()

void micro_os_plus::micro_test_plus::reporter_tap::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 230 of file reporter-tap.h, definition at line 675 of file reporter-tap.cpp.

676 {
677 size_t level = subtest.nesting_depth ();
678 *this << indent (level + 1) << "ok "
679 << static_cast<int> (subtest.current_subtest_index ()) << " - ";
680 if (!message.empty ())
681 {
682 *this << message.c_str ();
683 }
684 }

References micro_os_plus::micro_test_plus::detail::runnable_base::current_subtest_index, 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_tap::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 240 of file reporter-tap.h, definition at line 695 of file reporter-tap.cpp.

696 {
697 *this << endl;
698
699 flush ();
700 }

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

Referenced by micro_os_plus::micro_test_plus::reporter_human::end_subtest, end_subtest, micro_os_plus::micro_test_plus::reporter_human::end_suite, 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 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 micro_os_plus::micro_test_plus::reporter::argvs_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::begin_session, 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, micro_os_plus::micro_test_plus::reporter_human::operator<< and micro_os_plus::micro_test_plus::reporter::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 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.0 by Doxygen 1.17.0.