micro-test-plus 6.0.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::reporter Class Referenceabstract

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

#include "micro-os-plus/micro-test-plus.h"

Inheritance diagram for micro_os_plus::micro_test_plus::detail::reporter:

Classes

struct  open_test_case
 A test case that has begun and not yet ended. More...

Public Member Functions

 reporter (const runner_options &opts)
 Constructor for the reporter class.
virtual ~reporter ()
 Virtual destructor for the reporter class.
virtual void abort_session (const reflection::source_location &location, bool is_requirement)=0
 Reports the abort of the test execution.
virtual void begin_session (const runner &runner)=0
 Marks the beginning of a test session.
virtual void begin_suite (const suite &suite)=0
 Marks the beginning of a test suite.
virtual void begin_test_case (const test_case &test_case)=0
 Marks the beginning of a test case.
virtual const char * comment_prefix (void) const noexcept=0
 Returns the comment-prefix string used by this reporter format.
void end_line (void)
 Appends a line ending to the internal output buffer.
virtual void end_session (const runner &runner)=0
 Marks the end of a test session.
virtual void end_suite (const suite &suite)=0
 Marks the end of a test suite.
virtual void end_test_case (const test_case &test_case)=0
 Marks the end of a test case.
virtual const char * error_prefix (void) const noexcept
 Returns the prefix of the lines that report an error.
void fail (const failure_info &failure, const std::string &expression, const test_case &test_case)
 Reports a failed condition.
virtual void fail_suite (const std::string &message, const suite &suite)=0
 Reports a failure of a test suite outside its test cases.
void flush_streams (void)
 Flushes the standard output stream and the output file.
bool has_output_file_error (void) const noexcept
 Returns whether the output file could not be opened.
reporter & operator<< (bool v)
 Output operator for boolean values.
reporter & operator<< (char c)
 Output operator for a single character.
reporter & operator<< (const char *s)
 Output operator for a constant character string.
reporter & operator<< (indentation m)
 Output operator for the indentation manipulator.
reporter & operator<< (reporter &(*func)(reporter &))
 Output operator for stream manipulators, such as endl.
reporter & operator<< (std::nullptr_t)
 Output operator for nullptr.
reporter & operator<< (std::string_view sv)
 Output operator for std::string_view.
template<typename T>
requires (not std::is_same_v<T, char>)
reporter & operator<< (T *v)
 Output operator to display any pointer.
template<class T>
requires std::is_arithmetic_v<T>
reporter & operator<< (T v)
 Output operator for arithmetic types.
void pass (const std::string &message, const std::string &expression, const test_case &test_case)
 Reports a passed condition.
virtual void pass_without_text (const test_case &test_case)=0
 Reports a passed condition whose text is not written.
virtual void skip_suite (const suite &suite)=0
 Reports a test suite skipped by the filter.
virtual void skip_test_case (const test_case &test_case)=0
 Reports a test case skipped by the filter.
bool writes_passed_checks (void) const noexcept
 Returns whether the passed checks are written anywhere.
Deprecated Functions
auto verbosity (void) const noexcept -> micro_test_plus::verbosity
 Deprecated access to the verbosity level.

Protected Member Functions

void announce_output_file (void)
 Tells the console where the output file was written.
void clear_buffer (void)
 Clears the output buffer.
virtual void commit_buffer (void)=0
 Writes the results buffered for the outer test case before a nested test case begins or is skipped.
void commit_outer_results (void)
 Writes the results of the outer test case, if any, before a nested test case begins or is skipped.
std::string_view console_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.
virtual void display_open_heading (const open_test_case &open, bool is_first)=0
 Writes the heading of an open test case.
void display_open_test_cases (bool include_last)
 Displays the headings not yet displayed, of the open test cases.
void enter_suite (const suite &suite, bool displayed)
 Notes the suite that begins, for the headings displayed later.
void mark_failure (size_t begin)
 Records that the lines appended to the buffer from a given position are a failure.
virtual void output_fail_prefix (const std::string &message, const bool has_expression, const reflection::source_location &location, const test_case &test_case)=0
 Outputs the prefix for a failing condition.
virtual void output_fail_suffix (const reflection::source_location &location, check_kind kind, const test_case &test_case)=0
 Outputs the suffix for a failing condition.
virtual void output_pass_prefix (const std::string &message, const test_case &test_case)=0
 Outputs the prefix for a passing condition.
virtual void output_pass_suffix (const test_case &test_case)=0
 Outputs the suffix for a passing condition.
output_route route (record_kind kind) const noexcept
 Tells where a kind of record is written.
void write_buffer_to_file (void)
 Writes the current buffered content to the output file.
void write_console (const char *format,...)
 Writes formatted text to the console.
void write_console_text (std::string_view text)
 Writes a text to the console, unchanged.
void write_file (const char *format,...)
 Writes formatted text to the output file.
void write_info (const std::vector< std::string > &arguments)
 Writes the informational (non-result) lines to the console and to the output file.
void write_line (bool to_console, const char *format,...)
 Writes formatted lines to the output file and, when requested, to the console.

Static Protected Member Functions

static void format_elapsed_time (const stopwatch &stopwatch, char(&message)[elapsed_time_size_])
 Formats the elapsed time of a suite or of the session.
static void format_session_totals (const runner &runner, char(&message)[totals_size_])
 Formats the totals of the test session.
static void format_suite_totals (const suite &suite, char(&message)[totals_size_])
 Formats the totals of a suite.
static void format_test_case_totals (const test_case &test_case, char(&message)[totals_size_])
 Formats the totals of a test case.

Protected Attributes

bool add_empty_line_ { true }
 Whether to write an empty line before the next console output.
std::string buffer_ {}
 Output accumulation buffer.
bool buffer_has_failures_ { false }
 Whether the output buffer contains a failed check.
colours colours_ {}
 ANSI colour codes for output formatting.
const suite * current_suite_ { nullptr }
 The suite that has begun and not yet ended.
expression_formatter expression_ { colours_ }
 Expression formatter for pass and fail reporting.
std::string failures_ {}
 The lines of the failed checks, for the quiet verbosity.
bool has_output_file_error_ { false }
 Whether the output file could not be opened.
std::vector< open_test_case > open_test_cases_ {}
 The test cases that have begun and not yet ended, outermost first.
FILE * output_file_ { nullptr }
 Optional output file, receiving a copy of the test report.
std::string output_file_path_ {}
 Path of the optional output file.
bool suite_displayed_ { false }
 Whether the heading of the current suite was displayed on the console.
const micro_test_plus::verbosity verbosity_
 The verbosity level for test reporting.

Static Protected Attributes

static constexpr size_t elapsed_time_size_ = 40
 Size of the array that receives the elapsed time text.
static constexpr size_t indent_size_ = 4
 Number of spaces per nesting level.
static constexpr size_t totals_size_ = 94 + 6 * (std::numeric_limits<size_t>::digits10 + 1)
 Size of the array that receives the totals text.

Friends

class check_result
 The check result, which formats the expressions.
class micro_test_plus::runner
 The runner, which lists the test cases.
class micro_test_plus::test_case
 The test case, which creates the checks.

Detailed Description

The reporter class is responsible for presenting test results within the µTest++ framework. It accumulates output in a buffer, using basic output operators for strings, characters, booleans, numbers, and pointers, and writes it to the console and to an optional output file.

For failed checks, the reporter prints the actual values of the operands, pre-formatted by its expression_formatter (with type suffixes for numbers). The class supports multiple verbosity levels and colour-coded output to distinguish between passed and failed checks.

The pure virtual member functions report the beginning and end of the session, the suites, and the test cases, and format the pass and fail results; they are implemented by reporter_human and reporter_tap. The concrete reporter is created by the runner, as selected by the --reporter command-line option, or by runner_options::selected_reporter.

The reporters are internal to the framework: their public members are the protocol between the runner, the test nodes, the checks, and the reporter, and custom reporters are not supported. The applications select a reporter with the --reporter command-line option, or with the runner_options, and read the verbosity with runner::verbosity_level().

Definition at line 275 of file reporter.h.

Constructor & Destructor Documentation

◆ reporter()

micro_os_plus::micro_test_plus::detail::reporter::reporter ( const runner_options & opts)
explicit
Parameters
optsThe session options, passed to runner::initialise() or parsed by it from the command line.

Copies the verbosity and the view of the command-line arguments from the session options, and opens the output file, if a non-empty path was given, keeping a copy of the path. If the file cannot be opened, an error message is written to stderr, and has_output_file_error() returns true, after which runner::initialise() declines the session, so that no test is run. The internal string buffer is pre-allocated to reduce dynamic allocation overhead.

Definition at line 162 of file reporter.cpp.

163 : verbosity_{ opts.verbosity_level }
164 {
165#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
166 trace::printf ("%s\n", __PRETTY_FUNCTION__);
167#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
168
169 if (!opts.output_file_path.empty ())
170 {
171 output_file_ = fopen (opts.output_file_path.c_str (), "w");
172 if (output_file_ == nullptr)
173 {
174 fprintf (stderr, "error: failed to open output file '%s'\n",
175 opts.output_file_path.c_str ());
177 }
178 else
179 {
180 output_file_path_ = opts.output_file_path;
181 }
182 }
183
184 // Pre-allocate buffer to reduce dynamic allocations.
185 buffer_.reserve (128);
186 }
std::string buffer_
Output accumulation buffer.
Definition reporter.h:1294
bool has_output_file_error_
Whether the output file could not be opened.
Definition reporter.h:1444
const micro_test_plus::verbosity verbosity_
The verbosity level for test reporting.
Definition reporter.h:1273
FILE * output_file_
Optional output file, receiving a copy of the test report.
Definition reporter.h:1465
std::string output_file_path_
Path of the optional output file.
Definition reporter.h:1454

References buffer_, has_output_file_error_, output_file_, micro_os_plus::micro_test_plus::runner_options::output_file_path, output_file_path_, and verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::reporter_human(), micro_os_plus::micro_test_plus::detail::reporter_tap::reporter_tap(), micro_test_plus::runner, operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), and operator<<().

◆ ~reporter()

micro_os_plus::micro_test_plus::detail::reporter::~reporter ( )
virtual

Virtual, so that the concrete reporters, owned through a pointer to this base class, are destroyed correctly.

If an output file was opened, it is flushed and closed. If tracing is enabled, the function signature is output for diagnostic purposes.

Definition at line 194 of file reporter.cpp.

195 {
196#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
197 trace::printf ("%s\n", __PRETTY_FUNCTION__);
198#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
199
200 if (output_file_ != nullptr)
201 {
202 fflush (output_file_);
203 fclose (output_file_);
204
205 output_file_ = nullptr;
206 output_file_path_.clear ();
207 }
208 }

References output_file_, and output_file_path_.

Member Function Documentation

◆ abort_session()

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

Called by runner::abort() between begin_session() and end_session(), before the abort handler and ::abort(); neither the end_test_case() of the running test cases, if any, nor end_session() are called afterwards. The abort is caused either by a failed require(), when exceptions are disabled, after the failure was added to the output buffer, or by an explicit call of runner::abort(), from a test case body, from a suite body, or from the application.

Implementations display the buffered results, if any, with the context that identifies the running test case, followed by a line with the location of the abort, unless the verbosity is silent, and write them to the output file, if open, since the totals are never reached. They then clear the buffer, since the abort handler may throw an exception that the application catches, and the results must not be written again.

Parameters
locationThe source location of the failed requirement, or of the runner::abort() call.
is_requirementtrue if the abort is caused by a failed requirement.
Returns
Nothing.
Since
6.0.0

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

◆ announce_output_file()

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

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.

Definition at line 244 of file reporter.cpp.

245 {
246 if (output_file_ == nullptr)
247 {
248 return;
249 }
250
251 flush_streams ();
252
254 {
255 write_console ("%sTest output written to '%s'.\n", comment_prefix (),
256 output_file_path_.c_str ());
257 fflush (stdout);
258 }
259 }
virtual const char * comment_prefix(void) const noexcept=0
Returns the comment-prefix string used by this reporter format.
void flush_streams(void)
Flushes the standard output stream and the output file.
Definition reporter.cpp:622
void write_console(const char *format,...)
Writes formatted text to the console.
Definition reporter.cpp:444

References comment_prefix(), flush_streams(), output_file_, output_file_path_, micro_os_plus::micro_test_plus::silent, verbosity_, and write_console().

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session(), comment_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::end_session(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_session().

◆ begin_session()

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

Called by runner::initialise(), after the reporter is created; implementations display the session heading.

Parameters
runnerReference to the test runner.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::runner.

◆ begin_suite()

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

Called by suite::run() before the suite body, for the suites registered with runner::add_suite() and for the static suites, and by runner::add_top_suite() for the top suite.

Parameters
suiteReference to the test suite.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

Referenced by micro_os_plus::micro_test_plus::suite::run().

◆ begin_test_case()

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

Called by test_case::run() before the test case body; the results buffered for an outer test case, if any, are written first (see commit_outer_results()), so that the buffer is empty when the body starts.

Parameters
test_caseReference to the test case.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by micro_os_plus::micro_test_plus::test_case::run().

◆ clear_buffer()

◆ comment_prefix()

virtual const char * micro_os_plus::micro_test_plus::detail::reporter::comment_prefix ( void ) const
pure virtualnoexcept

◆ commit_buffer()

virtual void micro_os_plus::micro_test_plus::detail::reporter::commit_buffer ( void )
protectedpure virtual

The concrete reporters decide where the results are written, and with which verbosity levels; the buffer is cleared.

Parameters
None.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References commit_outer_results().

Referenced by commit_outer_results().

◆ commit_outer_results()

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

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.

Definition at line 1013 of file reporter.cpp.

1014 {
1015 if (!buffer_.empty ())
1016 {
1017 commit_buffer ();
1018 }
1019 }
virtual void commit_buffer(void)=0
Writes the results buffered for the outer test case before a nested test case begins or is skipped.

References buffer_, and commit_buffer().

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_test_case(), commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::skip_test_case().

◆ console_lines()

std::string_view micro_os_plus::micro_test_plus::detail::reporter::console_lines ( bool failed) const
nodiscardprotectednoexcept

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

Definition at line 332 of file reporter.cpp.

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 buffer_, failures_, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::verbose, and verbosity_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session(), comment_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_tap::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case().

◆ display_open_heading()

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

Called by display_open_test_cases(), for each open test case whose heading was not displayed yet. The concrete reporters write the line in their own format, preceded by an empty line when they need one, and update add_empty_line_ accordingly.

Parameters
openThe open test case.
is_firstWhether this is the first heading written by the current call of display_open_test_cases().
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

Referenced by display_open_test_cases().

◆ display_open_test_cases()

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

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

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 }
std::vector< open_test_case > open_test_cases_
The test cases that have begun and not yet ended, outermost first.
Definition reporter.h:1352
virtual void display_open_heading(const open_test_case &open, bool is_first)=0
Writes the heading of an open test case.
A test case that has begun and not yet ended.
Definition reporter.h:1325

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

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

◆ end_line()

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

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.

Definition at line 232 of file reporter.cpp.

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

References buffer_.

Referenced by micro_os_plus::micro_test_plus::detail::endl(), and micro_test_plus::runner.

◆ end_session()

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

Called by runner::run_suites(), after all suites have run; implementations display the session summary.

Parameters
runnerReference to the test runner.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::runner.

◆ end_suite()

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

Called by suite::run() after the suite body, also when an exception escaped it, for the suites registered with runner::add_suite() and for the static suites, and by runner::run_suites() for the top suite; implementations display the suite results.

Parameters
suiteReference to the test suite.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

Referenced by micro_os_plus::micro_test_plus::suite::run().

◆ end_test_case()

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

Called by test_case::run() after the test case body; implementations display the test case results and clear the output buffer.

Parameters
test_caseReference to the test case.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by micro_os_plus::micro_test_plus::test_case::run().

◆ enter_suite()

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

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

Parameters
suiteThe suite that begins.
displayedWhether 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.

Definition at line 409 of file reporter.cpp.

410 {
411 current_suite_ = &suite;
412 suite_displayed_ = displayed;
413 }
bool suite_displayed_
Whether the heading of the current suite was displayed on the console.
Definition reporter.h:1410
const suite * current_suite_
The suite that has begun and not yet ended.
Definition reporter.h:1399

References current_suite_, and suite_displayed_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_suite(), and comment_prefix().

◆ error_prefix()

const char * micro_os_plus::micro_test_plus::detail::reporter::error_prefix ( void ) const
virtualnoexcept

Used by the runner to write the command-line errors on the console when it refuses to run the tests, so that they are valid in the output format (for TAP, a Bail out! line). The default is "error: ", as the messages written on stderr.

Parameters
None.
Returns
A null-terminated prefix string.

Returns "error: ", as the messages written on stderr; the TAP reporter overrides it with its bail-out marker.

Reimplemented in micro_os_plus::micro_test_plus::detail::reporter_tap.

Definition at line 267 of file reporter.cpp.

268 {
269 return "error: ";
270 }

Referenced by comment_prefix().

◆ fail()

void micro_os_plus::micro_test_plus::detail::reporter::fail ( const failure_info & failure,
const std::string & expression,
const test_case & test_case )
Parameters
failureThe failure details: the kind of the check, the message to display, whether the expression text is displayed, and the source location of the failure.
expressionThe string representation of the expression.
test_caseThe 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.

Definition at line 771 of file reporter.cpp.

773 {
774 const size_t begin = buffer_.size ();
775
776 output_fail_prefix (failure.message, failure.has_expression,
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 }
virtual void output_fail_prefix(const std::string &message, const bool has_expression, const reflection::source_location &location, const test_case &test_case)=0
Outputs the prefix for a failing condition.
void mark_failure(size_t begin)
Records that the lines appended to the buffer from a given position are a failure.
Definition reporter.cpp:367
friend class micro_test_plus::test_case
The test case, which creates the checks.
Definition reporter.h:284
virtual void output_fail_suffix(const reflection::source_location &location, check_kind kind, const test_case &test_case)=0
Outputs the suffix for a failing condition.

References 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, mark_failure(), micro_os_plus::micro_test_plus::detail::failure_info::message, micro_test_plus::test_case, output_fail_prefix(), and 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 pass_without_text().

◆ fail_suite()

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

Called between begin_suite() and end_suite(), outside the test cases: by suite::run(), through fail_unexpected_exception(), when an exception escapes the suite body, and by runner::reject_call() and runnable_base::accepts_test_case(), when a call is rejected while the suite body runs. The suite has already advanced to its next test point, which numbers the failure after the test cases already run. Implementations add a failed line to the output buffer, at the indentation of the test cases, which end_suite() displays; there is no source location to show.

Parameters
messageThe message to display.
suiteReference to the test suite.
Returns
Nothing.
Since
6.0.0

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::accepts_test_case(), and micro_os_plus::micro_test_plus::suite::fail_unexpected_exception().

◆ flush_streams()

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

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.

Definition at line 622 of file reporter.cpp.

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

References output_file_.

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

◆ format_elapsed_time()

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

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
stopwatchThe stopwatch of the suite or of the runner.
messageThe 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.

Definition at line 810 of file reporter.cpp.

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

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

◆ format_session_totals()

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

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
runnerThe runner of the test session.
messageThe 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().

Definition at line 896 of file reporter.cpp.

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),
916 " check%s passed, %" MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
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 }
friend class micro_test_plus::runner
The runner, which lists the test cases.
Definition reporter.h:301
static constexpr size_t totals_size_
Size of the array that receives the totals text.
Definition reporter.h:1083
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
Portable printf() conversion for the size_t values.
Definition detail.h:102
void format_skipped(size_t count, char(&message)[fragment_size])
Formats the number of items skipped by the filter.
Definition reporter.cpp:874
constexpr size_t fragment_size
Size of the array that receives a fragment of the totals.
Definition reporter.cpp:841
constexpr const char * plural(size_t count) noexcept
Returns the plural suffix for a count.
Definition reporter.cpp:854

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

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_session(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_session().

◆ format_suite_totals()

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

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
suiteThe suite that ended.
messageThe 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.

Definition at line 933 of file reporter.cpp.

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),
955 " check%s passed, %" MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
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 totals_size_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), and micro_os_plus::micro_test_plus::detail::reporter_tap::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_] )
staticprotected

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_caseThe test case that ended.
messageThe 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.

Definition at line 970 of file reporter.cpp.

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),
995 " check%s passed, %" MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
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_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 totals_size_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case().

◆ has_output_file_error()

bool micro_os_plus::micro_test_plus::detail::reporter::has_output_file_error ( void ) const
nodiscardnoexcept

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
trueThe output file was requested but could not be opened.
falseNo output file was requested, or it was opened.

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

Definition at line 636 of file reporter.cpp.

637 {
639 }

References has_output_file_error_.

Referenced by micro_test_plus::runner.

◆ mark_failure()

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

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

Parameters
beginThe 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.

Definition at line 367 of file reporter.cpp.

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

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

Referenced by comment_prefix(), fail(), micro_os_plus::micro_test_plus::detail::reporter_human::fail_suite(), and micro_os_plus::micro_test_plus::detail::reporter_tap::fail_suite().

◆ operator<<() [1/9]

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( bool v)
Parameters
vThe 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.

Definition at line 725 of file reporter.cpp.

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

References reporter(), and buffer_.

◆ operator<<() [2/9]

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( char c)
Parameters
cThe character to output.
Returns
Reference to the current reporter instance.

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

Definition at line 688 of file reporter.cpp.

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

References reporter(), and buffer_.

◆ operator<<() [3/9]

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

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

Definition at line 703 of file reporter.cpp.

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

References reporter(), and buffer_.

◆ operator<<() [4/9]

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

Appends indent_size_ spaces for each indentation level.

Parameters
mThe indentation manipulator produced by indent(n).
Returns
Reference to the current reporter instance.

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

Definition at line 664 of file reporter.cpp.

666 {
667 buffer_.append (m.level * indent_size_, ' ');
668 return *this;
669 }
static constexpr size_t indent_size_
Number of spaces per nesting level.
Definition reporter.h:1263

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

◆ operator<<() [5/9]

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( reporter &(* func )(reporter &))
Parameters
funcFunction pointer to the stream manipulator.
Returns
Reference to the current reporter instance.

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

Definition at line 650 of file reporter.cpp.

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

References reporter().

◆ operator<<() [6/9]

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( std::nullptr_t )
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.

Definition at line 737 of file reporter.cpp.

739 {
740 buffer_.append ("nullptr");
741 return *this;
742 }

References reporter(), and buffer_.

◆ operator<<() [7/9]

reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( std::string_view sv)
Parameters
svThe string view to output.
Returns
Reference to the current reporter instance.

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

Definition at line 676 of file reporter.cpp.

678 {
679 buffer_.append (sv);
680 return *this;
681 }

References reporter(), and buffer_.

◆ operator<<() [8/9]

template<typename T>
requires (not std::is_same_v<T, char>)
reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( T * v)

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
TThe type pointed to, other than char.
Parameters
vThe 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.

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

81 {
83 return *this;
84 }
void append_pointer(std::string &buffer, T *v)
Appends the hexadecimal address of a pointer to a buffer.

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

◆ operator<<() [9/9]

template<class T>
requires std::is_arithmetic_v<T>
reporter & micro_os_plus::micro_test_plus::detail::reporter::operator<< ( T v)
Template Parameters
TThe arithmetic type.
Parameters
vThe value to output.
Returns
Reference to the current reporter instance.

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

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

98 {
100 return *this;
101 }
void append_number(std::string &buffer, T v)
Appends the shortest decimal representation of a numeric value to a buffer.

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

◆ output_fail_prefix()

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

Called by fail() before the expression text; the prefix includes the message, if any, and the source location.

Parameters
messageThe message to display.
has_expressionWhether the failure is associated with an expression.
locationThe source location of the failure.
test_caseThe test case that owns this check.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by fail().

◆ output_fail_suffix()

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

Called by fail() after the expression text, to complete the output. The kind of the check lets a reporter show that a failed requirement stops the test case, or aborts the test execution.

Parameters
locationThe source location of the failure.
kindThe kind of the check (expectation or requirement).
test_caseThe test case that owns this check.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by fail().

◆ output_pass_prefix()

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

Called by pass() before the expression text; the prefix includes the message, if any.

Parameters
messageThe message to display.
test_caseThe test case that owns this check.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by pass().

◆ output_pass_suffix()

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

Called by pass() after the expression text, to complete the line.

Parameters
test_caseThe test case that owns this check.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by pass().

◆ pass()

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

Definition at line 751 of file reporter.cpp.

753 {
754 output_pass_prefix (message, test_case);
755
756 if (message.empty ())
757 {
758 *this << expression;
759 }
760
762 }
virtual void output_pass_suffix(const test_case &test_case)=0
Outputs the suffix for a passing condition.
virtual void output_pass_prefix(const std::string &message, const test_case &test_case)=0
Outputs the prefix for a passing condition.

References micro_test_plus::test_case, output_pass_prefix(), and output_pass_suffix().

Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result(), and micro_test_plus::runner.

◆ pass_without_text()

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

Called by the destructor of check_result instead of pass(), for a passed check that was neither formatted nor described, since writes_passed_checks() returned false; the check has already been numbered and is counted by the caller. The TAP reporter records the test point, so that the plan of a test case displayed as a block matches its test points; the human-readable reporter does nothing.

Parameters
test_caseThe test case that owns this check.
Returns
Nothing.

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References fail(), and micro_test_plus::test_case.

Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result().

◆ route()

output_route micro_os_plus::micro_test_plus::detail::reporter::route ( record_kind kind) const
nodiscardprotectednoexcept

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

Definition at line 280 of file reporter.cpp.

281 {
282 bool console;
283 if (kind == record_kind::failed_check || kind == record_kind::total
284 || kind == record_kind::abort)
285 {
286 console = (verbosity_ != verbosity::silent);
287 }
288 else if (kind == record_kind::test_case_heading
289 || kind == record_kind::passed_check)
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 }
@ test_case_heading
The heading that marks the beginning of a test case.
Definition reporter.h:181
@ abort
The report of an aborted test execution.
Definition reporter.h:212
@ info
The informational lines written at the beginning of the session.
Definition reporter.h:166
@ failed_check
The lines of a failed check, or the failure of a suite.
Definition reporter.h:202

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, 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 verbosity_.

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

◆ skip_suite()

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

Called by runner::run_child_suites(), instead of running the suite, when its name does not match the first filter pattern; the suite has already been assigned its index. Implementations display a single line, without the suite body.

Parameters
suiteReference to the skipped test suite.
Returns
Nothing.
Since
6.0.0

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

◆ skip_test_case()

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

Called instead of begin_test_case() and end_test_case(), when the name of the test case, or of its suite, does not match the filter pattern of its level; the test case has already been assigned its index. Implementations display a single line, at the indentation of the test case.

Parameters
test_caseReference to the skipped test case.
Returns
Nothing.
Since
6.0.0

Implemented in micro_os_plus::micro_test_plus::detail::reporter_human, and micro_os_plus::micro_test_plus::detail::reporter_tap.

References micro_test_plus::test_case.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_test_case_create().

◆ verbosity()

auto micro_os_plus::micro_test_plus::detail::reporter::verbosity ( void ) const -> micro_test_plus::verbosity
inlinenodiscardnoexcept

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.
Deprecated
use runner::verbosity_level() (since 6.0.0)

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

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

111 {
112 return verbosity_;
113 }

References verbosity_.

Referenced by micro_test_plus::runner.

◆ write_buffer_to_file()

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

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

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.
434 }
void write_without_colours(FILE *file, std::string_view text)
Writes a text to a file, without the ANSI colour sequences.
Definition reporter.cpp:113

References buffer_, and output_file_.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session(), comment_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_tap::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case().

◆ write_console()

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

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

Definition at line 444 of file reporter.cpp.

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(), micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session(), announce_output_file(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_session(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_test_case(), comment_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_tap::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_human::display_open_heading(), micro_os_plus::micro_test_plus::detail::reporter_tap::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(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_session(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_human::skip_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::skip_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::skip_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::write_quiet_failures().

◆ write_console_text()

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

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

Definition at line 355 of file reporter.cpp.

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(), micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session(), comment_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_tap::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::write_quiet_failures().

◆ write_file()

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

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

Parameters
formatA 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.

Definition at line 458 of file reporter.cpp.

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 }

References output_file_.

Referenced by comment_prefix(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case().

◆ write_info()

void micro_os_plus::micro_test_plus::detail::reporter::write_info ( const std::vector< std::string > & arguments)
protected
Parameters
argumentsThe 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.

Definition at line 547 of file reporter.cpp.

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 }
void write_line(bool to_console, const char *format,...)
Writes formatted lines to the output file and, when requested, to the console.
Definition reporter.cpp:485
output_route route(record_kind kind) const noexcept
Tells where a kind of record is written.
Definition reporter.cpp:280
const char * extract_file_name(const char *path) noexcept
Extracts the file name component from a full path.
Definition utility.cpp:95
bool console
Whether the record is written to the console.
Definition reporter.h:229

References 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, route(), and write_line().

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

◆ write_line()

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

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_consoleWhether to write the text to stdout as well.
formatA 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.

Definition at line 485 of file reporter.cpp.

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 {
524 }
525
526 if (to_console)
527 {
528 fwrite (text.data (), 1, text.size (), stdout);
529 }
530 }

References output_file_.

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

◆ writes_passed_checks()

bool micro_os_plus::micro_test_plus::detail::reporter::writes_passed_checks ( void ) const
nodiscardnoexcept

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
trueThe lines of the passed checks reach the console or the output file, at least in some cases.
falseThe 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()).

Definition at line 320 of file reporter.cpp.

321 {
322 return output_file_ != nullptr || verbosity_ == verbosity::verbose;
323 }

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

Referenced by comment_prefix(), and micro_os_plus::micro_test_plus::test_case::report_misdirected().

◆ check_result

friend class check_result
friend

It formats its expression into the expression formatter, and retrieves the text when it reports the check.

Definition at line 293 of file reporter.h.

References check_result.

Referenced by check_result.

◆ micro_test_plus::runner

◆ micro_test_plus::test_case

friend class micro_test_plus::test_case
friend

It passes the expression formatter to the check results created by expect() and require().

Definition at line 284 of file reporter.h.

Referenced by begin_test_case(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_test_case(), end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case(), fail(), format_test_case_totals(), micro_test_plus::runner, micro_os_plus::micro_test_plus::detail::reporter_human::operator=(), micro_os_plus::micro_test_plus::detail::reporter_tap::operator=(), output_fail_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::output_fail_prefix(), micro_os_plus::micro_test_plus::detail::reporter_tap::output_fail_prefix(), output_fail_suffix(), micro_os_plus::micro_test_plus::detail::reporter_human::output_fail_suffix(), micro_os_plus::micro_test_plus::detail::reporter_tap::output_fail_suffix(), output_pass_prefix(), micro_os_plus::micro_test_plus::detail::reporter_human::output_pass_prefix(), micro_os_plus::micro_test_plus::detail::reporter_tap::output_pass_prefix(), output_pass_suffix(), micro_os_plus::micro_test_plus::detail::reporter_human::output_pass_suffix(), micro_os_plus::micro_test_plus::detail::reporter_tap::output_pass_suffix(), pass(), pass_without_text(), micro_os_plus::micro_test_plus::detail::reporter_human::pass_without_text(), micro_os_plus::micro_test_plus::detail::reporter_tap::pass_without_text(), skip_test_case(), micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::skip_test_case().

Member Data Documentation

◆ add_empty_line_

bool micro_os_plus::micro_test_plus::detail::reporter::add_empty_line_ { true }
protected

Set and cleared by the concrete reporters, to separate the groups of console lines, such as the suites and the failed test cases; the output file is not affected.

Definition at line 1434 of file reporter.h.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::abort_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::abort_session(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_session(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::begin_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::begin_test_case(), micro_os_plus::micro_test_plus::detail::reporter_human::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_tap::commit_buffer(), micro_os_plus::micro_test_plus::detail::reporter_human::display_open_heading(), micro_os_plus::micro_test_plus::detail::reporter_tap::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(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_session(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_human::skip_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::skip_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::skip_test_case(), and micro_os_plus::micro_test_plus::detail::reporter_tap::skip_test_case().

◆ buffer_

◆ buffer_has_failures_

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

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.

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

◆ colours_

◆ current_suite_

◆ elapsed_time_size_

size_t micro_os_plus::micro_test_plus::detail::reporter::elapsed_time_size_ = 40
staticconstexprprotected

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.

Referenced by micro_os_plus::micro_test_plus::detail::reporter_human::end_session(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_session(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), and format_elapsed_time().

◆ expression_

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

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

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.

Referenced by clear_buffer(), console_lines(), mark_failure(), and micro_os_plus::micro_test_plus::detail::reporter_tap::write_quiet_failures().

◆ has_output_file_error_

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

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 reporter(), and has_output_file_error().

◆ indent_size_

◆ open_test_cases_

◆ output_file_

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

When non-null, the report is written to this file in addition to the console, without colour sequences. The file receives the full report, regardless of the verbosity. The file is opened by the constructor and closed by the destructor.

Definition at line 1465 of file reporter.h.

Referenced by reporter(), ~reporter(), announce_output_file(), flush_streams(), route(), write_buffer_to_file(), write_file(), write_line(), and writes_passed_checks().

◆ output_file_path_

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

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.

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

◆ suite_displayed_

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

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.

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

◆ totals_size_

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

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.

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

◆ verbosity_

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

A copy of the level kept by the runner, set by the constructor from the same session options and not changed afterwards. The public accessor is runner::verbosity_level().

Definition at line 1273 of file reporter.h.

Referenced by reporter(), announce_output_file(), console_lines(), mark_failure(), micro_os_plus::micro_test_plus::detail::reporter_tap::pass_without_text(), route(), verbosity(), and writes_passed_checks().


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