micro-test-plus 4.1.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::reporter_tap Class Referencefinal

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

#include <micro-os-plus/micro-test-plus.h>

Inheritance diagram for micro_os_plus::micro_test_plus::reporter_tap:

Public Member Functions

 reporter_tap (const reporter_tap &)=delete
 Deleted copy constructor to prevent copying.
 reporter_tap (reporter_tap &&)=delete
 Deleted move constructor to prevent moving.
 reporter_tap (std::unique_ptr< std::vector< std::string_view > > argvs)
 Constructor for the reporter_tap class.
 ~reporter_tap () override
 Destructor for the reporter_tap class.
void begin_session (runner &runner) override
 Mark the beginning of a test session.
virtual void begin_subtest (subtest &subtest) override
 Mark the beginning of a subtest.
virtual void begin_suite (suite &suite) override
 Mark the beginning of a test suite.
void end_session (runner &runner) override
 Mark the end of a test session.
virtual void end_subtest (subtest &subtest) override
 Mark the end of a subtest.
virtual void end_suite (suite &suite) override
 Mark the end of a test suite.
void endline (void)
 Inserts a line ending into the output buffer.
detail::expression_formatterexpression ()
 Provides access to the expression formatter for this reporter.
void fail (bool abort, std::string &message, const std::string &expression, bool has_expression, const reflection::source_location &location, subtest &subtest)
 Report a failed condition.
void flush (void)
 Flush the current buffered content.
virtual const char * get_comment_prefix (void) override
 Returns the TAP comment prefix string "# ".
reporteroperator<< (bool v)
 Output operator for boolean values.
reporteroperator<< (char c)
 Output operator for a single character.
reporteroperator<< (const char *s)
 Output operator for a constant character string.
reporter_tapoperator<< (detail::indent_t m)
 Output operator for the indent_t manipulator.
reporteroperator<< (reporter &(*func)(reporter &))
 Output operator to display the endl.
reporteroperator<< (std::nullptr_t)
 Output operator for nullptr.
reporteroperator<< (std::string_view sv)
 Output operator for std::string_view.
template<typename T>
reporteroperator<< (T *v)
 Output operator to display any pointer.
template<class T>
requires std::is_arithmetic_v<T>
reporteroperator<< (T v)
 Output operator for arithmetic types, with type suffixes.
reporter_tapoperator= (const reporter_tap &)=delete
 Deleted copy assignment operator to prevent copying.
reporter_tapoperator= (reporter_tap &&)=delete
 Deleted move assignment operator to prevent moving.
void pass (std::string &message, const std::string &expression, subtest &subtest)
 Report a passed condition.
auto verbosity () const -> micro_test_plus::verbosity
 Returns the current verbosity level.
void write_buffer_to_stdout (void)
 Output the current buffered content.

Protected Member Functions

auto colour_ (const bool cond) const
 Selects the appropriate colour code based on a condition.
void output_fail_prefix_ (std::string &message, const bool has_expression, const reflection::source_location &location, subtest &subtest) override
 Outputs the prefix for a failing condition.
void output_fail_suffix_ (const reflection::source_location &location, bool abort, subtest &subtest) override
 Outputs the suffix for a failing condition.
void output_pass_prefix_ (std::string &message, subtest &subtest) override
 Outputs the prefix for a passing condition.
void output_pass_suffix_ (subtest &subtest) override
 Outputs the suffix for a passing condition.
void write_buffer_to_file_ (void)
void write_info_ (void)
 Appends informational (non-result) text to the output buffer.

Protected Attributes

bool add_empty_line_ { true }
 Controls whether to add an empty line between successful test cases.
std::unique_ptr< std::vector< std::string_view > > argvs_ {}
 Owns the command-line arguments passed to the test runner.
std::string buffer_ {}
 Output accumulation buffer.
detail::colours colours_ {}
 ANSI colour codes for output formatting.
detail::expression_formatter expression_ { colours_ }
 Expression formatter for pass and fail reporting.
FILE * output_file_ { nullptr }
 Optional output file for redirecting test report output.
const char * output_file_path_ { nullptr }
 Optional file path for redirecting test report output.
enum verbosity verbosity_ = verbosity::normal
 The verbosity level for test reporting.

Detailed Description

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.

Constructor & Destructor Documentation

◆ reporter_tap() [1/3]

micro_os_plus::micro_test_plus::reporter_tap::reporter_tap ( std::unique_ptr< std::vector< std::string_view > > argvs)
Parameters
argvsOwning 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.

Definition at line 83 of file reporter-tap.cpp.

85 : reporter{ std::move (argvs) }
86 {
87#if defined(MICRO_OS_PLUS_TRACE) \
88 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
89 trace::printf ("%s\n", __PRETTY_FUNCTION__);
90#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
91 }
reporter(std::unique_ptr< std::vector< std::string_view > > argvs)
Constructor for the reporter class.
Definition reporter.cpp:87

References micro_os_plus::micro_test_plus::reporter::reporter().

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

◆ reporter_tap() [2/3]

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

References reporter_tap().

◆ reporter_tap() [3/3]

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

References reporter_tap().

◆ ~reporter_tap()

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

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.

Definition at line 99 of file reporter-tap.cpp.

100 {
101#if defined(MICRO_OS_PLUS_TRACE) \
102 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
103 trace::printf ("%s\n", __PRETTY_FUNCTION__);
104#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
105 }

Member Function Documentation

◆ begin_session()

void micro_os_plus::micro_test_plus::reporter_tap::begin_session ( runner & runner)
overridevirtual
Parameters
runnerReference 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 137 of file reporter-tap.cpp.

138 {
139#if defined(MICRO_OS_PLUS_TRACE) \
140 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
141 trace::printf ("%s\n", __PRETTY_FUNCTION__);
142#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
143
144#if defined(__GNUC__)
145#pragma GCC diagnostic push
146#if defined(__clang__)
147#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
148#endif
149#endif
150
152 {
153 printf ("\n");
154 }
155
156 write_info_ ();
157
158 const char* message = "TAP version 14";
159 if (output_file_ != nullptr)
160 {
161 fprintf (output_file_, "%s\n", message);
162 }
163
165 {
166 printf ("%s\n", message);
167
168 flush ();
169 }
170
171 add_empty_line_ = false;
172
173#if defined(__GNUC__)
174#pragma GCC diagnostic pop
175#endif
176 }
FILE * output_file_
Optional output file for redirecting test report output.
Definition reporter.h:591
bool add_empty_line_
Controls whether to add an empty line between successful test cases.
Definition reporter.h:572
void write_info_(void)
Appends informational (non-result) text to the output buffer.
Definition reporter.cpp:278
void flush(void)
Flush the current buffered content.
Definition reporter.cpp:373
enum verbosity verbosity_
The verbosity level for test reporting.
Definition reporter.h:537

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)
overridevirtual
Parameters
subtestReference 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 472 of file reporter-tap.cpp.

473 {
474#if defined(MICRO_OS_PLUS_TRACE) \
475 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
476#pragma GCC diagnostic push
477#if defined(__clang__)
478#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
479#endif
480 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, subtest.name ());
481#pragma GCC diagnostic pop
482#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
483
484#if defined(__GNUC__)
485#pragma GCC diagnostic push
486#if defined(__clang__)
487#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
488#endif
489#endif
490
491 if (!buffer_.empty ())
492 {
493 // Each suite should start with an empty buffer.
495 flush ();
496 abort ();
497 }
498
499 std::string indent (indent_size * subtest.nesting_depth (), ' ');
500
501 char message_subtest[120];
502 snprintf (message_subtest, sizeof (message_subtest), "%s# Subtest: %s",
503 indent.c_str (), subtest.name ());
504
505 if (output_file_ != nullptr)
506 {
507 fprintf (output_file_, "%s\n", message_subtest);
508 }
509
511 {
512 if (add_empty_line_)
513 {
514 printf ("\n");
515 }
516
517 printf ("%s\n", message_subtest);
518
519 flush ();
520
521 add_empty_line_ = false;
522 }
523
524#if defined(__GNUC__)
525#pragma GCC diagnostic pop
526#endif
527 }
void write_buffer_to_stdout(void)
Output the current buffered content.
Definition reporter.cpp:245
std::string buffer_
Output accumulation buffer.
Definition reporter.h:552
constexpr size_t indent_size
Number of spaces per indentation level.
detail::indent_t indent(size_t level)
Factory function that creates an indent_t manipulator.

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)
overridevirtual
Parameters
suiteReference 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 279 of file reporter-tap.cpp.

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

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_.

◆ colour_()

auto micro_os_plus::micro_test_plus::reporter::colour_ ( const bool cond) const
inlinenodiscardprotectedinherited
Parameters
condBoolean 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.

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

119 {
120 return cond ? colours_.pass : colours_.fail;
121 }
detail::colours colours_
ANSI colour codes for output formatting.
Definition reporter.h:542

References colours_.

Referenced by get_comment_prefix().

◆ end_session()

void micro_os_plus::micro_test_plus::reporter_tap::end_session ( runner & runner)
overridevirtual
Parameters
runnerReference 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 188 of file reporter-tap.cpp.

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

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)
overridevirtual
Parameters
subtestReference 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 539 of file reporter-tap.cpp.

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

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)
overridevirtual
Parameters
suiteReference 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 336 of file reporter-tap.cpp.

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

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 )
inherited
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.

Definition at line 229 of file reporter.cpp.

230 {
231 buffer_.append ("\n");
232 flush ();
233 }

References buffer_, and flush().

◆ expression()

detail::expression_formatter & micro_os_plus::micro_test_plus::reporter::expression ( )
inlineinherited
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.

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

108 {
109 return expression_;
110 }
detail::expression_formatter expression_
Expression formatter for pass and fail reporting.
Definition reporter.h:563

References expression_.

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

◆ fail()

void micro_os_plus::micro_test_plus::reporter::fail ( bool abort,
std::string & message,
const std::string & expression,
bool has_expression,
const reflection::source_location & location,
subtest & subtest )
inherited
Parameters
abortWhether to abort execution after failure.
messageThe message to display.
expressionThe string representation of the expression.
has_expressionWhether the expression is a compound op to display.
locationThe source location of the failure.
subtestThe 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.

Definition at line 471 of file reporter.cpp.

475 {
476 output_fail_prefix_ (message, has_expression, location, subtest);
477
478 if (has_expression)
479 {
480 *this << expression;
481 }
482
483 output_fail_suffix_ (location, abort, subtest);
484 }
virtual void output_fail_prefix_(std::string &message, const bool has_expression, const reflection::source_location &location, subtest &subtest)=0
Outputs the prefix for a failing condition.
detail::expression_formatter & expression()
Provides access to the expression formatter for this reporter.
virtual void output_fail_suffix_(const reflection::source_location &location, bool abort, subtest &subtest)=0
Outputs the suffix for a failing condition.

References expression(), output_fail_prefix_(), and output_fail_suffix_().

◆ flush()

void micro_os_plus::micro_test_plus::reporter::flush ( void )
inherited
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.

Definition at line 373 of file reporter.cpp.

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

References output_file_.

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

◆ get_comment_prefix()

const char * micro_os_plus::micro_test_plus::reporter_tap::get_comment_prefix ( void )
overridevirtual
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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 665 of file reporter-tap.cpp.

666 {
667 return "# ";
668 }

◆ operator<<() [1/9]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( bool v)
Parameters
vThe boolean value to output.
Returns
Reference to the current reporter instance.

◆ operator<<() [2/9]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( char c)
Parameters
cThe 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.

Definition at line 216 of file reporter.cpp.

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

◆ operator<<() [3/9]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( const char * s)
Parameters
sThe 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.

Definition at line 225 of file reporter.cpp.

440 {
441 buffer_.append (s);
442 return *this;
443 }

◆ operator<<() [4/9]

reporter_tap & micro_os_plus::micro_test_plus::reporter_tap::operator<< ( detail::indent_t m)
Parameters
mThe 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.

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

120 {
121 buffer_.append (m.level * indent_size, ' ');
122 return *this;
123 }

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<<() [5/9]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( reporter &(* func )(reporter &))
Parameters
funcFunction 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.

Definition at line 274 of file reporter.cpp.

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

◆ operator<<() [6/9]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( std::nullptr_t )
Returns
Reference to the current reporter instance.

◆ operator<<() [7/9]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( std::string_view sv)
Parameters
svThe 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.

Definition at line 207 of file reporter.cpp.

411 {
412 buffer_.append (sv);
413 return *this;
414 }

◆ operator<<() [8/9]

template<typename T>
reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( T * v)
Template Parameters
TThe type of the pointer.
Parameters
vThe 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.

Definition at line 265 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<<() [9/9]

template<class T>
requires std::is_arithmetic_v<T>
reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( T v)
Template Parameters
TThe arithmetic type.
Parameters
vThe 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.

Definition at line 253 of file reporter-inlines.h.

186 {
188 return *this;
189 }
void append_number_(std::string &buffer, T v)
Appends the string representation of a numeric value to a buffer, using std::to_chars for allocation-...

◆ operator=() [1/2]

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

References reporter_tap().

◆ operator=() [2/2]

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

References reporter_tap().

◆ 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 )
overrideprotectedvirtual
Parameters
messageThe message to display.
has_expressionWhether the failure is associated with an expression.
locationThe source location of the failure.
subtestThe 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 720 of file reporter-tap.cpp.

724 {
725 size_t level = subtest.nesting_depth ();
726 *this << indent (level + 1) << "not ok "
727 << static_cast<int> (subtest.current_subtest_index ());
728
729 if (!message.empty ())
730 {
731 *this << " - " << message.c_str ();
732 }
733 *this << endl;
734
735 // https://testanything.org/tap-version-14-specification.html
736 // 2-space indentation for YAML diagnostics.
737 *this << indent (level + 1) << " ---";
738 if (has_expression)
739 {
740 *this << endl;
741 *this << indent (level + 1) << " condition: ";
742 }
743 }
reporter & endl(reporter &stream)
Output stream manipulator for ending a line in test reports.
Definition reporter.cpp:214

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 )
overrideprotectedvirtual
Parameters
locationThe source location of the failure.
abortWhether to abort execution after failure.
subtestThe 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 752 of file reporter-tap.cpp.

755 {
756 size_t level = subtest.nesting_depth ();
757 if (abort)
758 {
759 *this << " aborted...";
760 }
761 *this << endl;
762
763 // https://testanything.org/tap-version-14-specification.html
764 // 2-space indentation for YAML diagnostics.
765
766 *this << indent (level + 1) << " at:" << endl;
767 *this << indent (level + 1)
768 << " filename: " << reflection::short_name (location.file_name ())
769 << endl;
770 *this << indent (level + 1) << " line: " << location.line () << endl;
771
772 *this << indent (level + 1) << " ..." << endl;
773
774 flush ();
775 }
const char * short_name(const char *name) noexcept
Extract a short type or function name from a fully qualified name.

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 )
overrideprotectedvirtual
Parameters
messageThe message to display.
subtestThe 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 683 of file reporter-tap.cpp.

684 {
685 size_t level = subtest.nesting_depth ();
686 *this << indent (level + 1) << "ok "
687 << static_cast<int> (subtest.current_subtest_index ()) << " - ";
688 if (!message.empty ())
689 {
690 *this << message.c_str ();
691 }
692 }

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)
overrideprotectedvirtual
Parameters
subtestThe 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.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 703 of file reporter-tap.cpp.

704 {
705 *this << endl;
706
707 flush ();
708 }

References micro_os_plus::micro_test_plus::endl(), and micro_os_plus::micro_test_plus::reporter::flush().

◆ pass()

void micro_os_plus::micro_test_plus::reporter::pass ( std::string & message,
const std::string & expression,
subtest & subtest )
inherited
Parameters
messageThe message to display.
expressionThe string representation of the expression.
subtestThe 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.

Definition at line 452 of file reporter.cpp.

454 {
455 output_pass_prefix_ (message, subtest);
456
457 if (message.empty ())
458 {
459 *this << expression;
460 }
461
462 output_pass_suffix_ (subtest);
463 }
virtual void output_pass_suffix_(subtest &subtest)=0
Outputs the suffix for a passing condition.
virtual void output_pass_prefix_(std::string &message, subtest &subtest)=0
Outputs the prefix for a passing condition.

References expression(), output_pass_prefix_(), and output_pass_suffix_().

◆ verbosity()

auto micro_os_plus::micro_test_plus::reporter::verbosity ( ) const -> micro_test_plus::verbosity
inlineinherited
Parameters
None.
Returns
The active verbosity value.

Returns the verbosity level stored in verbosity_.

Definition at line 92 of file reporter-inlines.h.

93 {
94 return verbosity_;
95 }

References verbosity(), and verbosity_.

Referenced by get_comment_prefix(), and verbosity().

◆ write_buffer_to_file_()

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

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.

Definition at line 258 of file reporter.cpp.

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

References buffer_, and output_file_.

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

◆ write_buffer_to_stdout()

void micro_os_plus::micro_test_plus::reporter::write_buffer_to_stdout ( void )
inherited
Note
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.

Definition at line 245 of file reporter.cpp.

246 {
247 // Pass only the string, do not add an `\n` here.
248 printf ("%s", buffer_.c_str ());
249 }

References buffer_.

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

◆ write_info_()

void micro_os_plus::micro_test_plus::reporter::write_info_ ( void )
protectedinherited
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.

Definition at line 278 of file reporter.cpp.

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

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

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

Member Data Documentation

◆ add_empty_line_

◆ argvs_

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

Definition at line 596 of file reporter.h.

596{};

Referenced by reporter(), and write_info_().

◆ buffer_

◆ colours_

◆ expression_

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

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.

563{ colours_ };

Referenced by expression().

◆ output_file_

◆ output_file_path_

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

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{ nullptr };

Referenced by reporter(), and ~reporter().

◆ verbosity_


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