micro-test-plus 4.1.1
µ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 92 of file reporter-human.cpp.

94 : reporter{ std::move (argvs) }
95 {
96#if defined(MICRO_OS_PLUS_TRACE) \
97 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
98 trace::printf ("%s\n", __PRETTY_FUNCTION__);
99#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
100
101#if defined(__APPLE__) || defined(__linux__) || defined(__unix__)
102 if (isatty (fileno (stdout)))
103 {
105 }
106#endif
107 }
reporter(std::unique_ptr< std::vector< std::string_view > > argvs)
Constructor for the reporter class.
Definition reporter.cpp:87
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 115 of file reporter-human.cpp.

116 {
117#if defined(MICRO_OS_PLUS_TRACE) \
118 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
119 trace::printf ("%s\n", __PRETTY_FUNCTION__);
120#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
121 }

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

160 {
161#if defined(MICRO_OS_PLUS_TRACE) \
162 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
163 trace::printf ("%s\n", __PRETTY_FUNCTION__);
164#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
165
166#if defined(__GNUC__)
167#pragma GCC diagnostic push
168#if defined(__clang__)
169#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
170#endif
171#endif
172
174 {
175 printf ("\n");
176 }
177
178 write_info_ ();
179
180 const char* message = "µTest++ human report";
181 if (output_file_ != nullptr)
182 {
183 fprintf (output_file_, "%s\n", message);
184 }
185
187 {
188 printf ("%s\n", message);
189
190 flush ();
191 }
192
193 add_empty_line_ = true;
194
195#if defined(__GNUC__)
196#pragma GCC diagnostic pop
197#endif
198 }
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_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 497 of file reporter-human.cpp.

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

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

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 }

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

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

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

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

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

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

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 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_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 703 of file reporter-human.cpp.

704 {
705 return "";
706 }

◆ 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_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 141 of file reporter-human.cpp.

143 {
144 buffer_.append (m.level * indent_size, ' ');
145 return *this;
146 }

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.

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 }

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

◆ 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_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 761 of file reporter-human.cpp.

764 {
765#if defined(__GNUC__)
766#pragma GCC diagnostic push
767#if defined(__clang__)
768#pragma clang diagnostic ignored "-Wsign-conversion"
769#elif defined(__GNUC__)
770#pragma GCC diagnostic ignored "-Wnarrowing"
771#pragma GCC diagnostic ignored "-Wsign-conversion"
772#endif
773#endif
774
775 size_t level = subtest.nesting_depth ();
776
777 *this << indent (level + 1);
778 *this << colours_.fail << "✗" << colours_.none << " ";
779 if (!message.empty ())
780 {
781 *this << message.c_str ();
782 *this << " ";
783 }
784 *this << colours_.fail << "FAILED" << colours_.none;
785 *this << " (" << reflection::short_name (location.file_name ()) << ":"
786 << location.line ();
787 if (has_expression)
788 {
789 *this << ", ";
790 }
791
792#if defined(__GNUC__)
793#pragma GCC diagnostic pop
794#endif
795 }
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 807 of file reporter-human.cpp.

810 {
811 *this << ")";
812 if (abort)
813 {
814 *this << " aborted...";
815 }
816 *this << endl;
817
818 flush ();
819 }
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::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 721 of file reporter-human.cpp.

722 {
723 size_t level = subtest.nesting_depth ();
724
725 *this << indent (level + 1);
726 *this << colours_.pass << "✓" << colours_.none << " ";
727 if (!message.empty ())
728 {
729 *this << message.c_str ();
730 }
731 }

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

743 {
744 *this << endl;
745
746 flush ();
747 }

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: