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

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

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

Inheritance diagram for micro_os_plus::micro_test_plus::reporter_human:

Public Member Functions

 reporter_human (const reporter_human &)=delete
 Deleted copy constructor to prevent copying.
 reporter_human (reporter_human &&)=delete
 Deleted move constructor to prevent moving.
 reporter_human (std::unique_ptr< std::vector< std::string_view > > argvs)
 Constructor for the reporter_human class.
 ~reporter_human () override
 Destructor for the reporter_human 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 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 an empty 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_humanoperator<< (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_humanoperator= (const reporter_human &)=delete
 Deleted copy assignment operator to prevent copying.
reporter_humanoperator= (reporter_human &&)=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_human provides the default concrete implementation of the reporter abstract interface, formatting and presenting test results using printf-based output. It accumulates output in an internal string buffer and writes it to the standard output stream, supporting colour-coded diagnostics and multiple verbosity levels.

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

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

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

Constructor & Destructor Documentation

◆ reporter_human() [1/3]

micro_os_plus::micro_test_plus::reporter_human::reporter_human ( 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. On POSIX platforms, if stdout is connected to a terminal (isatty()), colour output is enabled by selecting the red/green colour scheme. If tracing is enabled, the function signature is output for diagnostic purposes.

Definition at line 84 of file reporter-human.cpp.

86 : reporter{ std::move (argvs) }
87 {
88#if defined(MICRO_OS_PLUS_TRACE) \
89 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
90 trace::printf ("%s\n", __PRETTY_FUNCTION__);
91#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
92
93#if defined(__APPLE__) || defined(__linux__) || defined(__unix__)
94 if (isatty (fileno (stdout)))
95 {
97 }
98#endif
99 }
reporter(std::unique_ptr< std::vector< std::string_view > > argvs)
Constructor for the reporter class.
Definition reporter.cpp:79
detail::colours colours_
ANSI colour codes for output formatting.
Definition reporter.h:542

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

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

◆ reporter_human() [2/3]

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

References reporter_human().

◆ reporter_human() [3/3]

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

References reporter_human().

◆ ~reporter_human()

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

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

Definition at line 107 of file reporter-human.cpp.

108 {
109#if defined(MICRO_OS_PLUS_TRACE) \
110 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
111 trace::printf ("%s\n", __PRETTY_FUNCTION__);
112#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
113 }

Member Function Documentation

◆ begin_session()

void micro_os_plus::micro_test_plus::reporter_human::begin_session ( runner & runner)
overridevirtual
Parameters
runnerReference to the test runner.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 151 of file reporter-human.cpp.

152 {
153#if defined(MICRO_OS_PLUS_TRACE) \
154 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
155 trace::printf ("%s\n", __PRETTY_FUNCTION__);
156#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
157
158#if defined(__GNUC__)
159#pragma GCC diagnostic push
160#if defined(__clang__)
161#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
162#endif
163#endif
164
166 {
167 printf ("\n");
168 }
169
170 write_info_ ();
171
172 const char* message = "µTest++ human report";
173 if (output_file_ != nullptr)
174 {
175 fprintf (output_file_, "%s\n", message);
176 }
177
179 {
180 printf ("%s\n", message);
181
182 flush ();
183 }
184
185 add_empty_line_ = true;
186
187#if defined(__GNUC__)
188#pragma GCC diagnostic pop
189#endif
190 }
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:270
void flush(void)
Flush the current buffered content.
Definition reporter.cpp:365
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_human::begin_subtest ( subtest & subtest)
overridevirtual
Parameters
subtestReference to the subtest.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 489 of file reporter-human.cpp.

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

◆ begin_suite()

void micro_os_plus::micro_test_plus::reporter_human::begin_suite ( suite & suite)
overridevirtual
Parameters
suiteReference to the suite.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 296 of file reporter-human.cpp.

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

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

118 {
119 return cond ? colours_.pass : colours_.fail;
120 }

References colours_.

Referenced by get_comment_prefix().

◆ end_session()

void micro_os_plus::micro_test_plus::reporter_human::end_session ( runner & runner)
overridevirtual
Parameters
runnerReference to the test runner.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 202 of file reporter-human.cpp.

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

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

◆ end_subtest()

void micro_os_plus::micro_test_plus::reporter_human::end_subtest ( subtest & subtest)
overridevirtual
Parameters
subtestReference to the subtest.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 561 of file reporter-human.cpp.

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

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

◆ end_suite()

void micro_os_plus::micro_test_plus::reporter_human::end_suite ( suite & suite)
overridevirtual
Parameters
suiteReference to the test suite.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 352 of file reporter-human.cpp.

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

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

◆ endline()

void micro_os_plus::micro_test_plus::reporter::endline ( void )
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 221 of file reporter.cpp.

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

References buffer_, and flush().

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

◆ expression()

detail::expression_formatter & micro_os_plus::micro_test_plus::reporter::expression ( )
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 106 of file reporter-inlines.h.

107 {
108 return expression_;
109 }
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::assume(), micro_os_plus::micro_test_plus::subtest::expect(), fail(), get_comment_prefix(), operator<<(), and pass().

◆ fail()

void micro_os_plus::micro_test_plus::reporter::fail ( bool abort,
std::string & message,
const std::string & expression,
bool has_expression,
const reflection::source_location & location,
subtest & subtest )
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 463 of file reporter.cpp.

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

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

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_human::get_comment_prefix ( void )
overridevirtual
Parameters
None.
Returns
An empty string, as the human-readable format does not use a comment prefix.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 695 of file reporter-human.cpp.

696 {
697 return "";
698 }

Referenced by operator<<().

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

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

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

432 {
433 buffer_.append (s);
434 return *this;
435 }

◆ operator<<() [4/9]

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

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

135 {
136 buffer_.append (m.level * indent_size, ' ');
137 return *this;
138 }

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

◆ operator<<() [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.

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

References micro_os_plus::micro_test_plus::reporter::argvs_, and get_comment_prefix().

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

403 {
404 buffer_.append (sv);
405 return *this;
406 }

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

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

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<<() [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.

185 {
187 return *this;
188 }
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_human & micro_os_plus::micro_test_plus::reporter_human::operator= ( const reporter_human & )
delete

References reporter_human().

◆ operator=() [2/2]

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

References reporter_human().

◆ output_fail_prefix_()

void micro_os_plus::micro_test_plus::reporter_human::output_fail_prefix_ ( std::string & message,
const bool has_expression,
const reflection::source_location & location,
subtest & subtest )
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 the label "FAILED". The source location is appended in parentheses, showing the file or folder name and line number where the failure occurred. Colour formatting is reset after the prefix to maintain consistent output style across all test cases and folders.

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 753 of file reporter-human.cpp.

756 {
757#if defined(__GNUC__)
758#pragma GCC diagnostic push
759#if defined(__clang__)
760#pragma clang diagnostic ignored "-Wsign-conversion"
761#elif defined(__GNUC__)
762#pragma GCC diagnostic ignored "-Wnarrowing"
763#pragma GCC diagnostic ignored "-Wsign-conversion"
764#endif
765#endif
766
767 size_t level = subtest.nesting_depth ();
768
769 *this << indent (level + 1);
770 *this << colours_.fail << "✗" << colours_.none << " ";
771 if (!message.empty ())
772 {
773 *this << message.c_str ();
774 *this << " ";
775 }
776 *this << colours_.fail << "FAILED" << colours_.none;
777 *this << " (" << reflection::short_name (location.file_name ()) << ":"
778 << location.line ();
779 if (has_expression)
780 {
781 *this << ", ";
782 }
783
784#if defined(__GNUC__)
785#pragma GCC diagnostic pop
786#endif
787 }
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::reporter::colours_, micro_os_plus::micro_test_plus::reflection::source_location::file_name(), micro_os_plus::micro_test_plus::indent(), micro_os_plus::micro_test_plus::reflection::source_location::line(), micro_os_plus::micro_test_plus::subtest::nesting_depth(), and micro_os_plus::micro_test_plus::reflection::short_name().

◆ output_fail_suffix_()

void micro_os_plus::micro_test_plus::reporter_human::output_fail_suffix_ ( const reflection::source_location & location,
bool abort,
subtest & subtest )
overrideprotectedvirtual
Parameters
locationThe source location of the failure.
abortWhether to abort execution after failure.
subtestThe subtest that owns this check.
Returns
Nothing.

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

Implements micro_os_plus::micro_test_plus::reporter.

Definition at line 799 of file reporter-human.cpp.

802 {
803 *this << ")";
804 if (abort)
805 {
806 *this << " aborted...";
807 }
808 *this << endl;
809
810 flush ();
811 }
reporter & endl(reporter &stream)
Output stream manipulator for ending a line in test reports.
Definition reporter.cpp:206

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

◆ output_pass_prefix_()

void micro_os_plus::micro_test_plus::reporter_human::output_pass_prefix_ ( std::string & message,
subtest & subtest )
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 713 of file reporter-human.cpp.

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

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

◆ output_pass_suffix_()

void micro_os_plus::micro_test_plus::reporter_human::output_pass_suffix_ ( subtest & subtest)
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 734 of file reporter-human.cpp.

735 {
736 *this << endl;
737
738 flush ();
739 }

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

446 {
447 output_pass_prefix_ (message, subtest);
448
449 if (message.empty ())
450 {
451 *this << expression;
452 }
453
454 output_pass_suffix_ (subtest);
455 }
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 91 of file reporter-inlines.h.

92 {
93 return verbosity_;
94 }

References verbosity(), and verbosity_.

Referenced by get_comment_prefix(), and verbosity().

◆ write_buffer_to_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 250 of file reporter.cpp.

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

References buffer_, and output_file_.

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

◆ write_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 237 of file reporter.cpp.

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

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

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

◆ 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: