Skip to main content

reporter_tap Class

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

Declaration​

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

Included Headers​

Base class​

classreporter

Abstract base class for the reporters that display test results, including operand values for failures. More...

Public Constructors Index​

reporter_tap (const reporter_tap &)=delete

Deleted copy constructor to prevent copying. More...

reporter_tap (const runner_options &opts)

Constructor for the reporter_tap class. More...

reporter_tap (reporter_tap &&)=delete

Deleted move constructor to prevent moving. More...

Public Destructor Index​

~reporter_tap () override

Destructor for the reporter_tap class. More...

Public Operators Index​

reporter &operator<< (bool v)

Output operator for boolean values. More...

reporter &operator<< (char c)

Output operator for a single character. More...

reporter &operator<< (const char *s)

Output operator for a constant character string. More...

reporter &operator<< (indentation m)

Output operator for the indentation manipulator. More...

reporter &operator<< (reporter &(*func)(reporter &))

Output operator for stream manipulators, such as endl. More...

reporter &operator<< (std::nullptr_t)

Output operator for nullptr. More...

reporter &operator<< (std::string_view sv)

Output operator for std::string_view. More...

template <typename T>
reporter &operator<< (T *v)

Output operator to display any pointer. More...

template <class T>
reporter &operator<< (T v)

Output operator for arithmetic types. More...

reporter_tap &operator= (const reporter_tap &)=delete

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

reporter_tap &operator= (reporter_tap &&)=delete

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

Public Member Functions Index​

voidabort_session (const reflection::source_location &location, bool is_requirement) override

Reports the abort of the test execution. More...

voidbegin_session (const runner &runner) override

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

voidbegin_suite (const suite &suite) override

Marks the beginning of a test suite. More...

voidbegin_test_case (const test_case &test_case) override

Marks the beginning of a test case. More...

const char *comment_prefix (void) const noexcept override

Returns the TAP comment prefix string "# ". More...

voidend_line (void)

Appends a line ending to the internal output buffer. More...

voidend_session (const runner &runner) override

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

voidend_suite (const suite &suite) override

Marks the end of a test suite. More...

voidend_test_case (const test_case &test_case) override

Marks the end of a test case. More...

const char *error_prefix (void) const noexcept override

Returns the TAP bail-out prefix string "Bail out! ". More...

voidfail (const failure_info &failure, const std::string &expression, const test_case &test_case)

Reports a failed condition. More...

voidfail_suite (const std::string &message, const suite &suite) override

Reports a failure of a test suite outside its test cases. More...

voidflush_streams (void)

Flushes the standard output stream and the output file. More...

boolhas_output_file_error (void) const noexcept

Returns whether the output file could not be opened. More...

voidpass (const std::string &message, const std::string &expression, const test_case &test_case)

Reports a passed condition. More...

voidpass_without_text (const test_case &test_case) override

Records a passed check whose text is not written. More...

voidskip_suite (const suite &suite) override

Reports a test suite skipped by the filter. More...

voidskip_test_case (const test_case &test_case) override

Reports a test case skipped by the filter. More...

boolwrites_passed_checks (void) const noexcept

Returns whether the passed checks are written anywhere. More...

Protected Member Functions Index​

voidannounce_output_file (void)

Tells the console where the output file was written. More...

voidclear_buffer (void)

Clears the output buffer. More...

voidcommit_outer_results (void)

Writes the results of the outer test case, if any, before a nested test case begins or is skipped. More...

std::string_viewconsole_lines (bool failed) const noexcept

Returns the buffered lines that the console displays when a test case or a suite ends, or when its results are committed. More...

voiddisplay_open_test_cases (bool include_last)

Displays the headings not yet displayed, of the open test cases. More...

voidenter_suite (const suite &suite, bool displayed)

Notes the suite that begins, for the headings displayed later. More...

voidmark_failure (size_t begin)

Records that the lines appended to the buffer from a given position are a failure. More...

output_routeroute (record_kind kind) const noexcept

Tells where a kind of record is written. More...

voidwrite_buffer_to_file (void)

Writes the current buffered content to the output file. More...

voidwrite_console (const char *format,...)

Writes formatted text to the console. More...

voidwrite_console_text (std::string_view text)

Writes a text to the console, unchanged. More...

voidwrite_file (const char *format,...)

Writes formatted text to the output file. More...

voidwrite_info (const std::vector< std::string > &arguments)

Writes the informational (non-result) lines to the console and to the output file. More...

voidwrite_line (bool to_console, const char *format,...)

Writes formatted lines to the output file and, when requested, to the console. More...

Private Member Functions Index​

voidcommit_buffer (void) override

Writes the results buffered for the outer test case before a nested test case begins. More...

voiddisplay_open_heading (const open_test_case &open, bool is_first) override

Writes the # Subtest: heading of an open test case. More...

voidoutput_fail_prefix (const std::string &message, const bool has_expression, const reflection::source_location &location, const test_case &test_case) override

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

voidoutput_fail_suffix (const reflection::source_location &location, check_kind kind, const test_case &test_case) override

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

voidoutput_pass_prefix (const std::string &message, const test_case &test_case) override

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

voidoutput_pass_suffix (const test_case &test_case) override

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

voidwrite_quiet_failures (void)

Writes the failed checks of the quiet verbosity, as comments. More...

Protected Member Attributes Index​

booladd_empty_line_ { true }

Whether to write an empty line before the next console output. More...

std::stringbuffer_ {}

Output accumulation buffer. More...

boolbuffer_has_failures_ { false }

Whether the output buffer contains a failed check. More...

colourscolours_ {}

ANSI colour codes for output formatting. More...

const suite *current_suite_ { nullptr }

The suite that has begun and not yet ended. More...

expression_formatterexpression_ { colours_ }

Expression formatter for pass and fail reporting. More...

std::stringfailures_ {}

The lines of the failed checks, for the quiet verbosity. More...

boolhas_output_file_error_ { false }

Whether the output file could not be opened. More...

std::vector< open_test_case >open_test_cases_ {}

The test cases that have begun and not yet ended, outermost first. More...

FILE *output_file_ { nullptr }

Optional output file, receiving a copy of the test report. More...

std::stringoutput_file_path_ {}

Path of the optional output file. More...

boolsuite_displayed_ { false }

Whether the heading of the current suite was displayed on the console. More...

const micro_test_plus::verbosityverbosity_

The verbosity level for test reporting. More...

Private Member Attributes Index​

size_tcondition_begin_ = std::string::npos

The position in the buffer where the expression of a failed check begins. More...

size_tdescription_begin_ = 0

The position in the buffer where the description of a passed check begins. More...

Protected Static Functions Index​

static voidformat_elapsed_time (const stopwatch &stopwatch, char(&message)[elapsed_time_size_])

Formats the elapsed time of a suite or of the session. More...

static voidformat_session_totals (const runner &runner, char(&message)[totals_size_])

Formats the totals of the test session. More...

static voidformat_suite_totals (const suite &suite, char(&message)[totals_size_])

Formats the totals of a suite. More...

static voidformat_test_case_totals (const test_case &test_case, char(&message)[totals_size_])

Formats the totals of a test case. More...

Protected Static Attributes Index​

static constexpr size_telapsed_time_size_ = 40

Size of the array that receives the elapsed time text. More...

static constexpr size_tindent_size_ = 4

Number of spaces per nesting level. More...

static constexpr size_ttotals_size_ = 94 + 6 * (std::numeric_limits<size_t>::digits10 + 1)

Size of the array that receives the totals text. More...

Deprecated Functions Index​

micro_test_plus::verbosityverbosity (void) const noexcept

Deprecated access to the verbosity level. More...

Description​

TAP (Test Anything Protocol) implementation of reporter.

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

The reporter is created by the runner, as selected by the --reporter command-line option, or by runner_options::selected_reporter; it is the default. A different output format requires a new class derived from reporter, and an extension of the runner to create it.

All members are defined within the micro_os_plus::micro_test_plus::detail namespace, since the reporters are internal to the framework.

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

Public Constructors​

reporter_tap()​

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

Deleted copy constructor to prevent copying.

The reporter owns the output buffer and the output file, which must not be shared.

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

Reference reporter_tap.

reporter_tap()​

micro_os_plus::micro_test_plus::detail::reporter_tap::reporter_tap (const runner_options & opts)
explicit

Constructor for the reporter_tap class.

Parameters
opts

The session options, passed to runner::initialise() or parsed by it from the command line.

Delegates construction to the reporter base class with the supplied options. If tracing is enabled, the function signature is output for diagnostic purposes.

Declaration at line 99 of file reporter-tap.h, definition at line 400 of file reporter-tap.cpp.

401 {
402#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
403 trace::printf ("%s\n", __PRETTY_FUNCTION__);
404#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
405 }

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

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

reporter_tap()​

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

Deleted move constructor to prevent moving.

The reporter is owned by the runner, through a pointer, and is never relocated.

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

Reference reporter_tap.

Public Destructor​

~reporter_tap()​

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

Destructor for the reporter_tap class.

The output file, if any, is closed by the base class destructor.

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

Declaration at line 147 of file reporter-tap.h, definition at line 413 of file reporter-tap.cpp.

414 {
415#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
416 trace::printf ("%s\n", __PRETTY_FUNCTION__);
417#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
418 }

Public Operators​

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (bool v)

Output operator for boolean values.

Parameters
v

The boolean value to output.

Returns

Reference to the current reporter instance.

This operator overload appends "true" or "false" to the internal output buffer of the reporter, as the expression formatter does. Being a non-template function, it is selected for bool values instead of the arithmetic template, which would format them as numbers.

Declaration at line 359 of file reporter.h, definition at line 726 of file reporter.cpp.

727 {
728 buffer_.append (v ? "true" : "false");
729 return *this;
730 }

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

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (char c)

Output operator for a single character.

Parameters
c

The character to output.

Returns

Reference to the current reporter instance.

This operator overload appends the specified character to the internal output buffer of the reporter.

Declaration at line 336 of file reporter.h, definition at line 689 of file reporter.cpp.

690 {
691 buffer_.append (1, c);
692 return *this;
693 }

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

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (const char * s)

Output operator for a constant character string.

Also selected for the non-const char pointers and arrays, which the pointer template does not accept. A null pointer is output as "nullptr".

Parameters
s

The string to output, or a null pointer.

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, or "nullptr" for a null pointer, as the expression formatter does; the char* values also reach this overload, and std::string::append() must not be called with a null pointer.

Declaration at line 350 of file reporter.h, definition at line 704 of file reporter.cpp.

704 reporter::operator<<(const char* s)
705 {
706 if (s == nullptr)
707 {
708 buffer_.append ("nullptr");
709 }
710 else
711 {
712 buffer_.append (s);
713 }
714 return *this;
715 }

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

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (indentation m)

Output operator for the indentation manipulator.

Appends indent_size_ spaces for each indentation level.

Parameters
m

The indentation manipulator produced by indent(n).

Returns

Reference to the current reporter instance.

This operator overload appends spaces to the internal output buffer, indent_size_ for each of the m.level indentation levels, allowing *this << indent(n) << "text" chaining in both reporters.

Declaration at line 418 of file reporter.h, definition at line 665 of file reporter.cpp.

666 {
667 buffer_.append (m.level * indent_size_, ' ');
668 return *this;
669 }

References micro_os_plus::micro_test_plus::detail::reporter::reporter, micro_os_plus::micro_test_plus::detail::reporter::buffer_, micro_os_plus::micro_test_plus::detail::reporter::indent_size_ and micro_os_plus::micro_test_plus::detail::indentation::level.

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (reporter &(*)(reporter &) func)

Output operator for stream manipulators, such as endl.

Parameters
func

Function pointer to the stream manipulator.

Returns

Reference to the current reporter instance.

This operator overload enables manipulators, such as endl, to be used with the reporter stream in a manner similar to standard C++ streams. When a manipulator function is passed, it is invoked with the current reporter instance.

Declaration at line 406 of file reporter.h, definition at line 651 of file reporter.cpp.

652 {
653 // Call the endl function.
654 (*func) (*this);
655 return *this;
656 }

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

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (std::nullptr_t)

Output operator for nullptr.

Returns

Reference to the current reporter instance.

This operator overload appends the string "nullptr" to the internal output buffer of the reporter, as the expression formatter does.

Declaration at line 367 of file reporter.h, definition at line 738 of file reporter.cpp.

738 reporter::operator<<(std::nullptr_t)
739 {
740 buffer_.append ("nullptr");
741 return *this;
742 }

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

operator<<()​

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (std::string_view sv)

Output operator for std::string_view.

Parameters
sv

The string view to output.

Returns

Reference to the current reporter instance.

This operator overload appends the contents of the provided std::string_view to the internal output buffer of the reporter.

Declaration at line 327 of file reporter.h, definition at line 677 of file reporter.cpp.

677 reporter::operator<<(std::string_view sv)
678 {
679 buffer_.append (sv);
680 return *this;
681 }

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

operator<<()​

template <typename T>
reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (T * v)

Output operator to display any pointer.

The char pointers are excluded, so that they are output as strings by the const char* overload, as the const char pointers are.

Template Parameters
T

The type pointed to, other than char.

Parameters
v

The pointer value to output.

Returns

Reference to the current reporter instance.

The address is formatted by the detail::append_pointer() helper, shared with the detail::expression_formatter, so that the pointers are displayed identically in the expressions and in the messages.

Declaration at line 397 of file reporter.h, definition at line 80 of file reporter-inlines.h.

80 reporter::operator<< (T* v)
81 {
83 return *this;
84 }

References micro_os_plus::micro_test_plus::detail::reporter::reporter, micro_os_plus::micro_test_plus::detail::append_pointer and micro_os_plus::micro_test_plus::detail::reporter::buffer_.

operator<<()​

template <class T>
reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< (T v)

Output operator for arithmetic types.

Template Parameters
T

The arithmetic type.

Parameters
v

The value to output.

Returns

Reference to the current reporter instance.

This template operator overload allows the reporter to output values of any arithmetic type (integral or floating-point) in a consistent and readable format. The value is formatted using the detail::append_number() helper, without a type suffix (unlike the detail::expression_formatter operators, which add one).

Declaration at line 379 of file reporter.h, definition at line 97 of file reporter-inlines.h.

98 {
100 return *this;
101 }

References micro_os_plus::micro_test_plus::detail::reporter::reporter, micro_os_plus::micro_test_plus::detail::append_number and micro_os_plus::micro_test_plus::detail::reporter::buffer_.

operator=()​

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

Deleted copy assignment operator to prevent copying.

The reporter owns the output buffer and the output file, which must not be shared.

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

Reference reporter_tap.

operator=()​

Public Member Functions​

abort_session()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session (const reflection::source_location & location, bool is_requirement)
virtual

Reports the abort of the test execution.

Displays the buffered check results, followed by a Bail out! line with the location of the failed requirement, or of the runner::abort() call.

Parameters
location

The source location of the failed requirement, or of the runner::abort() call.

is_requirement

true if the abort is caused by a failed requirement.

Returns

Nothing.

Since end_test_case() is not called for the running test cases, this member function writes the buffered lines, if any, in its place (after a failed requirement, they end with it), preceded, with normal or verbose verbosity, by the headings of the open test cases, if not displayed yet, followed by an unindented Bail out! <reason> at <file>:<line> line, with the file name escaped as the reason, which tells the TAP consumers that the run stopped early (see the TAP 14 specification), not that the output was truncated. The reason is Requirement failed after a failed requirement, and Test execution aborted for an explicit call of runner::abort().

Both are always written to the output file, as in end_test_case(), and, unless the verbosity is silent, to stdout, preceded by an empty line when add_empty_line_ is set. With quiet verbosity, which otherwise displays only the summary, the failed checks are displayed as comments, and the Bail out! line as well, since the summary is never reached.

The buffer is then cleared, so that its lines are not written again, should the abort handler throw an exception that the application catches.

Declaration at line 286 of file reporter-tap.h, definition at line 1159 of file reporter-tap.cpp.

1160 bool is_requirement)
1161 {
1162#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
1163 trace::printf ("%s\n", __PRETTY_FUNCTION__);
1164#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
1165
1166 // The type of `line()` depends on the toolchain (`uint_least32_t` for
1167 // `std::source_location`); widen it implicitly, without a cast that
1168 // would be useless on some platforms.
1169 const unsigned long line = location.line ();
1170 // The reason is escaped, as the descriptions.
1171 const std::string file_name
1172 = tap_text (utility::extract_file_name (location.file_name ()), true);
1173 const char* reason
1174 = is_requirement ? "Requirement failed" : "Test execution aborted";
1175
1177
1178 const bool to_console = route (record_kind::abort).console;
1179
1180 if (to_console)
1181 {
1182 if (route (record_kind::suite_result).console)
1183 {
1185
1186 if (add_empty_line_)
1187 {
1188 write_console ("\n");
1189 }
1190
1192 }
1193 else
1194 {
1196 }
1197 }
1198
1199 write_line (to_console, "Bail out! %s at %s:%lu\n", reason,
1200 file_name.c_str (), line);
1201
1202 flush_streams ();
1203
1205
1206 clear_buffer ();
1207
1208 // Should the abort handler throw, nothing may refer to the objects
1209 // that are unwound.
1210 open_test_cases_.clear ();
1211 current_suite_ = nullptr;
1212 }

References micro_os_plus::micro_test_plus::detail::abort, micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::reporter::announce_output_file, micro_os_plus::micro_test_plus::detail::reporter::clear_buffer, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::console_lines, micro_os_plus::micro_test_plus::detail::reporter::current_suite_, micro_os_plus::micro_test_plus::detail::reporter::display_open_test_cases, micro_os_plus::micro_test_plus::utility::extract_file_name, micro_os_plus::micro_test_plus::reflection::source_location::file_name, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::reflection::source_location::line, micro_os_plus::micro_test_plus::detail::reporter::open_test_cases_, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::suite_result, micro_os_plus::micro_test_plus::detail::reporter::write_buffer_to_file, micro_os_plus::micro_test_plus::detail::reporter::write_console, micro_os_plus::micro_test_plus::detail::reporter::write_console_text, micro_os_plus::micro_test_plus::detail::reporter::write_line and write_quiet_failures.

Referenced by operator=.

begin_session()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::begin_session (const runner & runner)
virtual

Marks the beginning of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

If verbosity is not silent, emits a blank line to stdout and then calls write_info() to output build and environment information. The TAP version header "TAP version 14" is then written to the output file (if open) and, unless verbosity is silent, to stdout. The add_empty_line_ flag is cleared so that the first suite header is not separated by an extra blank line.

Declaration at line 159 of file reporter-tap.h, definition at line 433 of file reporter-tap.cpp.

434 {
435#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
436 trace::printf ("%s\n", __PRETTY_FUNCTION__);
437#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
438
439 const bool to_console = route (record_kind::total).console;
440
441 if (to_console)
442 {
443 write_console ("\n");
444 }
445
447
448 write_line (to_console, "TAP version 14\n");
449
451
452 add_empty_line_ = false;
453 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::runner_options::arguments, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner, micro_os_plus::micro_test_plus::runner::options_, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::total, micro_os_plus::micro_test_plus::detail::reporter::write_console, micro_os_plus::micro_test_plus::detail::reporter::write_info and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by operator=.

begin_suite()​

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

Marks the beginning of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

Emits a "# Subtest: <name>" comment line to mark the start of a TAP test case block for the suite; the line breaks in the name are replaced by spaces (see tap_text()). The line is written to the output file when one is open. Under normal or verbose verbosity, it is also written to stdout, preceded by a blank line when add_empty_line_ is set.

Declaration at line 179 of file reporter-tap.h, definition at line 514 of file reporter-tap.cpp.

515 {
516#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
517 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
518#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
519
520 const tap_name name{ suite.name (), false };
521
522 const bool to_console = route (record_kind::suite_heading).console;
523
524 if (to_console && add_empty_line_)
525 {
526 write_console ("\n");
527 }
528
529 write_line (to_console, "# Subtest: %s\n", name.c_str ());
530
532
533 if (to_console)
534 {
535 add_empty_line_ = true;
536 }
537
538 enter_suite (suite, to_console);
539 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::enter_suite, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::suite_heading, micro_os_plus::micro_test_plus::detail::reporter::write_console and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by operator=.

begin_test_case()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::begin_test_case (const test_case & test_case)
virtual

Marks the beginning of a test case.

Parameters
test_case

Reference to the test case.

Returns

Nothing.

For a nested test case, the results of the checks already performed by the outer test case, if any, are written first (see commit_outer_results()), so that the output follows the execution order.

A "# Subtest: <name>" comment line (indented according to nesting depth), with the line breaks in the name replaced by spaces, is then written to the output file and, under verbose verbosity, to stdout as well. With the other verbosity levels, the heading is displayed later, only if something is displayed under it (see display_open_test_cases()).

Declaration at line 228 of file reporter-tap.h, definition at line 722 of file reporter-tap.cpp.

723 {
724#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
725 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, test_case.name ());
726#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
727
729
730 const bool to_console = route (record_kind::test_case_heading).console;
731
732 open_test_cases_.push_back ({ &test_case, to_console });
733
734 std::string indent (indent_size_ * test_case.nesting_depth (), ' ');
735
736 const tap_name name{ test_case.name (), false };
737
738 if (to_console && add_empty_line_)
739 {
740 write_console ("\n");
741 }
742
743 write_line (to_console, "%s# Subtest: %s\n", indent.c_str (),
744 name.c_str ());
745
747
748 if (to_console)
749 {
750 add_empty_line_ = false;
751 }
752 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::reporter::commit_outer_results, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::indent_size_, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::test_case::nesting_depth, micro_os_plus::micro_test_plus::detail::reporter::open_test_cases_, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::test_case_heading, micro_os_plus::micro_test_plus::detail::reporter::write_console and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by operator=.

comment_prefix()​

const char * micro_os_plus::micro_test_plus::detail::reporter_tap::comment_prefix (void)
noexcept virtual

Returns the TAP comment prefix string "# ".

Parameters

None.

Returns

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

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

Declaration at line 298 of file reporter-tap.h, definition at line 890 of file reporter-tap.cpp.

890 reporter_tap::comment_prefix (void) const noexcept
891 {
892 return "# ";
893 }

Referenced by operator= and write_quiet_failures.

end_line()​

void micro_os_plus::micro_test_plus::detail::reporter::end_line (void)

Appends a line ending to the internal output buffer.

Nothing is written to the console or to the output file; the buffer is written by the concrete reporters, at the end of each test case or suite.

Parameters

None.

Returns

Nothing.

This member function appends a newline character to the internal output buffer of the reporter. The buffer itself is written later, by the concrete reporters, at the end of each test case or suite, which then also flush the streams.

Declaration at line 437 of file reporter.h, definition at line 232 of file reporter.cpp.

233 {
234 buffer_.append ("\n");
235 }

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

Referenced by micro_os_plus::micro_test_plus::detail::endl and micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner.

end_session()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::end_session (const runner & runner)
virtual

Marks the end of a test session.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

Emits the TAP plan line (1..N, where N is the total number of test suites) followed by a comment line summarising passed checks, failed checks, executed test cases, suite count, and elapsed time. The numbers of test cases and of suites skipped by the filter follow the respective counts, only when not zero. Both lines are written to the output file when one is open, and, unless verbosity is silent, to stdout. With quiet verbosity, the plan matches the ok/not ok lines of the suites displayed by end_suite() and skip_suite(), so that the console output is a complete TAP document, which node-tap and the other TAP consumers read as failed when a suite failed; no empty line precedes it.

Declaration at line 169 of file reporter-tap.h, definition at line 470 of file reporter-tap.cpp.

471 {
472#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
473 trace::printf ("%s\n", __PRETTY_FUNCTION__);
474#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
475
476 char message_summary[32];
477 snprintf (message_summary, sizeof (message_summary),
480
481 char message_totals[totals_size_];
482 format_session_totals (runner, message_totals);
483
484 char message_time[elapsed_time_size_];
486
487 const bool to_console = route (record_kind::total).console;
488
490 {
491 write_console ("\n");
492 }
493
494 write_line (to_console, "%s\n# { total: %s%s }\n", message_summary,
495 message_totals, message_time);
496
498
500 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::reporter::announce_output_file, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::elapsed_time_size_, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::reporter::format_elapsed_time, micro_os_plus::micro_test_plus::detail::reporter::format_session_totals, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::runner::stopwatch_, micro_os_plus::micro_test_plus::detail::suite_result, micro_os_plus::micro_test_plus::detail::total, micro_os_plus::micro_test_plus::runner::total_suites_count, micro_os_plus::micro_test_plus::detail::reporter::totals_size_, micro_os_plus::micro_test_plus::detail::reporter::write_console and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by operator=.

end_suite()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite (const suite & suite)
virtual

Marks the end of a test suite.

Parameters
suite

Reference to the test suite.

Returns

Nothing.

Emits the TAP plan line for the suite's test cases, and for the failure of the suite body, if any (see fail_suite()), followed by an ok/not ok result line that includes the suite index, name, pass/fail status, check counts, test case count, and elapsed time; the name is escaped (see tap_text()). Any output accumulated in buffer_ is written to the output file and, with normal or verbose verbosity, when verbosity is verbose or the suite failed, to stdout as well; the plan and result lines are written to stdout with normal or verbose verbosity. With quiet verbosity, only the result line is written to stdout, without the plan and without an empty line, so that the session plan written by end_session() counts the displayed lines; the failure of the suite body, if any, precedes it, as comments (see write_quiet_failures()). The buffer is cleared on exit.

Declaration at line 189 of file reporter-tap.h, definition at line 559 of file reporter-tap.cpp.

560 {
561#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
562 trace::printf (
568 __PRETTY_FUNCTION__, suite.name (), suite.totals ().passed_checks (),
571#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
572
573 std::string indent (indent_size_, ' ');
574
575 // The name is not included, since its length is not bounded; it is
576 // passed to each write.
577 const bool passed = suite.totals ().passed ();
578 const char* result = passed ? "ok" : "not ok";
579 const char* status = passed ? "passed" : "FAILED";
580
581 char message_totals[totals_size_];
582 format_suite_totals (suite, message_totals);
583
584 char message_time[elapsed_time_size_];
585 format_elapsed_time (suite.stopwatch_, message_time);
586
587 const tap_name name{ suite.name (), true };
588
590
591 const bool to_console = route (record_kind::suite_result).console;
592
593 // At this point, the buffer may contain output from the test case, which
594 // should be displayed.
595 if (to_console)
596 {
598 {
599 write_console ("\n");
600 }
601
602 // With verbosity, the full TAP output accumulated in the buffer;
603 // for a failed suite, as it may contain useful information about
604 // the failure.
606 }
607 else
608 {
610 }
611
612 // The plan counts the test cases and the failure of the suite body,
613 // if any, which is numbered after them.
614 write_line (to_console,
617 " - %s # { %s, %s%s }\n",
618 indent.c_str (), suite.test_point_number_, result,
619 suite.own_index_, name.c_str (), status, message_totals,
620 message_time);
621
622 if (!to_console && route (record_kind::total).console)
623 {
624 // Quiet: only the test point of the suite, counted by the session
625 // plan.
627 " - %s # { %s, %s%s }\n",
628 result, suite.own_index_, name.c_str (), status,
629 message_totals, message_time);
630 }
631
633
634 clear_buffer ();
635
636 add_empty_line_ = true;
637
638 current_suite_ = nullptr;
639 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::runnable_base::child_test_cases_count_, micro_os_plus::micro_test_plus::detail::reporter::clear_buffer, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::console_lines, micro_os_plus::micro_test_plus::detail::reporter::current_suite_, micro_os_plus::micro_test_plus::detail::reporter::elapsed_time_size_, micro_os_plus::micro_test_plus::counters::executed_checks, micro_os_plus::micro_test_plus::counters::executed_test_cases, micro_os_plus::micro_test_plus::counters::failed_checks, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::reporter::format_elapsed_time, micro_os_plus::micro_test_plus::detail::reporter::format_suite_totals, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::indent_size_, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::detail::runnable_base::own_index_, micro_os_plus::micro_test_plus::counters::passed, micro_os_plus::micro_test_plus::counters::passed_checks, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::suite::stopwatch_, micro_os_plus::micro_test_plus::detail::suite_result, micro_os_plus::micro_test_plus::detail::runnable_base::test_point_number_, micro_os_plus::micro_test_plus::detail::total, micro_os_plus::micro_test_plus::detail::runnable_base::totals, micro_os_plus::micro_test_plus::detail::reporter::totals_size_, micro_os_plus::micro_test_plus::detail::reporter::write_buffer_to_file, micro_os_plus::micro_test_plus::detail::reporter::write_console, micro_os_plus::micro_test_plus::detail::reporter::write_console_text, micro_os_plus::micro_test_plus::detail::reporter::write_line and write_quiet_failures.

Referenced by operator=.

end_test_case()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case (const test_case & test_case)
virtual

Marks the end of a test case.

Parameters
test_case

Reference to the test case.

Returns

Nothing.

Emits the TAP plan line for the test case's checks and nested test cases, followed by an ok/not ok result line that includes the test case index, escaped name, pass/fail status, and check counts. As in node-tap, the result is not ok when a check or a nested test case failed; the number of failed nested test cases is added when it is not zero. Any output accumulated in buffer_ and the two lines are always written to the output file.

With normal verbosity, a passed test case that has nothing displayed under it (no nested test case, and no committed checks) is displayed as a single test point, the ok line, without the # Subtest: heading, the plan, and the checks; this is a valid test point, and it keeps the console output short. Otherwise, with normal or verbose verbosity, the test case is displayed as a complete block, with the headings of the outer test cases first, if not displayed yet, all the buffered checks, the plan, and the result line, so that the plan matches the displayed test points, with the test point numbers unchanged. With quiet verbosity, only the failed checks are displayed, as comments (see write_quiet_failures()).

The buffer is cleared on exit.

Declaration at line 238 of file reporter-tap.h, definition at line 779 of file reporter-tap.cpp.

780 {
781#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
782 trace::printf ("%s '%s' i%" MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
788 __PRETTY_FUNCTION__, test_case.name (),
795#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
796
797 std::string indent (indent_size_ * test_case.nesting_depth (), ' ');
798 std::string indent2 (indent_size_ * (test_case.nesting_depth () + 1), ' ');
799
800 // The nested test cases skipped by the filter keep their index, and are
801 // counted in the plan.
802 size_t plan_count = test_case.totals ().executed_checks ()
805
806 // The name and the indentation are not included, since their lengths
807 // are not bounded; they are passed to each write.
808 const bool passed = test_case.totals ().passed ();
809 const char* result = passed ? "ok" : "not ok";
810 const char* status = passed ? "passed" : "FAILED";
811
812 char message_totals[totals_size_];
813 format_test_case_totals (test_case, message_totals);
814
815 const tap_name name{ test_case.name (), true };
816
818
819 const bool to_console = route (record_kind::test_case_result).console;
820
821 // A passed test case without anything displayed under it is a single
822 // test point.
823 const bool is_single_point
824 = to_console && passed
825 && (open_test_cases_.empty ()
826 || !open_test_cases_.back ().name_displayed);
827
828 if (to_console)
829 {
830 if (is_single_point)
831 {
832 // The headings of the outer test cases, to keep the test point
833 // in their block.
835 }
836 else
837 {
838 // The heading of this test case too, if not displayed yet.
840
842 {
843 write_console ("\n");
844 }
845
846 // The full TAP output accumulated in the buffer, as the
847 // plan counts it.
849
851 "\n",
852 indent2.c_str (), plan_count);
853 }
854 }
855 else
856 {
858 }
859
861 indent2.c_str (), plan_count);
862
863 write_line (to_console,
865 " - %s # { %s, %s }\n",
866 indent.c_str (), result, test_case.own_index_, name.c_str (),
867 status, message_totals);
868
870
871 clear_buffer ();
872
873 add_empty_line_ = true;
874
875 if (!open_test_cases_.empty ())
876 {
877 open_test_cases_.pop_back ();
878 }
879 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::runnable_base::child_test_cases_count_, micro_os_plus::micro_test_plus::detail::reporter::clear_buffer, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::console_lines, micro_os_plus::micro_test_plus::detail::reporter::display_open_test_cases, micro_os_plus::micro_test_plus::counters::executed_checks, micro_os_plus::micro_test_plus::counters::executed_test_cases, micro_os_plus::micro_test_plus::counters::failed_checks, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::reporter::format_test_case_totals, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::indent_size_, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::test_case::nesting_depth, micro_os_plus::micro_test_plus::detail::reporter::open_test_cases_, micro_os_plus::micro_test_plus::detail::runnable_base::own_index_, micro_os_plus::micro_test_plus::counters::passed, micro_os_plus::micro_test_plus::counters::passed_checks, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::counters::skipped_test_cases, micro_os_plus::micro_test_plus::detail::test_case_result, micro_os_plus::micro_test_plus::detail::runnable_base::totals, micro_os_plus::micro_test_plus::detail::reporter::totals_size_, micro_os_plus::micro_test_plus::detail::reporter::write_buffer_to_file, micro_os_plus::micro_test_plus::detail::reporter::write_console, micro_os_plus::micro_test_plus::detail::reporter::write_console_text, micro_os_plus::micro_test_plus::detail::reporter::write_file, micro_os_plus::micro_test_plus::detail::reporter::write_line and write_quiet_failures.

Referenced by operator=.

error_prefix()​

const char * micro_os_plus::micro_test_plus::detail::reporter_tap::error_prefix (void)
noexcept virtual

Returns the TAP bail-out prefix string "Bail out! ".

Parameters

None.

Returns

The string "Bail out! ", used to start the lines that report an error and stop the session.

Returns "Bail out! ", the TAP line that tells the consumer that the session cannot continue.

Declaration at line 309 of file reporter-tap.h, definition at line 901 of file reporter-tap.cpp.

901 reporter_tap::error_prefix (void) const noexcept
902 {
903 return "Bail out! ";
904 }

Referenced by operator=.

fail()​

void micro_os_plus::micro_test_plus::detail::reporter::fail (const failure_info & failure, const std::string & expression, const test_case & test_case)

Reports a failed condition.

Parameters
failure

The failure details: the kind of the check, the message to display, whether the expression text is displayed, and the source location of the failure.

expression

The string representation of the expression.

test_case

The test case that owns this check.

Returns

Nothing.

Outputs a fail prefix (which includes the message and the source location), followed, when failure.has_expression is true, by the pre-formatted expression string, and a fail suffix.

Declaration at line 546 of file reporter.h, definition at line 771 of file reporter.cpp.

771 reporter::fail (const failure_info& failure, const std::string& expression,
772 const test_case& test_case)
773 {
774 const size_t begin = buffer_.size ();
775
777 failure.location, test_case);
778
779 if (failure.has_expression)
780 {
781 *this << expression;
782 }
783
784 output_fail_suffix (failure.location, failure.kind, test_case);
785
786 mark_failure (begin);
787 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, micro_os_plus::micro_test_plus::detail::failure_info::has_expression, micro_os_plus::micro_test_plus::detail::failure_info::kind, micro_os_plus::micro_test_plus::detail::failure_info::location, micro_os_plus::micro_test_plus::detail::reporter::mark_failure, micro_os_plus::micro_test_plus::detail::failure_info::message, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::detail::reporter::output_fail_prefix and micro_os_plus::micro_test_plus::detail::reporter::output_fail_suffix.

Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result, micro_os_plus::micro_test_plus::test_case::fail_unexpected_exception and micro_os_plus::micro_test_plus::detail::reporter::pass_without_text.

fail_suite()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::fail_suite (const std::string & message, const suite & suite)
virtual

Reports a failure of a test suite outside its test cases.

Adds a not ok <n> - <message> test point, at the indentation of the test cases, to the output buffer, which end_suite() displays.

Parameters
message

The message to display.

suite

Reference to the test suite.

Returns

Nothing.

Adds a not ok <n> - <message> line, with the message escaped (see tap_text()), to the output buffer, indented as the test cases of the suite, where <n> is the current test point number of the suite, which follows the test cases already run, and is therefore counted in the plan of the suite. Since there is no source location, no YAML diagnostics block follows. The line is displayed by end_suite(), with the other buffered output of the failed suite.

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

691 reporter_tap::fail_suite (const std::string& message, const suite& suite)
692 {
693#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
694 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
695#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
696
697 const size_t begin = buffer_.size ();
698
699 *this << indent (1) << "not ok " << suite.test_point_number_ << " - "
700 << tap_text (message, true) << endl;
701
702 mark_failure (begin);
703 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, micro_os_plus::micro_test_plus::detail::endl, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::mark_failure, micro_os_plus::micro_test_plus::detail::runnable_base::name and micro_os_plus::micro_test_plus::detail::runnable_base::test_point_number_.

Referenced by operator=.

flush_streams()​

void micro_os_plus::micro_test_plus::detail::reporter::flush_streams (void)

Flushes the standard output stream and the output file.

Only the C streams are flushed; the internal output buffer is not written.

Parameters

None.

Returns

Nothing.

This member function flushes the stdout stream and, if open, the output file, so that everything already written to them becomes visible. It does not write the contents of the internal buffer.

Declaration at line 452 of file reporter.h, definition at line 622 of file reporter.cpp.

623 {
624 fflush (stdout);
625 if (output_file_ != nullptr)
626 {
627 fflush (output_file_);
628 }
629 }

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

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter::announce_output_file, micro_os_plus::micro_test_plus::detail::reporter_human::begin_session, begin_session, micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite, begin_suite, micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case, begin_test_case, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case, end_test_case, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner, micro_os_plus::micro_test_plus::detail::reporter_human::skip_suite, skip_suite, micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case and skip_test_case.

has_output_file_error()​

bool micro_os_plus::micro_test_plus::detail::reporter::has_output_file_error (void)
nodiscard noexcept

Returns whether the output file could not be opened.

Checked by runner::initialise(), which reports it on the console, as the option errors are, and declines the session, so that no test is run and runner::run_suites() returns 2.

Parameters

None.

Return Values
true

The output file was requested but could not be opened.

false

No output file was requested, or it was opened.

Returns the flag set by the constructor when fopen() failed.

Declaration at line 469 of file reporter.h, definition at line 636 of file reporter.cpp.

636 reporter::has_output_file_error (void) const noexcept
637 {
639 }

Reference micro_os_plus::micro_test_plus::detail::reporter::has_output_file_error_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner.

pass()​

void micro_os_plus::micro_test_plus::detail::reporter::pass (const std::string & message, const std::string & expression, const test_case & test_case)

Reports a passed condition.

Parameters
message

The message to display.

expression

The string representation of the expression.

test_case

The test case that owns this check.

Returns

Nothing.

Outputs a pass prefix, followed by either the provided message or, if the message is empty, the evaluated expression string itself. A pass suffix is then appended to complete the output.

Declaration at line 511 of file reporter.h, definition at line 751 of file reporter.cpp.

751 reporter::pass (const std::string& message, const std::string& expression,
752 const test_case& test_case)
753 {
755
756 if (message.empty ())
757 {
758 *this << expression;
759 }
760
762 }

References micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::detail::reporter::output_pass_prefix and micro_os_plus::micro_test_plus::detail::reporter::output_pass_suffix.

Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result and micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner.

pass_without_text()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::pass_without_text (const test_case & test_case)
virtual

Records a passed check whose text is not written.

With the normal verbosity, appends a bare ok <n> line, without a description, to the buffered results of the test case, so that, when the test case is displayed as a block, the plan matches the test points.

Parameters
test_case

The test case that owns this check.

Returns

Nothing.

The line is appended only with the normal verbosity, the only level at which a test case may be displayed as a block while its passed checks are not formatted: with the verbose verbosity, or with an output file, the passed checks are written in full, by pass(), and with the quiet and silent verbosity levels, only the failed checks are displayed. The line, indented one level deeper than the test case, carries the test point number of the check; the buffer is displayed only when the test case is displayed as a block, and discarded when it is a single test point.

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

920 {
922 {
923 return;
924 }
925
926 *this << indent (test_case.nesting_depth () + 1) << "ok "
928 }

References micro_os_plus::micro_test_plus::detail::endl, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::test_case::nesting_depth, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::detail::runnable_base::test_point_number_ and micro_os_plus::micro_test_plus::detail::reporter::verbosity_.

Referenced by operator=.

skip_suite()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::skip_suite (const suite & suite)
virtual

Reports a test suite skipped by the filter.

Displays an ok <index> - <name> # SKIP filtered line, instead of the suite body and results.

Parameters
suite

Reference to the skipped test suite.

Returns

Nothing.

Emits an ok <index> - <name> # SKIP filtered line, with the name escaped (see tap_text()), without a test case block, so that the suite keeps its place in the TAP plan of the session. The line is written to the output file when one is open. Unless verbosity is silent, it is also written to stdout; under normal or verbose verbosity, it is preceded by a blank line when add_empty_line_ is set. With quiet verbosity, it is written as the result lines of end_suite(), which the session plan counts.

Declaration at line 203 of file reporter-tap.h, definition at line 653 of file reporter-tap.cpp.

654 {
655#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
656 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
657#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
658
659 const tap_name name{ suite.name (), true };
660
661 // The skipped suites are counted by the session plan, so they are
662 // displayed with quiet verbosity too.
663 const bool to_console = route (record_kind::total).console;
664
666 {
667 write_console ("\n");
668 }
669
670 write_line (to_console,
672 " - %s # SKIP filtered\n",
673 suite.own_index_, name.c_str ());
674
676
677 add_empty_line_ = true;
678 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::detail::runnable_base::own_index_, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::skipped, micro_os_plus::micro_test_plus::detail::total, micro_os_plus::micro_test_plus::detail::reporter::write_console and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by operator=.

skip_test_case()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::skip_test_case (const test_case & test_case)
virtual

Reports a test case skipped by the filter.

Displays an ok <index> - <name> # SKIP filtered line, indented by its nesting depth.

Parameters
test_case

Reference to the skipped test case.

Returns

Nothing.

As in begin_test_case(), for a nested test case, the results of the checks already performed by the outer test case, if any, are written first (see commit_outer_results()), so that the output follows the execution order.

An ok <index> - <name> # SKIP filtered line, with the name escaped, indented according to the nesting depth, without a test case block, is then written to the output file and, under normal or verbose verbosity, to stdout, after the headings of the outer test cases, if not displayed yet, and, under verbose verbosity, preceded by a blank line when add_empty_line_ is set.

Declaration at line 252 of file reporter-tap.h, definition at line 1100 of file reporter-tap.cpp.

1101 {
1102#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
1103 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, test_case.name ());
1104#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
1105
1107
1108 std::string indent (indent_size_ * test_case.nesting_depth (), ' ');
1109
1110 const tap_name name{ test_case.name (), true };
1111
1112 const bool to_console = route (record_kind::skipped).console;
1113
1114 if (to_console)
1115 {
1117
1119 {
1120 write_console ("\n");
1121 }
1122 }
1123
1124 write_line (to_console,
1126 " - %s # SKIP filtered\n",
1127 indent.c_str (), test_case.own_index_, name.c_str ());
1128
1129 flush_streams ();
1130
1131 add_empty_line_ = true;
1132 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::reporter::commit_outer_results, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::detail::reporter::display_open_test_cases, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::indent_size_, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::test_case::nesting_depth, micro_os_plus::micro_test_plus::detail::runnable_base::own_index_, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::skipped, micro_os_plus::micro_test_plus::detail::test_case_heading, micro_os_plus::micro_test_plus::detail::reporter::write_console and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by operator=.

writes_passed_checks()​

bool micro_os_plus::micro_test_plus::detail::reporter::writes_passed_checks (void)
nodiscard noexcept

Returns whether the passed checks are written anywhere.

Called by test_case::expect() and test_case::require(), so that a passed check whose line is never written does not format its expression, its messages, or its line. The answer depends only on the verbosity and on the output file, which do not change during the session. A failed check is always formatted.

Parameters

None.

Return Values
true

The lines of the passed checks reach the console or the output file, at least in some cases.

false

The descriptions and the expressions of the passed checks are never written; the TAP reporter writes only their test points (see pass_without_text()).

The passed checks are written to the output file, when it is open, whatever the verbosity; to the console only with the verbose verbosity level. With the normal verbosity, only the failed checks (with the names of the open test cases) are displayed, so the passed checks are counted, without formatting them; the TAP reporter records their test points (see pass_without_text()).

Declaration at line 796 of file reporter.h, definition at line 320 of file reporter.cpp.

320 reporter::writes_passed_checks (void) const noexcept
321 {
322 return output_file_ != nullptr || verbosity_ == verbosity::verbose;
323 }

References micro_os_plus::micro_test_plus::detail::reporter::output_file_, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::detail::reporter::verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter::comment_prefix and micro_os_plus::micro_test_plus::test_case::report_misdirected.

Protected Member Functions​

announce_output_file()​

void micro_os_plus::micro_test_plus::detail::reporter::announce_output_file (void)
protected

Tells the console where the output file was written.

Called by the derived classes at the end of the session, after the totals, or after the abort report. It writes a line that names the output file, prefixed with comment_prefix() so that it is valid in the output format, and flushes the streams, so that the file is complete when the line is displayed. Nothing is written if there is no output file, or with the silent verbosity.

Parameters

None.

Returns

Nothing.

The file is flushed before the line is written, so that the line is displayed only when the content of the file is complete. The file itself is closed by the destructor.

Declaration at line 1014 of file reporter.h, definition at line 244 of file reporter.cpp.

245 {
246 if (output_file_ == nullptr)
247 {
248 return;
249 }
250
252
254 {
255 write_console ("%sTest output written to '%s'.\n", comment_prefix (),
256 output_file_path_.c_str ());
257 fflush (stdout);
258 }
259 }

References micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::reporter::output_file_, micro_os_plus::micro_test_plus::detail::reporter::output_file_path_, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::detail::reporter::verbosity_ and micro_os_plus::micro_test_plus::detail::reporter::write_console.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::end_session and end_session.

clear_buffer()​

commit_outer_results()​

void micro_os_plus::micro_test_plus::detail::reporter::commit_outer_results (void)
protected

Writes the results of the outer test case, if any, before a nested test case begins or is skipped.

Called by begin_test_case() and skip_test_case() of the concrete reporters, so that the output follows the execution order.

Parameters

None.

Returns

Nothing.

For a nested test case, the outer test case may have performed checks before it; their results are written first, by commit_buffer(). For a top-level test case, the buffer is expected to be empty, since the checks are performed only by the test cases, and each one writes its results when it ends; should it not be, its content is written in the same way, rather than lost or attributed to the next test case, and the run continues.

Declaration at line 1181 of file reporter.h, definition at line 1013 of file reporter.cpp.

1014 {
1015 if (!buffer_.empty ())
1016 {
1017 commit_buffer ();
1018 }
1019 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_ and micro_os_plus::micro_test_plus::detail::reporter::commit_buffer.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case, begin_test_case, micro_os_plus::micro_test_plus::detail::reporter::commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case and skip_test_case.

console_lines()​

std::string_view micro_os_plus::micro_test_plus::detail::reporter::console_lines (bool failed)
nodiscard noexcept protected

Returns the buffered lines that the console displays when a test case or a suite ends, or when its results are committed.

With the verbose verbosity, all the buffered lines; with the normal verbosity, all the buffered lines of a failed test case or suite, otherwise none; with the quiet verbosity, only the lines of the failed checks; with the silent verbosity, none.

Parameters
failed

Whether the test case or the suite failed, or, when committing the results of an outer test case, whether the buffer contains a failed check.

Returns

A view of buffer_ or of failures_, valid until they are modified.

The quiet verbosity displays the failed checks, and the buffer may also contain the passed checks, for the output file; the lines of the failed checks are therefore kept separately, in failures_.

Declaration at line 866 of file reporter.h, definition at line 332 of file reporter.cpp.

332 reporter::console_lines (bool failed) const noexcept
333 {
335 {
336 return buffer_;
337 }
339 {
340 return failed ? std::string_view{ buffer_ } : std::string_view{};
341 }
343 {
344 return failures_;
345 }
346 return {};
347 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, micro_os_plus::micro_test_plus::detail::reporter::failures_, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::detail::reporter::verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case and end_test_case.

display_open_test_cases()​

void micro_os_plus::micro_test_plus::detail::reporter::display_open_test_cases (bool include_last)
protected

Displays the headings not yet displayed, of the open test cases.

Walks open_test_cases_ from the outermost test case and, for each one whose heading was not displayed yet, calls display_open_heading() and marks it as displayed. A failure in a nested test case also fails the outer ones, so their headings are displayed first, to show where the result is.

Parameters
include_last

Whether to display the heading of the innermost open test case too; false for the result of a passed test case, which is not preceded by its own heading.

Returns

Nothing.

The innermost open test case is skipped unless include_last is true.

Declaration at line 1372 of file reporter.h, definition at line 382 of file reporter.cpp.

383 {
384 const size_t count = include_last || open_test_cases_.empty ()
385 ? open_test_cases_.size ()
386 : open_test_cases_.size () - 1;
387 bool is_first = true;
388 for (size_t i = 0; i < count; ++i)
389 {
391 if (open.name_displayed)
392 {
393 continue;
394 }
395
396 display_open_heading (open, is_first);
397 is_first = false;
398
399 open.name_displayed = true;
400 }
401 }

References micro_os_plus::micro_test_plus::detail::reporter::display_open_heading, micro_os_plus::micro_test_plus::detail::reporter::open_test_case::name_displayed and micro_os_plus::micro_test_plus::detail::reporter::open_test_cases_.

Referenced by abort_session, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::display_open_names, end_test_case and skip_test_case.

enter_suite()​

void micro_os_plus::micro_test_plus::detail::reporter::enter_suite (const suite & suite, bool displayed)
protected

Notes the suite that begins, for the headings displayed later.

Called by begin_suite() of the concrete reporters, with the information whether the heading of the suite was displayed.

Parameters
suite

The suite that begins.

displayed

Whether the heading was written to the console.

Returns

Nothing.

Records the suite and whether its heading was displayed; the quiet verbosity displays it later, if the suite has a failure.

Declaration at line 913 of file reporter.h, definition at line 409 of file reporter.cpp.

409 reporter::enter_suite (const suite& suite, bool displayed)
410 {
412 suite_displayed_ = displayed;
413 }

References micro_os_plus::micro_test_plus::detail::reporter::current_suite_ and micro_os_plus::micro_test_plus::detail::reporter::suite_displayed_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite, begin_suite and micro_os_plus::micro_test_plus::detail::reporter::comment_prefix.

mark_failure()​

void micro_os_plus::micro_test_plus::detail::reporter::mark_failure (size_t begin)
protected

Records that the lines appended to the buffer from a given position are a failure.

Sets buffer_has_failures_ and, with the quiet verbosity, which displays only the failures, copies the lines to failures_.

Parameters
begin

The position in buffer_ where the lines of the failure begin.

Returns

Nothing.

Only the quiet verbosity needs the copy, since the other levels display the buffer as a whole, or nothing.

Declaration at line 897 of file reporter.h, definition at line 367 of file reporter.cpp.

368 {
370 {
371 failures_.append (buffer_, begin, std::string::npos);
372 }
374 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, micro_os_plus::micro_test_plus::detail::reporter::buffer_has_failures_, micro_os_plus::micro_test_plus::detail::reporter::failures_, micro_os_plus::micro_test_plus::quiet and micro_os_plus::micro_test_plus::detail::reporter::verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter::fail, micro_os_plus::micro_test_plus::detail::reporter_human::fail_suite and fail_suite.

route()​

output_route micro_os_plus::micro_test_plus::detail::reporter::route (record_kind kind)
nodiscard noexcept protected

Tells where a kind of record is written.

The single place of the output policy. The output file receives all the records, whatever the verbosity, so that its content does not depend on the console. The console receives, with each verbosity level:

  • silent: nothing;
  • quiet: the failed checks, the failures of the suites, the totals, and the report of an aborted execution;
  • normal: in addition, the informational lines, the headings and results of the suites, the results of the test cases, and the skipped suites and test cases;
  • verbose: in addition, the headings of the test cases and the lines of the passed checks.

The headings of the test cases that contain a failure are also displayed with the normal verbosity (see console_lines()), but the passed checks are not; they are counted, without being formatted (see writes_passed_checks()), and the TAP reporter records their test points (see pass_without_text()). The concrete reporters adapt the quiet and normal levels to their format.

Parameters
kind

The kind of record.

Returns

The destinations of the record.

The file receives all the records, when it is open, so that its content does not depend on the verbosity (a file of a silent run is as complete as that of a verbose one). The console follows the verbosity levels, as documented in the declaration.

Declaration at line 847 of file reporter.h, definition at line 280 of file reporter.cpp.

280 reporter::route (record_kind kind) const noexcept
281 {
282 bool console;
284 || kind == record_kind::abort)
285 {
286 console = (verbosity_ != verbosity::silent);
287 }
288 else if (kind == record_kind::test_case_heading
290 {
291 console = (verbosity_ == verbosity::verbose);
292 }
293#if defined(MICRO_OS_PLUS_STARTUP_ENABLED) \
294 && defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
295 else if (kind == record_kind::info)
296 {
297 // The startup code already displays this information.
298 console = false;
299 }
300#endif // defined(MICRO_OS_PLUS_STARTUP_ENABLED) && ...
301 else
302 {
303 console = (verbosity_ == verbosity::normal
305 }
306
307 return { console, output_file_ != nullptr };
308 }

References micro_os_plus::micro_test_plus::detail::abort, micro_os_plus::micro_test_plus::detail::failed_check, micro_os_plus::micro_test_plus::detail::info, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::detail::reporter::output_file_, micro_os_plus::micro_test_plus::detail::passed_check, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::detail::test_case_heading, micro_os_plus::micro_test_plus::detail::total, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::detail::reporter::verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter_human::begin_session, begin_session, micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite, begin_suite, micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case, begin_test_case, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case, end_test_case, micro_os_plus::micro_test_plus::detail::reporter_human::skip_suite, skip_suite, micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case, skip_test_case and micro_os_plus::micro_test_plus::detail::reporter::write_info.

write_buffer_to_file()​

void micro_os_plus::micro_test_plus::detail::reporter::write_buffer_to_file (void)
protected

Writes the current buffered content to the output file.

The buffer is written without appending a line ending, and is not cleared. ANSI colour sequences are removed, so the file receives plain text even when the console output is coloured. If no output file is open, the call has no effect.

Parameters

None.

Returns

Nothing.

Writes the contents of buffer_ to output_file_ without appending a newline. If output_file_ is null, the call is a no-op.

The buffer may contain ANSI colour sequences, added when the console is a terminal, which must not reach the file; they are removed by write_without_colours().

Declaration at line 816 of file reporter.h, definition at line 425 of file reporter.cpp.

426 {
427 if (output_file_ == nullptr)
428 {
429 return;
430 }
431
432 // Pass only the string, do not add an `\n` here.
433 write_without_colours (output_file_, buffer_);
434 }

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

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case and end_test_case.

write_console()​

void micro_os_plus::micro_test_plus::detail::reporter::write_console (const char * format, ...)
protected

Writes formatted text to the console.

All reporter console output is routed through this function, so that it reaches the standard output stream via a single path, shared with the output of the user printf() calls. Using one stream-based path keeps the reporter and user output in the same buffer, preserving their relative order.

Parameters
format

A printf()-style format string.

...

The arguments referred to by the format string.

Returns

Nothing.

The arguments are forwarded to vfprintf() on stdout. The stream is explicit, so the compiler does not rewrite the call into puts() or putchar(), and all console output shares the same FILE-based path.

Declaration at line 931 of file reporter.h, definition at line 444 of file reporter.cpp.

444 reporter::write_console (const char* format, ...)
445 {
446 va_list args;
447 va_start (args, format);
448 vfprintf (stdout, format, args);
449 va_end (args);
450 }

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter::announce_output_file, micro_os_plus::micro_test_plus::detail::reporter_human::begin_session, begin_session, micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite, begin_suite, micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case, begin_test_case, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::display_open_heading, display_open_heading, micro_os_plus::micro_test_plus::detail::reporter_human::display_open_names, micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case, end_test_case, micro_os_plus::micro_test_plus::detail::reporter_human::skip_suite, skip_suite, micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case, skip_test_case and write_quiet_failures.

write_console_text()​

void micro_os_plus::micro_test_plus::detail::reporter::write_console_text (std::string_view text)
protected

Writes a text to the console, unchanged.

The text is written with its size, not as a C string, so that a zero character in a message does not end the output. No line ending is appended.

Parameters
text

The text to write.

Returns

Nothing.

The text is written with its size, not as a C string, so that a zero character in a message does not end the output.

Declaration at line 881 of file reporter.h, definition at line 355 of file reporter.cpp.

355 reporter::write_console_text (std::string_view text)
356 {
357 // Pass only the text, do not add an `\n` here.
358 fwrite (text.data (), 1, text.size (), stdout);
359 }

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer, commit_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case, end_test_case and write_quiet_failures.

write_file()​

void micro_os_plus::micro_test_plus::detail::reporter::write_file (const char * format, ...)
protected

Writes formatted text to the output file.

If no output file is open, the call has no effect, so callers do not need to check output_file_ themselves.

Parameters
format

A printf()-style format string.

...

The arguments referred to by the format string.

Returns

Nothing.

The arguments are forwarded to vfprintf() on output_file_. If output_file_ is null, the arguments are ignored.

Declaration at line 950 of file reporter.h, definition at line 458 of file reporter.cpp.

458 reporter::write_file (const char* format, ...)
459 {
460 if (output_file_ == nullptr)
461 {
462 return;
463 }
464
465 va_list args;
466 va_start (args, format);
467 vfprintf (output_file_, format, args);
468 va_end (args);
469 }

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

Referenced by micro_os_plus::micro_test_plus::detail::reporter::comment_prefix and end_test_case.

write_info()​

void micro_os_plus::micro_test_plus::detail::reporter::write_info (const std::vector< std::string > & arguments)
protected

Writes the informational (non-result) lines to the console and to the output file.

Parameters
arguments

The command line of the session, listed when not empty; passed by begin_session() from the runner options, so that the reporter does not keep a copy.

Returns

Nothing.

Constructs and emits two informational lines, each prefixed by comment_prefix(): the first lists the program name (without the path) 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 when the verbosity is normal or verbose (see route()), except when both MICRO_OS_PLUS_STARTUP_ENABLED and MICRO_OS_PLUS_DIAG_TRACE_ENABLED are defined, since the startup code already displays this information.

Declaration at line 994 of file reporter.h, definition at line 547 of file reporter.cpp.

547 reporter::write_info (const std::vector<std::string>& arguments)
548 {
549 const bool to_console = route (record_kind::info).console;
550
551 if (!arguments.empty ())
552 {
553 std::string line;
554 line.reserve (256);
555 line.append (comment_prefix ());
556 line.append ("Running: ");
557
558 // Append only the file name part of argv[0].
559 line.append (utility::extract_file_name (arguments[0].c_str ()));
560
561 for (size_t i = 1; i < arguments.size (); ++i)
562 {
563 line.append (" ");
564 line.append (arguments[i]);
565 }
566 line.append ("\n");
567
568 write_line (to_console, "%s", line.c_str ());
569 }
570
571 {
572 // Build the "Built with ..." line, including the compiler version
573 // (via __VERSION__); the same line goes to the file and to stdout.
574 std::string line;
575 line.reserve (256);
576 line.append (comment_prefix ());
577 line.append ("Built with ");
578#if defined(__clang__)
579 line.append ("clang " __VERSION__);
580#elif defined(__GNUC__)
581 line.append ("GCC " __VERSION__);
582#elif defined(_MSC_VER)
583 line.append ("MSVC");
584 char msvc_ver[16];
585 snprintf (msvc_ver, sizeof (msvc_ver), " - %d", _MSC_VER);
586 line.append (msvc_ver);
587#else
588 line.append ("an unknown compiler");
589#endif // defined(__clang__)
590#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
591 || defined(_WIN32))
592 // This is relevant only on bare-metal.
593#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
594 line.append (", with FP");
595#else
596 line.append (", no FP");
597#endif // defined(__ARM_PCS_VFP) || defined(__ARM_FP)
598#endif // bare-metal only
599#if defined(__cpp_exceptions)
600 line.append (", with exceptions");
601#else
602 line.append (", no exceptions");
603#endif // defined(__cpp_exceptions)
604#if defined(MICRO_OS_PLUS_DEBUG_ENABLED)
605 line.append (", with MICRO_OS_PLUS_DEBUG_ENABLED");
606#endif // defined(MICRO_OS_PLUS_DEBUG_ENABLED)
607#if defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
608 line.append (", with MICRO_OS_PLUS_DIAG_TRACE_ENABLED");
609#endif // defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
610
611 write_line (to_console, "%s\n", line.c_str ());
612 }
613 }

References micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::output_route::console, micro_os_plus::micro_test_plus::utility::extract_file_name, micro_os_plus::micro_test_plus::detail::info, micro_os_plus::micro_test_plus::detail::reporter::route and micro_os_plus::micro_test_plus::detail::reporter::write_line.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::begin_session, begin_session and micro_os_plus::micro_test_plus::detail::reporter::comment_prefix.

write_line()​

void micro_os_plus::micro_test_plus::detail::reporter::write_line (bool to_console, const char * format, ...)
protected

Writes formatted lines to the output file and, when requested, to the console.

The text is formatted once, and the same text is written to the output file, if open, and, when to_console is true, to stdout. As in write_buffer_to_file(), the ANSI colour sequences are removed from the file copy, so a console line with colours and its plain file line are written by one call. The format normally ends with a line ending; any empty line or buffered output that precedes the console line is written by the caller, before this call.

Parameters
to_console

Whether to write the text to stdout as well.

format

A printf()-style format string.

...

The arguments referred to by the format string.

Returns

Nothing.

The text is formatted with vsnprintf() into a local array, which holds the usual lines without an allocation; a longer text, for example with a long test name, is formatted again, from a copy of the arguments, into a string of the exact length. The array is kept small, since the lines that end the nested test cases are written at the deepest point of the stack. The text is then written with its length to the output file, without the colour sequences (see write_without_colours()), and, when requested, to stdout, unchanged. When there is nowhere to write, or the formatting fails, nothing is written.

Declaration at line 977 of file reporter.h, definition at line 485 of file reporter.cpp.

485 reporter::write_line (bool to_console, const char* format, ...)
486 {
487 if (output_file_ == nullptr && !to_console)
488 {
489 return;
490 }
491
492 va_list args;
493 va_start (args, format);
494 va_list args_copy;
495 va_copy (args_copy, args);
496
497 char local_text[128];
498 const int length
499 = vsnprintf (local_text, sizeof (local_text), format, args);
500 va_end (args);
501
502 if (length < 0)
503 {
504 va_end (args_copy);
505 return;
506 }
507
508 const size_t size = static_cast<size_t> (length);
509 std::string long_text;
510 std::string_view text{ local_text, size };
511 if (size >= sizeof (local_text))
512 {
513 // The terminating null character is written over the one kept by
514 // the string after its content.
515 long_text.resize (size);
516 vsnprintf (long_text.data (), size + 1, format, args_copy);
517 text = long_text;
518 }
519 va_end (args_copy);
520
521 if (output_file_ != nullptr)
522 {
523 write_without_colours (output_file_, text);
524 }
525
526 if (to_console)
527 {
528 fwrite (text.data (), 1, text.size (), stdout);
529 }
530 }

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

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, abort_session, micro_os_plus::micro_test_plus::detail::reporter_human::begin_session, begin_session, micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite, begin_suite, micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case, begin_test_case, micro_os_plus::micro_test_plus::detail::reporter::comment_prefix, micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case, end_test_case, micro_os_plus::micro_test_plus::detail::reporter_human::skip_suite, skip_suite, micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case, skip_test_case and micro_os_plus::micro_test_plus::detail::reporter::write_info.

Private Member Functions​

commit_buffer()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::commit_buffer (void)
virtual

Writes the results buffered for the outer test case before a nested test case begins.

Keeps the TAP stream in execution order, with the checks of the outer test case before the nested test case, as node-tap does.

Parameters

None.

Returns

Nothing.

The buffered ok/not ok lines of the outer test case are always written to the output file and, with normal or verbose verbosity, to stdout, after the headings of the outer test cases, if not displayed yet, and preceded by an empty line when add_empty_line_ is set. They are displayed even if all the checks passed, since the outer test case, which contains a nested test case, is displayed as a block, whose plan counts them. With quiet verbosity, only the failed checks are displayed, as comments. The buffer is then cleared, so that the nested test case starts with an empty buffer, and the remaining lines of the outer test case are written by its end_test_case().

Declaration at line 378 of file reporter-tap.h, definition at line 1228 of file reporter-tap.cpp.

1229 {
1231
1233 {
1235
1236 if (add_empty_line_)
1237 {
1238 write_console ("\n");
1239 add_empty_line_ = false;
1240 }
1241
1243 }
1244 else
1245 {
1247 }
1248
1249 flush_streams ();
1250
1251 clear_buffer ();
1252 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::reporter::clear_buffer, micro_os_plus::micro_test_plus::detail::reporter::console_lines, micro_os_plus::micro_test_plus::detail::reporter::display_open_test_cases, micro_os_plus::micro_test_plus::detail::reporter::flush_streams, micro_os_plus::micro_test_plus::detail::reporter::route, micro_os_plus::micro_test_plus::detail::test_case_result, micro_os_plus::micro_test_plus::detail::reporter::write_buffer_to_file, micro_os_plus::micro_test_plus::detail::reporter::write_console, micro_os_plus::micro_test_plus::detail::reporter::write_console_text and write_quiet_failures.

Referenced by operator=.

display_open_heading()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::display_open_heading (const open_test_case & open, bool is_first)
virtual

Writes the # Subtest: heading of an open test case.

With normal verbosity, a test case is displayed as a single test point, unless it contains a nested test case or a failure; its heading is therefore displayed only when something is displayed under it, outermost first, so that the displayed test points remain the complete content of the block.

Parameters
open

The open test case.

is_first

Not used; every heading is preceded by its own blank line.

Returns

Nothing.

Writes, to stdout, the indented "# Subtest: <name>" line, with the line breaks in the name replaced by spaces, preceded by a blank line when add_empty_line_ is set; the flag is then cleared, so that the content of the block follows its heading.

Declaration at line 397 of file reporter-tap.h, definition at line 1262 of file reporter-tap.cpp.

1263 {
1264 if (add_empty_line_)
1265 {
1266 write_console ("\n");
1267 }
1268
1269 std::string indent (indent_size_ * open.test->nesting_depth (), ' ');
1270 const tap_name name{ open.test->name (), false };
1271 write_console ("%s# Subtest: %s\n", indent.c_str (), name.c_str ());
1272
1273 add_empty_line_ = false;
1274 }

References micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::indent_size_, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::test_case::nesting_depth, micro_os_plus::micro_test_plus::detail::reporter::open_test_case::test and micro_os_plus::micro_test_plus::detail::reporter::write_console.

Referenced by operator=.

output_fail_prefix()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::output_fail_prefix (const std::string & message, const bool has_expression, const reflection::source_location & location, const test_case & test_case)
virtual

Outputs the prefix for a failing condition.

Parameters
message

The message to display.

has_expression

Whether the failure is associated with an expression.

location

The source location of the failure.

test_case

The test case that owns this check.

Returns

Nothing.

This member function outputs the prefix for a failing check result, as a TAP "not ok <n>" line, indented one level deeper than the test case, followed by the message, if provided, escaped (see tap_text()), so that a # does not start a directive and a line break does not end the test point line. It then opens the TAP 14 YAML diagnostics block (---) and, when the failure has an expression, starts a condition: field, so that the expression follows on the same line; the position where the expression begins is kept in condition_begin_, so that output_fail_suffix() can quote it. Without an expression, condition_begin_ is set to std::string::npos. No colours are used.

Declaration at line 346 of file reporter-tap.h, definition at line 998 of file reporter-tap.cpp.

999 const std::string& message, const bool has_expression,
1000 [[maybe_unused]] const reflection::source_location& location,
1001 const test_case& test_case)
1002 {
1003 size_t level = test_case.nesting_depth ();
1004 *this << indent (level + 1) << "not ok " << test_case.test_point_number_;
1005
1006 if (!message.empty ())
1007 {
1008 *this << " - " << tap_text (message, true);
1009 }
1010 *this << endl;
1011
1012 // https://testanything.org/tap-version-14-specification.html
1013 // 2-space indentation for YAML diagnostics.
1014 *this << indent (level + 1) << " ---";
1015 condition_begin_ = std::string::npos;
1016 if (has_expression)
1017 {
1018 *this << endl;
1019 *this << indent (level + 1) << " condition: ";
1020 condition_begin_ = buffer_.size ();
1021 }
1022 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, condition_begin_, micro_os_plus::micro_test_plus::detail::endl, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::test_case::nesting_depth and micro_os_plus::micro_test_plus::detail::runnable_base::test_point_number_.

Referenced by operator=.

output_fail_suffix()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::output_fail_suffix (const reflection::source_location & location, check_kind kind, const test_case & test_case)
virtual

Outputs the suffix for a failing condition.

Parameters
location

The source location of the failure.

kind

The kind of the check; not used, since a failed requirement is reported like any other failed check.

test_case

The test case that owns this check.

Returns

Nothing.

Completes the TAP 14 YAML diagnostics block of a failing check, by ending the line opened by the prefix (the --- line, or the condition: field), adding the at: field with the file name and the line number, and closing the block (...). As for a pass, the streams are flushed when the test case ends.

The location fields are named fileName: and lineNumber:, as written by node-tap; its reporters (for example the JUnit one, used by the CI systems to annotate the failures) read the file name only from fileName: or file:, not from filename:. There is no columnNumber:, since reflection::source_location does not provide a column. The file name is written as a plain scalar, as node-tap does, unless it contains a character that a YAML parser would not accept in a plain scalar, when it is double-quoted (see yaml_scalar()).

The expression, which follows condition_begin_ in the buffer, is first replaced by its YAML double-quoted form (see yaml_double_quoted()), so that the operands that start a YAML flow collection or a quoted scalar (for example {1, 2} or 'a'), or contain : or #, do not make the diagnostics block invalid.

A failed requirement is reported like any other failed check, as node-tap does for a failed assertion followed by a throw; no marker is added, since any text after --- or after the condition would make the block, or the value, invalid. That the test case stopped is shown by the plan, which follows this test point; without exceptions, the abort of the test execution is reported by the Bail out! line written by abort_session().

Declaration at line 361 of file reporter-tap.h, definition at line 1057 of file reporter-tap.cpp.

1058 const reflection::source_location& location,
1059 [[maybe_unused]] check_kind kind, const test_case& test_case)
1060 {
1061 if (condition_begin_ != std::string::npos)
1062 {
1063 const std::string condition = yaml_double_quoted (
1064 std::string_view{ buffer_ }.substr (condition_begin_));
1065 buffer_.replace (condition_begin_, std::string::npos, condition);
1066 condition_begin_ = std::string::npos;
1067 }
1068
1069 size_t level = test_case.nesting_depth ();
1070 *this << endl;
1071
1072 // https://testanything.org/tap-version-14-specification.html
1073 // 2-space indentation for YAML diagnostics.
1074
1075 *this << indent (level + 1) << " at:" << endl;
1076 *this << indent (level + 1) << " fileName: "
1077 << yaml_scalar (utility::extract_file_name (location.file_name ()))
1078 << endl;
1079 *this << indent (level + 1) << " lineNumber: " << location.line ()
1080 << endl;
1081
1082 *this << indent (level + 1) << " ..." << endl;
1083 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, condition_begin_, micro_os_plus::micro_test_plus::detail::endl, micro_os_plus::micro_test_plus::utility::extract_file_name, micro_os_plus::micro_test_plus::reflection::source_location::file_name, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::reflection::source_location::line, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case and micro_os_plus::micro_test_plus::test_case::nesting_depth.

Referenced by operator=.

output_pass_prefix()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::output_pass_prefix (const std::string & message, const test_case & test_case)
virtual

Outputs the prefix for a passing condition.

Parameters
message

The message to display.

test_case

The test case that owns this check.

Returns

Nothing.

This member function outputs the prefix for a passing check result, as a TAP "ok <n> - " line, where <n> is the test point number of the check, which counts the checks and the nested test cases of the test case, indented one level deeper than the test case, followed by the message, if provided. No colours are used.

The position where the description begins is kept in description_begin_, since, when there is no message, the caller appends the expression after this member function returns.

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

Declaration at line 321 of file reporter-tap.h, definition at line 946 of file reporter-tap.cpp.

946 reporter_tap::output_pass_prefix (const std::string& message,
947 const test_case& test_case)
948 {
949 size_t level = test_case.nesting_depth ();
950 *this << indent (level + 1) << "ok " << test_case.test_point_number_
951 << " - ";
953 if (!message.empty ())
954 {
955 *this << message;
956 }
957 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, description_begin_, micro_os_plus::micro_test_plus::detail::indent, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::test_case::nesting_depth and micro_os_plus::micro_test_plus::detail::runnable_base::test_point_number_.

Referenced by operator=.

output_pass_suffix()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::output_pass_suffix (const test_case & test_case)
virtual

Outputs the suffix for a passing condition.

Parameters
test_case

The test case that owns this check.

Returns

Nothing.

The description, either the message or the expression, which follows description_begin_ in the buffer, is replaced by its escaped form (see tap_text()), so that a # does not start a directive and a line break does not end the test point line. The pass output is then completed by appending endl, which adds a line ending to the buffer. The streams are not flushed, since nothing was written to them; the buffer is written, and the streams flushed, when the test case ends.

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

Declaration at line 332 of file reporter-tap.h, definition at line 974 of file reporter-tap.cpp.

975 [[maybe_unused]] const test_case& test_case)
976 {
977 const std::string description = tap_text (
978 std::string_view{ buffer_ }.substr (description_begin_), true);
979 buffer_.replace (description_begin_, std::string::npos, description);
980
981 *this << endl;
982 }

References micro_os_plus::micro_test_plus::detail::reporter::buffer_, description_begin_, micro_os_plus::micro_test_plus::detail::endl and micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case.

Referenced by operator=.

write_quiet_failures()​

void micro_os_plus::micro_test_plus::detail::reporter_tap::write_quiet_failures (void)

Writes the failed checks of the quiet verbosity, as comments.

The quiet verbosity displays the suites as single test points, so the failed checks cannot be displayed as test points of their own, without altering the plan. They are written as TAP comments, preceded by a comment that names the suite and the open test cases, which keeps the console output a valid TAP document. The failed checks are removed from the buffer by clear_buffer(), not by this function. Nothing is written if there is no failed check.

Parameters

None.

Returns

Nothing.

Writes a comment line with the names of the suite and of the open test cases, separated by " > ", with the line breaks replaced by spaces, then the lines of failures_, each prefixed by the comment prefix. The lines of the failed checks keep their indentation, after the prefix, so that the YAML diagnostics blocks remain readable. The output is not buffered; failures_ is not cleared.

Declaration at line 418 of file reporter-tap.h, definition at line 1286 of file reporter-tap.cpp.

1287 {
1288 if (failures_.empty ())
1289 {
1290 return;
1291 }
1292
1293 std::string path;
1294 if (current_suite_ != nullptr)
1295 {
1296 path = tap_name{ current_suite_->name (), false }.c_str ();
1297 }
1298 for (const open_test_case& open : open_test_cases_)
1299 {
1300 if (!path.empty ())
1301 {
1302 path.append (" > ");
1303 }
1304 path.append (tap_name{ open.test->name (), false }.c_str ());
1305 }
1306 write_console ("%s%s\n", comment_prefix (), path.c_str ());
1307
1308 std::string_view rest{ failures_ };
1309 while (!rest.empty ())
1310 {
1311 const size_t end = rest.find ('\n');
1312 const size_t length
1313 = (end == std::string_view::npos) ? rest.size () : end + 1;
1314 write_console ("%s", comment_prefix ());
1315 write_console_text (rest.substr (0, length));
1316 rest.remove_prefix (length);
1317 }
1318 }

References comment_prefix, micro_os_plus::micro_test_plus::detail::reporter::current_suite_, micro_os_plus::micro_test_plus::detail::reporter::failures_, micro_os_plus::micro_test_plus::detail::runnable_base::name, micro_os_plus::micro_test_plus::detail::reporter::open_test_cases_, micro_os_plus::micro_test_plus::detail::reporter::write_console and micro_os_plus::micro_test_plus::detail::reporter::write_console_text.

Referenced by abort_session, commit_buffer, end_suite, end_test_case and operator=.

Protected Member Attributes​

add_empty_line_​

buffer_​

std::string micro_os_plus::micro_test_plus::detail::reporter::buffer_ {}
protected

buffer_has_failures_​

bool micro_os_plus::micro_test_plus::detail::reporter::buffer_has_failures_ { false }
protected

Whether the output buffer contains a failed check.

Set by fail() and reset by clear_buffer(). When a nested test case begins, the concrete reporters use it to decide whether the results already buffered for the outer test case are displayed with normal verbosity.

Definition at line 1305 of file reporter.h.

1305 bool buffer_has_failures_{ false };

Referenced by micro_os_plus::micro_test_plus::detail::reporter::clear_buffer, micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer and micro_os_plus::micro_test_plus::detail::reporter::mark_failure.

colours_​

current_suite_​

const suite* micro_os_plus::micro_test_plus::detail::reporter::current_suite_ { nullptr }
protected

expression_​

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

Expression formatter for pass and fail reporting.

Used by the checks (test_case::expect(), test_case::require(), and detail::check_result), which are friends, to pre-format expressions at construction time; pass() and fail() then append the formatted text to buffer_. The applications format their own types by defining operator<< for the public expression_formatter alias.

Definition at line 1423 of file reporter.h.

Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result and micro_os_plus::micro_test_plus::test_case::report_misdirected.

failures_​

std::string micro_os_plus::micro_test_plus::detail::reporter::failures_ {}
protected

The lines of the failed checks, for the quiet verbosity.

With the quiet verbosity, the console displays only the failed checks, while buffer_ may also contain the passed checks, for the output file. Filled by mark_failure() and emptied by clear_buffer(); not used with the other verbosity levels.

Definition at line 1316 of file reporter.h.

1316 std::string failures_{};

Referenced by micro_os_plus::micro_test_plus::detail::reporter::clear_buffer, micro_os_plus::micro_test_plus::detail::reporter::console_lines, micro_os_plus::micro_test_plus::detail::reporter::mark_failure and write_quiet_failures.

has_output_file_error_​

bool micro_os_plus::micro_test_plus::detail::reporter::has_output_file_error_ { false }
protected

Whether the output file could not be opened.

Set by the constructor, and returned by has_output_file_error(). Kept next to the other flags, so that the class does not end with padding, which the derived classes would report.

Definition at line 1444 of file reporter.h.

Referenced by micro_os_plus::micro_test_plus::detail::reporter::reporter and micro_os_plus::micro_test_plus::detail::reporter::has_output_file_error.

open_test_cases_​

std::vector<open_test_case> micro_os_plus::micro_test_plus::detail::reporter::open_test_cases_ {}
protected

output_file_​

FILE* micro_os_plus::micro_test_plus::detail::reporter::output_file_ { nullptr }
protected

output_file_path_​

std::string micro_os_plus::micro_test_plus::detail::reporter::output_file_path_ {}
protected

Path of the optional output file.

Copied by the constructor from the session options. Used to name the file in the confirmation message displayed when the file is closed (not displayed with the silent verbosity).

Definition at line 1454 of file reporter.h.

1454 std::string output_file_path_{};

Referenced by micro_os_plus::micro_test_plus::detail::reporter::reporter, micro_os_plus::micro_test_plus::detail::reporter::~reporter and micro_os_plus::micro_test_plus::detail::reporter::announce_output_file.

suite_displayed_​

bool micro_os_plus::micro_test_plus::detail::reporter::suite_displayed_ { false }
protected

Whether the heading of the current suite was displayed on the console.

Set by enter_suite(); with the quiet verbosity, which does not display the headings, the heading is displayed when the first failure of the suite is.

Definition at line 1410 of file reporter.h.

1410 bool suite_displayed_{ false };

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session, micro_os_plus::micro_test_plus::detail::reporter_human::display_open_names and micro_os_plus::micro_test_plus::detail::reporter::enter_suite.

verbosity_​

const micro_test_plus::verbosity micro_os_plus::micro_test_plus::detail::reporter::verbosity_
protected

Private Member Attributes​

condition_begin_​

size_t micro_os_plus::micro_test_plus::detail::reporter_tap::condition_begin_ = std::string::npos

The position in the buffer where the expression of a failed check begins.

Set by output_fail_prefix(), after the condition: key, and used by output_fail_suffix() to write the expression appended between the two calls as a YAML double-quoted scalar. It is std::string::npos when the failure has no expression.

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

441 size_t condition_begin_ = std::string::npos;

Referenced by output_fail_prefix and output_fail_suffix.

description_begin_​

size_t micro_os_plus::micro_test_plus::detail::reporter_tap::description_begin_ = 0

The position in the buffer where the description of a passed check begins.

Set by output_pass_prefix() and used by output_pass_suffix() to escape the description, which is the message, or the expression appended between the two calls when there is no message.

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

Referenced by output_pass_prefix and output_pass_suffix.

Protected Static Functions​

format_elapsed_time()​

void micro_os_plus::micro_test_plus::detail::reporter::format_elapsed_time (const stopwatch & stopwatch, char(&message)[elapsed_time_size_])
protected static

Formats the elapsed time of a suite or of the session.

The text is appended to the summary lines by the concrete reporters, in the form ", time: 1.234 ms"; it is empty when the stopwatch has no elapsed time, so that the summary lines remain identical on the platforms without a clock.

The array has a fixed size, known at compile time, so that the compiler can verify that the text is never truncated.

Parameters
stopwatch

The stopwatch of the suite or of the runner.

message

The character array that receives the null-terminated text.

Returns

Nothing.

The elapsed time, in microseconds, is displayed in milliseconds, with three decimals. When it is zero, either because the stopwatch has no readings or because the interval was shorter than a microsecond, the text is empty.

Declaration at line 1061 of file reporter.h, definition at line 810 of file reporter.cpp.

811 char (&message)[elapsed_time_size_])
812 {
813 const auto elapsed = stopwatch.elapsed ().count ();
814 if (elapsed > 0)
815 {
816 snprintf (message, sizeof (message),
817 ", time: %" PRIu32 ".%03" PRIu32 " ms",
818 static_cast<uint32_t> (elapsed / 1000),
819 static_cast<uint32_t> (elapsed % 1000));
820 }
821 else
822 {
823 message[0] = '\0';
824 }
825 }

References micro_os_plus::micro_test_plus::detail::stopwatch::elapsed and micro_os_plus::micro_test_plus::detail::reporter::elapsed_time_size_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite and end_suite.

format_session_totals()​

void micro_os_plus::micro_test_plus::detail::reporter::format_session_totals (const runner & runner, char(&message)[totals_size_])
protected static

Formats the totals of the test session.

The text is the part of the session summary line common to the concrete reporters, in the form "7 checks passed, 1 failed, in 3 test cases, 2 test suites"; the numbers of test cases and of suites skipped by the filter follow the respective counts, as ", 1 skipped", only when not zero. The label (Total: or total:), the markers, and the elapsed time are added by the callers.

Parameters
runner

The runner of the test session.

message

The character array that receives the null-terminated text.

Returns

Nothing.

The suites are counted by runner::total_suites_count(), which includes the suites skipped by the filter, counted separately by runner::skipped_suites_count().

Declaration at line 1104 of file reporter.h, definition at line 896 of file reporter.cpp.

897 char (&message)[totals_size_])
898 {
899 // The fixed text, four counts, two fragments, and the terminator.
900 static_assert (totals_size_
901 >= 54 + 4 * (std::numeric_limits<size_t>::digits10 + 1)
902 + 2 * (fragment_size - 1),
903 "totals_size_ too small for the session totals");
904
905 const counters& totals = runner.totals ();
906 const size_t suites_count = runner.total_suites_count ();
907
908 char message_skipped_test_cases[fragment_size];
909 format_skipped (totals.skipped_test_cases (), message_skipped_test_cases);
910
911 char message_skipped_suites[fragment_size];
912 format_skipped (runner.skipped_suites_count (), message_skipped_suites);
913
914 snprintf (message, sizeof (message),
918 " test case%s%s, %" MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE " "
919 "test suite%s%s",
920 totals.passed_checks (), plural (totals.passed_checks ()),
921 totals.failed_checks (), totals.executed_test_cases (),
922 plural (totals.executed_test_cases ()),
923 message_skipped_test_cases, suites_count, plural (suites_count),
924 message_skipped_suites);
925 }

References micro_os_plus::micro_test_plus::counters::executed_test_cases, micro_os_plus::micro_test_plus::counters::failed_checks, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner, micro_os_plus::micro_test_plus::counters::passed_checks, micro_os_plus::micro_test_plus::runner::skipped_suites_count, micro_os_plus::micro_test_plus::counters::skipped_test_cases, micro_os_plus::micro_test_plus::runner::total_suites_count, micro_os_plus::micro_test_plus::runner::totals and micro_os_plus::micro_test_plus::detail::reporter::totals_size_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_session and end_session.

format_suite_totals()​

void micro_os_plus::micro_test_plus::detail::reporter::format_suite_totals (const suite & suite, char(&message)[totals_size_])
protected static

Formats the totals of a suite.

The text is the part of the suite result line common to the concrete reporters: "7 checks in 3 test cases" for a passed suite, and "6 checks passed, 1 failed, in 3 test cases" for a failed one; the number of test cases skipped by the filter follows, as ", 1 skipped", only when not zero. The status, the enclosing markers, and the elapsed time are added by the callers.

Parameters
suite

The suite that ended.

message

The character array that receives the null-terminated text.

Returns

Nothing.

A passed suite has no failed checks, so only the number of checks is shown.

Declaration at line 1125 of file reporter.h, definition at line 933 of file reporter.cpp.

934 char (&message)[totals_size_])
935 {
936 const counters& totals = suite.totals ();
937
938 char message_skipped[fragment_size];
939 format_skipped (totals.skipped_test_cases (), message_skipped);
940
941 if (totals.passed ()) [[likely]]
942 {
943 snprintf (message, sizeof (message),
946 " test case%s%s",
947 totals.passed_checks (), plural (totals.passed_checks ()),
948 totals.executed_test_cases (),
949 plural (totals.executed_test_cases ()), message_skipped);
950 }
951 else
952 {
953 snprintf (message, sizeof (message),
957 " test case%s%s",
958 totals.passed_checks (), plural (totals.passed_checks ()),
959 totals.failed_checks (), totals.executed_test_cases (),
960 plural (totals.executed_test_cases ()), message_skipped);
961 }
962 }

References micro_os_plus::micro_test_plus::counters::executed_test_cases, micro_os_plus::micro_test_plus::counters::failed_checks, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::counters::passed, micro_os_plus::micro_test_plus::counters::passed_checks, micro_os_plus::micro_test_plus::counters::skipped_test_cases, micro_os_plus::micro_test_plus::detail::runnable_base::totals and micro_os_plus::micro_test_plus::detail::reporter::totals_size_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_suite and end_suite.

format_test_case_totals()​

void micro_os_plus::micro_test_plus::detail::reporter::format_test_case_totals (const test_case & test_case, char(&message)[totals_size_])
protected static

Formats the totals of a test case.

The text is the part of the test case result line common to the concrete reporters: "7 checks" for a passed test case, and "6 checks passed, 1 failed" for a failed one, followed by the number of failed nested test cases, as ", 1 test case failed", only when not zero, since a test case may fail because of a nested one alone. The status and the enclosing markers are added by the callers.

Parameters
test_case

The test case that ended.

message

The character array that receives the null-terminated text.

Returns

Nothing.

A passed test case has no failed checks and no failed nested test cases, so only the number of checks is shown.

Declaration at line 1146 of file reporter.h, definition at line 970 of file reporter.cpp.

971 char (&message)[totals_size_])
972 {
973 const counters& totals = test_case.totals ();
974
975 if (totals.passed ()) [[likely]]
976 {
977 snprintf (message, sizeof (message),
979 totals.passed_checks (), plural (totals.passed_checks ()));
980 }
981 else
982 {
983 char message_test_cases[fragment_size] = "";
984 if (totals.failed_test_cases () > 0)
985 {
986 snprintf (message_test_cases, sizeof (message_test_cases),
988 " test case%s failed",
989 totals.failed_test_cases (),
990 plural (totals.failed_test_cases ()));
991 }
992
993 snprintf (message, sizeof (message),
996 " failed%s",
997 totals.passed_checks (), plural (totals.passed_checks ()),
998 totals.failed_checks (), message_test_cases);
999 }
1000 }

References micro_os_plus::micro_test_plus::counters::failed_checks, micro_os_plus::micro_test_plus::counters::failed_test_cases, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::test_case, micro_os_plus::micro_test_plus::counters::passed, micro_os_plus::micro_test_plus::counters::passed_checks, micro_os_plus::micro_test_plus::detail::runnable_base::totals and micro_os_plus::micro_test_plus::detail::reporter::totals_size_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case and end_test_case.

Protected Static Attributes​

elapsed_time_size_​

size_t micro_os_plus::micro_test_plus::detail::reporter::elapsed_time_size_ = 40
constexpr protected static

Size of the array that receives the elapsed time text.

Large enough for ", time: 4294967295.999 ms", the longest text produced by format_elapsed_time() (26 bytes with the terminator), and for the worst case assumed by GCC 11, which does not know that the fraction is below 1000 and counts ten digits for it (33 bytes).

Definition at line 1040 of file reporter.h.

1040 static constexpr size_t elapsed_time_size_ = 40;

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite and micro_os_plus::micro_test_plus::detail::reporter::format_elapsed_time.

indent_size_​

size_t micro_os_plus::micro_test_plus::detail::reporter::indent_size_ = 4
constexpr protected static

totals_size_​

size_t micro_os_plus::micro_test_plus::detail::reporter::totals_size_ = 94 + 6 * (std::numeric_limits<size_t>::digits10 + 1)
constexpr protected static

Size of the array that receives the totals text.

Large enough for the longest text produced by format_session_totals(), which is longer than the texts of the suites and of the test cases: 53 characters, four counts, two fragments of up to 20 characters and a count each (the longest fragment is ", N test cases failed"), and the terminator, with the counts of the largest size_t value (10 digits on 32-bit targets, 20 on 64-bit ones). The fragments are counted at their maximum length, as the compiler does when it checks for truncation.

The array is a local variable of the functions that end the test cases, which run at the deepest point of the stack, so it is not larger than needed on the 32-bit embedded targets.

Definition at line 1082 of file reporter.h.

1083 = 94 + 6 * (std::numeric_limits<size_t>::digits10 + 1);

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_session, end_session, micro_os_plus::micro_test_plus::detail::reporter_human::end_suite, end_suite, micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case, end_test_case, micro_os_plus::micro_test_plus::detail::reporter::format_session_totals, micro_os_plus::micro_test_plus::detail::reporter::format_suite_totals and micro_os_plus::micro_test_plus::detail::reporter::format_test_case_totals.

Deprecated Functions​

verbosity()​

micro_test_plus::verbosity micro_os_plus::micro_test_plus::detail::reporter::verbosity (void)
inline nodiscard noexcept

Deprecated access to the verbosity level.

Kept from the v5.0.1 reporter class, for the applications that read it through the deprecated runner::reporter() (tr.reporter ().verbosity ()). The level is the one returned by runner::verbosity_level(), from the same session options.

Parameters

None.

Returns

The verbosity level of the session.

Returns the level stored in verbosity_, set by the constructor.

Declaration at line 492 of file reporter.h, definition at line 110 of file reporter-inlines.h.

111 {
112 return verbosity_;
113 }

Reference micro_os_plus::micro_test_plus::detail::reporter::verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter::micro_test_plus::runner.


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


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.