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

Reporter to display test results, including operand values and types for failures. More...

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

Inheritance diagram for micro_os_plus::micro_test_plus::reporter:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Detailed Description

The reporter class is responsible for formatting and presenting test results within the µTest++ framework. It provides a comprehensive suite of output operators for a wide range of data types, containers, and comparator expressions, enabling detailed and informative reporting of test outcomes.

For failed tests, the reporter prints the actual values of the operands along with their types, supporting precise diagnostics and efficient debugging. The class supports multiple verbosity levels and colour-coded output to distinguish between successful and failed tests, thereby enhancing the clarity and professionalism of test reports.

The reporter also offers methods for reporting the commencement and completion of test cases and suites, as well as for handling pass and fail conditions. Additional features include output stream manipulators, support for exception-related expressions, and configurable formatting options.

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

Definition at line 185 of file reporter.h.

Constructor & Destructor Documentation

◆ reporter()

micro_os_plus::micro_test_plus::reporter::reporter ( std::unique_ptr< std::vector< std::string_view > > argvs)
Parameters
argvsOwning pointer to the command-line arguments vector; the reporter takes ownership via move.

Moves the supplied argument vector into argvs_ and scans it for the --verbose, --quiet, --silent, and --output-file= options, adjusting verbosity_ and optionally opening the output file. If the output file path is specified but the file cannot be opened, the process exits with a diagnostic error message. The internal string buffer is pre-allocated to reduce dynamic allocation overhead.

Definition at line 85 of file reporter.cpp.

86 {
87#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
88 trace::printf ("%s\n", __PRETTY_FUNCTION__);
89#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
90
91 std::string_view output_file_sv{};
92
93 argvs_ = std::move (argvs);
94
95 static constexpr std::string_view output_file_prefix{ "--output-file=" };
96 if (argvs_)
97 {
98 const auto& args = *argvs_;
99 for (size_t i = 0; i < args.size (); ++i)
100 {
101 if (args[i] == "--verbose")
102 {
104 }
105 else if (args[i] == "--quiet")
106 {
108 }
109 else if (args[i] == "--silent")
110 {
112 }
113 else if (args[i].starts_with (output_file_prefix))
114 {
115 output_file_sv = args[i].substr (output_file_prefix.size ());
116 }
117 else if (args[i]
118 == output_file_prefix.substr (
119 0, output_file_prefix.size () - 1))
120 {
121 if (i + 1 < args.size ())
122 {
123 output_file_sv = args[++i];
124 }
125 else
126 {
127 fprintf (stderr, "error: --output-file option requires a "
128 "file path argument\n");
129 exit (1);
130 }
131 }
132 }
133 }
134
135 if (!output_file_sv.empty ())
136 {
137 // .data() is safe: all string_views are views into argv[]
138 // entries, which are null-terminated C strings.
139 output_file_ = fopen (output_file_sv.data (), "w");
140 if (output_file_ == nullptr)
141 {
142#if defined(__GNUC__)
143#pragma GCC diagnostic push
144#if defined(__clang__)
145#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
146#endif
147#endif
148 fprintf (stderr, "error: Failed to open output file '%.*s'\n",
149 static_cast<int> (output_file_sv.size ()),
150 output_file_sv.data ());
151#if defined(__GNUC__)
152#pragma GCC diagnostic pop
153#endif
154 exit (1);
155 }
156 // The original string is zero terminated, so we can safely use .data()
157 // here.
158 output_file_path_ = output_file_sv.data ();
159 }
160
161 // Pre-allocate buffer to reduce dynamic allocations.
162 buffer_.reserve (128);
163 }
std::unique_ptr< std::vector< std::string_view > > argvs_
Owns the command-line arguments passed to the test runner.
Definition reporter.h:596
FILE * output_file_
Optional output file for redirecting test report output.
Definition reporter.h:591
std::string buffer_
Output accumulation buffer.
Definition reporter.h:552
const char * output_file_path_
Optional file path for redirecting test report output.
Definition reporter.h:581
enum verbosity verbosity_
The verbosity level for test reporting.
Definition reporter.h:537

References argvs_, buffer_, output_file_, output_file_path_, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::verbose, and verbosity_.

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

◆ ~reporter()

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

If an output file was opened, it is flushed and closed, and a confirmation message naming the output file is written to stdout. If tracing is enabled, the function signature is output for diagnostic purposes.

Definition at line 172 of file reporter.cpp.

173 {
174#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
175 trace::printf ("%s\n", __PRETTY_FUNCTION__);
176#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
177
178 if (output_file_ != nullptr)
179 {
180 fflush (output_file_);
181 fclose (output_file_);
182
183#if defined(__GNUC__)
184#pragma GCC diagnostic push
185#if defined(__clang__)
186#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
187#endif
188#endif
189 printf ("Test output written to '%s'.\n", output_file_path_);
190#if defined(__GNUC__)
191#pragma GCC diagnostic pop
192#endif
193
194 output_file_ = nullptr;
195 output_file_path_ = nullptr;
196 }
197 }

References output_file_, and output_file_path_.

Member Function Documentation

◆ begin_session()

virtual void micro_os_plus::micro_test_plus::reporter::begin_session ( runner & runner)
pure virtual
Parameters
runnerReference to the test runner.
Returns
Nothing.

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

◆ begin_subtest()

virtual void micro_os_plus::micro_test_plus::reporter::begin_subtest ( subtest & subtest)
pure virtual
Parameters
subtestReference to the subtest.
Returns
Nothing.

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

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

◆ begin_suite()

virtual void micro_os_plus::micro_test_plus::reporter::begin_suite ( suite & suite)
pure virtual
Parameters
suiteReference to the test suite.
Returns
Nothing.

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

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

◆ colour_()

auto micro_os_plus::micro_test_plus::reporter::colour_ ( const bool cond) const
inlinenodiscardprotected
Parameters
condBoolean value indicating pass (true) or fail (false).
Returns
The corresponding ANSI colour code as a string.

Returns the ANSI colour code for pass or fail, depending on the boolean condition provided.

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

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

References colours_.

Referenced by get_comment_prefix().

◆ end_session()

virtual void micro_os_plus::micro_test_plus::reporter::end_session ( runner & runner)
pure virtual
Parameters
runnerReference to the test runner.
Returns
Nothing.

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

◆ end_subtest()

virtual void micro_os_plus::micro_test_plus::reporter::end_subtest ( subtest & subtest)
pure virtual
Parameters
subtestReference to the subtest.
Returns
Nothing.

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

◆ end_suite()

virtual void micro_os_plus::micro_test_plus::reporter::end_suite ( suite & suite)
pure virtual
Parameters
suiteReference to the test suite.
Returns
Nothing.

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

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

◆ endline()

void micro_os_plus::micro_test_plus::reporter::endline ( void )
Parameters
None.
Returns
Nothing.

This method appends a newline character to the internal output buffer of the reporter and immediately flushes the stream. This ensures that each line of test output is clearly separated and promptly displayed, enhancing the readability and organisation of test results across all test cases and folders.

Definition at line 225 of file reporter.cpp.

226 {
227 buffer_.append ("\n");
228 flush ();
229 }
void flush(void)
Flush the current buffered content.
Definition reporter.cpp:371

References buffer_, and flush().

Referenced by micro_os_plus::micro_test_plus::endl().

◆ expression()

detail::expression_formatter & micro_os_plus::micro_test_plus::reporter::expression ( )
inline
Parameters
None.
Returns
Reference to the expression_formatter instance used by this reporter.

Returns a reference to the expression_formatter instance used by the reporter for formatting expressions in test reports. This allows the reporter to delegate the formatting of complex expressions to the expression_formatter, which provides a consistent and extensible way to convert various types of values and expressions into their string representations for output in test reports.

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

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

References expression_.

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

◆ fail()

void micro_os_plus::micro_test_plus::reporter::fail ( bool abort,
std::string & message,
const std::string & expression,
bool has_expression,
const reflection::source_location & location,
subtest & subtest )
Parameters
abortWhether to abort execution after failure.
messageThe message to display.
expressionThe string representation of the expression.
has_expressionWhether the expression is a compound op to display.
locationThe source location of the failure.
subtestThe subtest that owns this check.
Returns
Nothing.

Reports a test failure, formatting the output with source location and, when has_expression is true, the pre-formatted expression string.

Definition at line 469 of file reporter.cpp.

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

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

◆ flush()

void micro_os_plus::micro_test_plus::reporter::flush ( void )
Parameters
None.
Returns
Nothing.

This method flushes the output buffer of the reporter by synchronising it with the standard output stream. This guarantees that all pending test output is immediately written and visible, ensuring prompt and reliable reporting of test results across all test cases and folders.

Definition at line 371 of file reporter.cpp.

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

References output_file_.

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

◆ get_comment_prefix()

virtual const char * micro_os_plus::micro_test_plus::reporter::get_comment_prefix ( void )
pure virtual

◆ operator<<() [1/8]

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

References reporter().

◆ operator<<() [2/8]

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

This operator overload appends the specified character to the internal output buffer of the reporter. It enables efficient streaming of individual characters into the reporter, supporting precise and flexible formatting of test output across all test cases and folders.

Definition at line 421 of file reporter.cpp.

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

References reporter(), and buffer_.

◆ operator<<() [3/8]

reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( const char * s)
Parameters
sThe string to output.
Returns
Reference to the current reporter instance.

This operator overload appends the contents of the provided C-style string to the internal output buffer of the reporter. It enables efficient streaming of string literals and character arrays into the reporter, supporting clear and flexible formatting of test output across all test cases and folders.

Definition at line 436 of file reporter.cpp.

438 {
439 buffer_.append (s);
440 return *this;
441 }

References reporter(), and buffer_.

◆ operator<<() [4/8]

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

This operator overload enables manipulators, such as endl, to be used with the reporter stream in a manner similar to standard C++ streams. When a manipulator function is passed, it is invoked with the current reporter instance, allowing for seamless integration of stream operations and improved readability of test output across all test cases and folders.

Definition at line 391 of file reporter.cpp.

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

References reporter().

◆ operator<<() [5/8]

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

References reporter(), and expression().

◆ operator<<() [6/8]

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

This operator overload appends the contents of the provided std::string_view to the internal output buffer of the reporter. It enables seamless streaming of string data into the reporter, supporting clear and efficient formatting of test output across all test cases and folders.

Definition at line 407 of file reporter.cpp.

409 {
410 buffer_.append (sv);
411 return *this;
412 }

References reporter(), and buffer_.

◆ operator<<() [7/8]

template<typename T>
reporter & micro_os_plus::micro_test_plus::reporter::operator<< ( T * v)
Template Parameters
TThe type of the pointer.
Parameters
vThe pointer value to output.
Returns
Reference to the current reporter instance.

This operator overload enables the reporter to output pointer values in a consistent and readable format.

Null pointers are always rendered as the string "nullptr", regardless of the platform, avoiding platform-specific behaviour such as "(nil)" on Linux/glibc or "0x0" on macOS.

Non-null pointers are formatted as a hexadecimal address using snprintf with the p format specifier. The resulting string is appended to the internal output buffer, allowing pointer values to be included in test reports and diagnostics.

This approach provides clear and unambiguous representation of pointer addresses, which is particularly useful for debugging and verifying pointer-related test cases.

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

146 {
147 if (v == nullptr)
148 {
149 // Explicitly render null pointers as "0x0" to avoid platform-specific
150 // representations such as "(nil)" on Linux/glibc.
151 buffer_.append ("0x0");
152 return *this;
153 }
154#if defined(__GNUC__)
155#pragma GCC diagnostic push
156#if defined(__clang__)
157#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
158#endif
159#endif
160 char buff[20];
161 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
162 buffer_.append (buff);
163#if defined(__GNUC__)
164#pragma GCC diagnostic pop
165#endif
166
167 return *this;
168 }

References reporter(), and buffer_.

◆ operator<<() [8/8]

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

This template operator overload allows the reporter to output values of any arithmetic type (integral or floating-point) in a consistent and readable format. The value is formatted using the append_number_ helper function, which handles the conversion to a string representation with appropriate type suffixes where applicable (e.g., "f" for float, "l" for long double). This enables numeric values to be included in test reports and diagnostics in a clear and unambiguous manner, supporting the verification of test cases that involve arithmetic expressions and comparisons.

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

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

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

◆ output_fail_prefix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_fail_prefix_ ( std::string & message,
const bool has_expression,
const reflection::source_location & location,
subtest & subtest )
protectedpure virtual
Parameters
messageThe message to display.
has_expressionWhether the failure is associated with an expression.
locationThe source location of the failure.
subtestThe subtest that owns this check.
Returns
Nothing.

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

References output_fail_prefix_().

Referenced by fail(), and output_fail_prefix_().

◆ output_fail_suffix_()

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

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

References output_fail_suffix_().

Referenced by fail(), and output_fail_suffix_().

◆ output_pass_prefix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_pass_prefix_ ( std::string & message,
subtest & subtest )
protectedpure virtual
Parameters
messageThe message to display.
subtestThe subtest that owns this check.
Returns
Nothing.

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

References output_pass_prefix_().

Referenced by output_pass_prefix_(), and pass().

◆ output_pass_suffix_()

virtual void micro_os_plus::micro_test_plus::reporter::output_pass_suffix_ ( subtest & subtest)
protectedpure virtual
Parameters
subtestThe subtest that owns this check.
Returns
Nothing.

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

References output_pass_suffix_().

Referenced by output_pass_suffix_(), and pass().

◆ pass()

void micro_os_plus::micro_test_plus::reporter::pass ( std::string & message,
const std::string & expression,
subtest & subtest )
Parameters
messageThe message to display.
expressionThe string representation of the expression.
subtestThe subtest that owns this check.
Returns
Nothing.

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

Definition at line 450 of file reporter.cpp.

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

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

◆ verbosity()

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

Returns the verbosity level stored in verbosity_.

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

93 {
94 return verbosity_;
95 }

References verbosity(), and verbosity_.

Referenced by get_comment_prefix(), and verbosity().

◆ write_buffer_to_file_()

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

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

Definition at line 254 of file reporter.cpp.

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

References buffer_, and output_file_.

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

◆ write_buffer_to_stdout()

void micro_os_plus::micro_test_plus::reporter::write_buffer_to_stdout ( void )
Note
Public because deferred_reporter_base calls this from its destructor when aborting, after the subtest instance is no longer accessible via the normal reporting path.
Parameters
None.
Returns
Nothing.

This method writes the contents of the internal output buffer to the standard output stream without appending a newline character. After outputting the buffer, it is cleared to prepare for subsequent output. This approach ensures that test results are presented promptly and efficiently, supporting clear and organised reporting across all test cases and folders.

Definition at line 241 of file reporter.cpp.

242 {
243 // Pass only the string, do not add an `\n` here.
244 printf ("%s", buffer_.c_str ());
245 }

References buffer_.

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

◆ write_info_()

void micro_os_plus::micro_test_plus::reporter::write_info_ ( void )
protected
Parameters
None.
Returns
Nothing.

Constructs and emits two informational lines: the first lists the programme name and any command-line arguments; the second identifies the compiler (Clang, GCC, or MSVC) together with the version string, floating-point availability on bare-metal targets, exception support, and any active debug or trace macros. Both lines are written to the output file when one is open, and to stdout unless verbosity is set to silent.

Definition at line 274 of file reporter.cpp.

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

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

Member Data Documentation

◆ add_empty_line_

◆ argvs_

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

Definition at line 596 of file reporter.h.

596{};

Referenced by reporter(), and micro_os_plus::micro_test_plus::reporter_human::operator<<().

◆ buffer_

◆ colours_

◆ expression_

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

Used in pass() and fail() to format expression values before appending the result to buffer_. Will also be used by detail::deferred_reporter to pre-format expressions at construction time.

Definition at line 563 of file reporter.h.

563{ colours_ };

Referenced by expression().

◆ output_file_

◆ output_file_path_

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

When non-null, write_buffer_to_file_() writes accumulated output to this path in addition to (or instead of) standard output.

Definition at line 581 of file reporter.h.

581{ nullptr };

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

◆ verbosity_


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