Skip to main content

test_reporter_tap Class

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

Declaration

class micro_os_plus::micro_test_plus::test_reporter_tap { ... }

Included Headers

Base class

classtest_reporter

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

Public Constructors Index

test_reporter_tap ()=default

Default constructor for the test_reporter_tap class. More...

test_reporter_tap (const test_reporter_tap &)=delete

Deleted copy constructor to prevent copying. More...

test_reporter_tap (test_reporter_tap &&)=delete

Deleted move constructor to prevent moving. More...

Public Destructor Index

~test_reporter_tap () override=default

Destructor for the test_reporter_tap class. More...

Public Operators Index

test_reporter &operator<< (bool v)

Output operator for boolean values. More...

test_reporter &operator<< (char *s)

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

test_reporter &operator<< (char c)

Output operator for a single character. More...

test_reporter &operator<< (const char *s)

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

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::and_< Lhs_T, Rhs_T > &op)

Output operator to display and() expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::eq_< Lhs_T, Rhs_T > &op)

Output operator to display eq() expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::ge_< Lhs_T, Rhs_T > &op)

Output operator to display ge() expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::gt_< Lhs_T, Rhs_T > &op)

Output operator to display gt() expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::le_< Rhs_T, Lhs_T > &op)

Output operator to display le() expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::lt_< Rhs_T, Lhs_T > &op)

Output operator to display lt() expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::ne_< Lhs_T, Rhs_T > &op)

Output operator to display ne() expressions. More...

template <class T>
test_reporter &operator<< (const detail::not_< T > &op)

Output operator to display not() expressions. More...

template <class Expr_T>
test_reporter &operator<< (const detail::nothrow_< Expr_T > &op)

Output operator to display nothrow expressions. More...

template <class Lhs_T, class Rhs_T>
test_reporter &operator<< (const detail::or_< Lhs_T, Rhs_T > &op)

Output operator to display or() expressions. More...

template <class Expr_T, class Exception_T>
test_reporter &operator<< (const detail::throws_< Expr_T, Exception_T > &op)

Output operator to display throws expressions for a specific exception type. More...

template <class Expr_T>
test_reporter &operator<< (const detail::throws_< Expr_T, void > &op)

Output operator to display throws expressions for any exception. More...

template <class T>
test_reporter &operator<< (const T &t)

Output operator for types with a getter. More...

template <class T>
test_reporter &operator<< (const type_traits::genuine_integral_value< T > &v)

Output operator to display genuine integers, without the type suffix. More...

test_reporter &operator<< (double v)

Output operator for double values. More...

test_reporter &operator<< (float v)

Output operator for float values. More...

test_reporter &operator<< (long double v)

Output operator for long double values. More...

test_reporter &operator<< (signed char c)

Output operator for signed char values. More...

test_reporter &operator<< (signed int v)

Output operator for signed int values. More...

test_reporter &operator<< (signed long long v)

Output operator for signed long long values. More...

test_reporter &operator<< (signed long v)

Output operator for signed long values. More...

test_reporter &operator<< (signed short v)

Output operator for signed short values. More...

test_reporter &operator<< (std::nullptr_t)

Output operator for nullptr. More...

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

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

template < ... >
test_reporter &operator<< (T &&t)

Output operator to display containers. Iterates all members. More...

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

Output operator to display any pointer. More...

test_reporter &operator<< (test_reporter &(*func)(test_reporter &))

Output operator to display the endl. More...

test_reporter &operator<< (unsigned char c)

Output operator for unsigned char values. More...

test_reporter &operator<< (unsigned int v)

Output operator for unsigned int values. More...

test_reporter &operator<< (unsigned long long v)

Output operator for unsigned long long values. More...

test_reporter &operator<< (unsigned long v)

Output operator for unsigned long values. More...

test_reporter &operator<< (unsigned short v)

Output operator for unsigned short values. More...

test_reporter_tap &operator= (const test_reporter_tap &)=delete

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

test_reporter_tap &operator= (test_reporter_tap &&)=delete

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

Public Member Functions Index

voidbegin_test (size_t test_suites_count) override

Mark the beginning of a test. More...

voidbegin_test_case (const char *name) override

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

voidbegin_test_suite (const char *name) override

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

autocolor (const bool cond)

Selects the appropriate colour code based on a condition. More...

voidend_test (test_runner &runner) override

Mark the end of a test. More...

voidend_test_case (const char *name) override

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

voidend_test_suite (test_suite_base &suite) override

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

voidendline (void) override

Inserts a line ending into the output buffer. More...

template <class Expr_T>
voidfail (Expr_T &expr, bool abort, std::string &message, const reflection::source_location &location)

Report a failed condition. More...

voidflush (void) override

Flush the current buffered content. More...

voidoutput (void) override

Output the current buffered content. More...

template <class Expr_T>
voidpass (Expr_T &expr, std::string &message)

Report a passed condition. More...

Protected Member Functions Index

voidoutput_fail_prefix_ (std::string &message, const bool hasExpression, const reflection::source_location &location) override

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

voidoutput_fail_suffix_ (const reflection::source_location &location, bool abort) override

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

voidoutput_pass_prefix_ (std::string &message) override

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

voidoutput_pass_suffix_ (void) override

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

Public Member Attributes Index

booladd_empty_line { true }

Controls whether to add an empty line between successful test cases. More...

verbosity_tverbosity {}

The verbosity level for test reporting. More...

Protected Member Attributes Index

colorscolors_ {}

ANSI colour codes for output formatting. More...

boolis_in_test_case_ = false

Indicates whether the reporter is currently within a test case. More...

std::stringout_ {}

Internal output buffer for accumulating report content. More...

Description

TAP (Test Anything Protocol) implementation of test_reporter.

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

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

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

Definition at line 84 of file test-reporter-tap.h.

Public Constructors

test_reporter_tap()

micro_os_plus::micro_test_plus::test_reporter_tap::test_reporter_tap ()
default

Default constructor for the test_reporter_tap class.

The rule of five is enforced to prevent accidental copying or moving.

Definition at line 93 of file test-reporter-tap.h.

Referenced by test_reporter_tap, test_reporter_tap, operator= and operator=.

test_reporter_tap()

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

Deleted copy constructor to prevent copying.

Definition at line 98 of file test-reporter-tap.h.

Reference test_reporter_tap.

test_reporter_tap()

micro_os_plus::micro_test_plus::test_reporter_tap::test_reporter_tap (test_reporter_tap &&)
delete

Deleted move constructor to prevent moving.

Definition at line 103 of file test-reporter-tap.h.

Reference test_reporter_tap.

Public Destructor

~test_reporter_tap()

micro_os_plus::micro_test_plus::test_reporter_tap::~test_reporter_tap ()
default

Destructor for the test_reporter_tap class.

Definition at line 122 of file test-reporter-tap.h.

Reference micro_os_plus::micro_test_plus::runner.

Public Operators

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (bool v)

Output operator for boolean values.

Parameters
v

The boolean value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified boolean value to the internal output buffer of the test_reporter. It enables clear and direct streaming of boolean results into the reporter, supporting precise and readable formatting of test output across all test cases and folders.

Declaration at line 268 of file test-reporter.h, definition at line 169 of file test-reporter.cpp.

170 {
171 out_.append (v ? "true" : "false");
172 return *this;
173 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (char * s)

Output operator for a mutable character string.

Parameters
s

The string to output.

Returns

Reference to the current test_reporter instance.

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

Declaration at line 259 of file test-reporter.h, definition at line 154 of file test-reporter.cpp.

155 {
156 out_.append (s);
157 return *this;
158 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (char c)

Output operator for a single character.

Parameters
c

The character to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the specified character to the internal output buffer of the test_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.

Declaration at line 241 of file test-reporter.h, definition at line 124 of file test-reporter.cpp.

125 {
126 out_.append (1, c);
127 return *this;
128 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

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

Output operator for a constant character string.

Parameters
s

The string to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the contents of the provided C-style string to the internal output buffer of the test_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.

Declaration at line 250 of file test-reporter.h, definition at line 139 of file test-reporter.cpp.

139 test_reporter::operator<<(const char* s)
140 {
141 out_.append (s);
142 return *this;
143 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::and_< Lhs_T, Rhs_T > & op)

Output operator to display and() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The logical conjunction (AND) expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output logical conjunction (AND) expressions in a clear and structured format.

The left-hand side and right-hand side expressions are enclosed in parentheses and separated by the word "and", with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This presentation assists in quickly identifying the components of logical assertions and facilitates efficient debugging of test failures involving compound conditions.

Declaration at line 546 of file test-reporter.h, definition at line 306 of file test-reporter-inlines.h.

307 {
308 return (*this << '(' << op.lhs () << color (op) << " and " << colors_.none
309 << op.rhs () << ')');
310 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::and_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::and_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::eq_< Lhs_T, Rhs_T > & op)

Output operator to display eq() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The equality comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output equality comparison expressions in a clear and expressive format.

The left-hand side and right-hand side values are formatted and separated by the equality operator (==), with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This structured output assists in quickly identifying the values involved in equality assertions and facilitates efficient debugging of test failures.

Declaration at line 468 of file test-reporter.h, definition at line 185 of file test-reporter-inlines.h.

186 {
187 return (*this << color (op) << op.lhs () << " == " << op.rhs ()
188 << colors_.none);
189 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::ge_< Lhs_T, Rhs_T > & op)

Output operator to display ge() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The greater-than-or-equal-to comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output greater-than-or-equal-to comparison expressions in a clear and expressive format.

The left-hand side and right-hand side values are formatted and separated by the greater-than-or-equal-to operator (>=), with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This structured output assists in quickly identifying the values involved in greater-than-or-equal-to assertions and facilitates efficient debugging of test failures.

Declaration at line 507 of file test-reporter.h, definition at line 246 of file test-reporter-inlines.h.

247 {
248 return (*this << color (op) << op.lhs () << " >= " << op.rhs ()
249 << colors_.none);
250 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::ge_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::ge_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::gt_< Lhs_T, Rhs_T > & op)

Output operator to display gt() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The greater-than comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output greater-than comparison expressions in a clear and expressive format.

The left-hand side and right-hand side values are formatted and separated by the greater-than operator (>), with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This structured output assists in quickly identifying the values involved in greater-than assertions and facilitates efficient debugging of test failures.

Declaration at line 494 of file test-reporter.h, definition at line 225 of file test-reporter-inlines.h.

226 {
227 return (*this << color (op) << op.lhs () << " > " << op.rhs ()
228 << colors_.none);
229 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::gt_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::gt_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::le_< Rhs_T, Lhs_T > & op)

Output operator to display le() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The less-than-or-equal-to comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output less-than-or-equal-to comparison expressions in a clear and expressive format.

The left-hand side and right-hand side values are formatted and separated by the less-than-or-equal-to operator (<=), with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This structured output assists in quickly identifying the values involved in less-than-or-equal-to assertions and facilitates efficient debugging of test failures.

Declaration at line 533 of file test-reporter.h, definition at line 286 of file test-reporter-inlines.h.

287 {
288 return (*this << color (op) << op.lhs () << " <= " << op.rhs ()
289 << colors_.none);
290 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::le_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::le_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::lt_< Rhs_T, Lhs_T > & op)

Output operator to display lt() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The less-than comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output less-than comparison expressions in a clear and expressive format.

The left-hand side and right-hand side values are formatted and separated by the less-than operator (<), with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This structured output assists in quickly identifying the values involved in less-than assertions and facilitates efficient debugging of test failures.

Declaration at line 520 of file test-reporter.h, definition at line 265 of file test-reporter-inlines.h.

266 {
267 return (*this << color (op) << op.lhs () << " < " << op.rhs ()
268 << colors_.none);
269 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::lt_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::lt_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::ne_< Lhs_T, Rhs_T > & op)

Output operator to display ne() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The inequality comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output inequality comparison expressions in a clear and expressive format.

The left-hand side and right-hand side values are formatted and separated by the inequality operator (!=), with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This structured output assists in quickly identifying the values involved in inequality assertions and facilitates efficient debugging of test failures.

Declaration at line 481 of file test-reporter.h, definition at line 205 of file test-reporter-inlines.h.

206 {
207 return (*this << color (op) << op.lhs () << " != " << op.rhs ()
208 << colors_.none);
209 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::ne_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::ne_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::not_< T > & op)

Output operator to display not() expressions.

Template Parameters
T

The operand type.

Parameters
op

The logical negation expression.

Returns

Reference to the current test_reporter instance.

This operator overload enhances readability and clarity by formatting the output when handling negated expressions. It applies colour styling for improved distinction and appends the negated value accordingly, ensuring that logical negations are clearly represented in test reports and diagnostics.

Declaration at line 571 of file test-reporter.h, definition at line 342 of file test-reporter-inlines.h.

343 {
344 return (*this << color (op) << "not " << op.value () << colors_.none);
345 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_ and micro_os_plus::micro_test_plus::detail::not_< T >::value.

operator<<()

template <class Expr_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::nothrow_< Expr_T > & op)

Output operator to display nothrow expressions.

Template Parameters
Expr_T

The expression type.

Parameters
op

The nothrow comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload formats output for expressions that do not throw exceptions. It applies colour styling for clarity and ensures a structured and concise representation of exception safety within test reports.

The output highlights the nothrow qualifier, making it immediately apparent when an expression is guaranteed not to throw, thereby improving the readability and professionalism of the test output.

Declaration at line 610 of file test-reporter.h, definition at line 398 of file test-reporter-inlines.h.

399 {
400 return (*this << color (op) << "nothrow" << colors_.none);
401 }

References micro_os_plus::micro_test_plus::test_reporter::color and micro_os_plus::micro_test_plus::test_reporter::colors_.

operator<<()

template <class Lhs_T, class Rhs_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::or_< Lhs_T, Rhs_T > & op)

Output operator to display or() expressions.

Template Parameters
Lhs_T

The left-hand side type.

Rhs_T

The right-hand side type.

Parameters
op

The logical disjunction (OR) expression.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output logical disjunction (OR) expressions in a clear and structured format.

The left-hand side and right-hand side expressions are enclosed in parentheses and separated by the word "or", with appropriate colour highlighting applied for improved readability in test reports and diagnostics. This presentation assists in quickly identifying the components of logical assertions and facilitates efficient debugging of test failures involving compound conditions.

Declaration at line 559 of file test-reporter.h, definition at line 326 of file test-reporter-inlines.h.

327 {
328 return (*this << '(' << op.lhs () << color (op) << " or " << colors_.none
329 << op.rhs () << ')');
330 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_, micro_os_plus::micro_test_plus::detail::or_< Lhs_T, Rhs_T >::lhs and micro_os_plus::micro_test_plus::detail::or_< Lhs_T, Rhs_T >::rhs.

operator<<()

template <class Expr_T, class Exception_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::throws_< Expr_T, Exception_T > & op)

Output operator to display throws expressions for a specific exception type.

Template Parameters
Expr_T

The expression type.

Exception_T

The exception type.

Parameters
op

The throws comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload provides structured output for expressions that may throw exceptions. It applies colour styling for clarity and includes the exception type name for precise identification.

When invoked, the output highlights the throws qualifier along with the specific exception type, making it immediately apparent which exception is expected. This enhances the readability and professionalism of test reports, and assists in the precise identification and debugging of exception-related test cases.

Declaration at line 586 of file test-reporter.h, definition at line 362 of file test-reporter-inlines.h.

363 {
364 return (*this << color (op) << "throws<"
366 << colors_.none);
367 }

References micro_os_plus::micro_test_plus::test_reporter::color, micro_os_plus::micro_test_plus::test_reporter::colors_ and micro_os_plus::micro_test_plus::reflection::type_name.

operator<<()

template <class Expr_T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const detail::throws_< Expr_T, void > & op)

Output operator to display throws expressions for any exception.

Template Parameters
Expr_T

The expression type.

Parameters
op

The throws comparator expression.

Returns

Reference to the current test_reporter instance.

This operator overload formats output for expressions that may throw exceptions. It applies colour styling for clarity and ensures a structured representation of the exception handling mechanism.

When invoked, the output highlights the throws qualifier, making it immediately apparent when an expression is expected to throw, thereby improving the readability and professionalism of the test output.

Declaration at line 598 of file test-reporter.h, definition at line 381 of file test-reporter-inlines.h.

382 {
383 return (*this << color (op) << "throws" << colors_.none);
384 }

References micro_os_plus::micro_test_plus::test_reporter::color and micro_os_plus::micro_test_plus::test_reporter::colors_.

operator<<()

template <class T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const T & t)

Output operator for types with a getter.

Template Parameters
T

The type with a getter method.

Parameters
t

The object to output.

Returns

Reference to the current test_reporter instance.

Definition at line 427 of file test-reporter.h.

Reference micro_os_plus::micro_test_plus::type_traits::has_npos_v.

operator<<()

template <class T>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (const type_traits::genuine_integral_value< T > & v)

Output operator to display genuine integers, without the type suffix.

Template Parameters
T

The underlying integral type.

Parameters
v

The strongly-typed integral value to output.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output strongly-typed integral values in a clear and consistent decimal format.

The value is converted to a string using std::to_string after being cast to long long, ensuring accurate formatting and compatibility across platforms. The resulting string is appended to the internal output buffer, allowing integral values to be included in test reports and diagnostics.

This approach ensures precise and unambiguous representation of integral values, which is particularly advantageous for verifying test results and facilitating debugging.

Declaration at line 440 of file test-reporter.h, definition at line 135 of file test-reporter-inlines.h.

136 {
137 out_.append (std::to_string (static_cast<long long> (v.get ())));
138 return *this;
139 }

References micro_os_plus::micro_test_plus::type_traits::genuine_integral_value< T >::get and micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (double v)

Output operator for double values.

Parameters
v

The double value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified double-precision floating-point value to the internal output buffer of the test_reporter. It enables precise and readable streaming of double values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 382 of file test-reporter.h, definition at line 373 of file test-reporter.cpp.

374 {
375 out_.append (std::to_string (v));
376 return *this;
377 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (float v)

Output operator for float values.

Parameters
v

The float value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified floating-point value to the internal output buffer of the test_reporter, followed by the character 'f' to indicate a float type. It enables precise and readable streaming of float values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 373 of file test-reporter.h, definition at line 357 of file test-reporter.cpp.

358 {
359 out_.append (std::to_string (v));
360 out_.append ("f");
361 return *this;
362 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (long double v)

Output operator for long double values.

Parameters
v

The long double value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified long double-precision floating-point value to the internal output buffer of the test_reporter, followed by the character 'l' to indicate a long double type. It enables precise and readable streaming of long double values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 391 of file test-reporter.h, definition at line 389 of file test-reporter.cpp.

389 test_reporter::operator<<(long double v)
390 {
391 out_.append (std::to_string (v));
392 out_.append ("l");
393 return *this;
394 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (signed char c)

Output operator for signed char values.

Parameters
c

The signed char value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified signed character to the internal output buffer of the test_reporter. It enables precise and readable streaming of character values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 283 of file test-reporter.h, definition at line 198 of file test-reporter.cpp.

198 test_reporter::operator<<(signed char c)
199 {
200 out_.append (std::to_string (c));
201 out_.append ("c");
202 return *this;
203 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (signed int v)

Output operator for signed int values.

Parameters
v

The signed int value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified signed integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of signed integer values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 319 of file test-reporter.h, definition at line 262 of file test-reporter.cpp.

262 test_reporter::operator<<(signed int v)
263 {
264 out_.append (std::to_string (v));
265 return *this;
266 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (signed long long v)

Output operator for signed long long values.

Parameters
v

The signed long long value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified signed long long integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of signed long long values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 355 of file test-reporter.h, definition at line 325 of file test-reporter.cpp.

325 test_reporter::operator<<(signed long long v)
326 {
327 out_.append (std::to_string (v));
328 out_.append ("ll");
329 return *this;
330 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (signed long v)

Output operator for signed long values.

Parameters
v

The signed long value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified signed long integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of signed long values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 337 of file test-reporter.h, definition at line 293 of file test-reporter.cpp.

293 test_reporter::operator<<(signed long v)
294 {
295 out_.append (std::to_string (v));
296 out_.append ("l");
297 return *this;
298 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (signed short v)

Output operator for signed short values.

Parameters
v

The signed short value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified signed short integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of signed short values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 301 of file test-reporter.h, definition at line 230 of file test-reporter.cpp.

230 test_reporter::operator<<(signed short v)
231 {
232 out_.append (std::to_string (v));
233 out_.append ("s");
234 return *this;
235 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (std::nullptr_t)

Output operator for nullptr.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string "nullptr" to the internal output buffer of the test_reporter. It enables clear and explicit streaming of null pointer values into the reporter, supporting precise and readable formatting of test output across all test cases and folders.

Declaration at line 275 of file test-reporter.h, definition at line 183 of file test-reporter.cpp.

183 test_reporter::operator<<(std::nullptr_t)
184 {
185 out_.append ("nullptr");
186 return *this;
187 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (std::string_view sv)

Output operator for std::string_view.

Parameters
sv

The string view to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the contents of the provided std::string_view to the internal output buffer of the test_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.

Declaration at line 232 of file test-reporter.h, definition at line 110 of file test-reporter.cpp.

110 test_reporter::operator<<(std::string_view sv)
111 {
112 out_.append (sv);
113 return *this;
114 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

template <class T, type_traits::requires_t< type_traits::is_container_v< T > and not type_traits::has_npos_v< T > > = 0>
test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (T && t)

Output operator to display containers. Iterates all members.

Template Parameters
T

The container type.

Parameters
t

The container to output.

Returns

Reference to the current test_reporter instance.

This operator overload enables the test_reporter to output container types in a structured and readable format.

The contents of the container are enclosed in curly braces and each element is separated by a comma and a space. The operator iterates over the container, formatting each element in sequence, which ensures clarity and consistency in test reports and diagnostics.

This approach provides a clear visual representation of container contents, making it easier to interpret test results and debug issues involving collections of values.

Declaration at line 455 of file test-reporter.h, definition at line 159 of file test-reporter-inlines.h.

160 {
161 *this << '{';
162 auto first = true;
163 for (const auto& arg : t)
164 {
165 *this << (first ? "" : ", ") << arg;
166 first = false;
167 }
168 *this << '}';
169 return *this;
170 }

operator<<()

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

Output operator to display any pointer.

Template Parameters
T

The type of the pointer.

Parameters
v

The pointer value to output.

Returns

Reference to the current test_reporter instance.

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

The pointer is formatted as a string using snprintf with the p format specifier, ensuring portability across platforms. 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.

Declaration at line 403 of file test-reporter.h, definition at line 92 of file test-reporter-inlines.h.

93 {
94 char buff[20];
95 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
96 out_.append (buff);
97
98 return *this;
99 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (test_reporter &(*)(test_reporter &) func)

Output operator to display the endl.

Parameters
func

Function pointer to the stream manipulator.

Returns

Reference to the current test_reporter instance.

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

Declaration at line 412 of file test-reporter.h, definition at line 94 of file test-reporter.cpp.

95 {
96 // Call the endl function.
97 (*func) (*this);
98 return *this;
99 }

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (unsigned char c)

Output operator for unsigned char values.

Parameters
c

The unsigned char value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified unsigned character to the internal output buffer of the test_reporter. It enables precise and readable streaming of unsigned character values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 292 of file test-reporter.h, definition at line 214 of file test-reporter.cpp.

214 test_reporter::operator<<(unsigned char c)
215 {
216 out_.append (std::to_string (static_cast<int> (c)));
217 out_.append ("uc");
218 return *this;
219 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (unsigned int v)

Output operator for unsigned int values.

Parameters
v

The unsigned int value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified unsigned integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of unsigned integer values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 328 of file test-reporter.h, definition at line 277 of file test-reporter.cpp.

277 test_reporter::operator<<(unsigned int v)
278 {
279 out_.append (std::to_string (v));
280 out_.append ("u");
281 return *this;
282 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (unsigned long long v)

Output operator for unsigned long long values.

Parameters
v

The unsigned long long value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified unsigned long long integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of unsigned long long values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 364 of file test-reporter.h, definition at line 341 of file test-reporter.cpp.

341 test_reporter::operator<<(unsigned long long v)
342 {
343 out_.append (std::to_string (v));
344 out_.append ("ull");
345 return *this;
346 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (unsigned long v)

Output operator for unsigned long values.

Parameters
v

The unsigned long value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified unsigned long integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of unsigned long values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 346 of file test-reporter.h, definition at line 309 of file test-reporter.cpp.

309 test_reporter::operator<<(unsigned long v)
310 {
311 out_.append (std::to_string (v));
312 out_.append ("ul");
313 return *this;
314 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator<<()

test_reporter & micro_os_plus::micro_test_plus::test_reporter::operator<< (unsigned short v)

Output operator for unsigned short values.

Parameters
v

The unsigned short value to output.

Returns

Reference to the current test_reporter instance.

This operator overload appends the string representation of the specified unsigned short integer to the internal output buffer of the test_reporter. It enables precise and readable streaming of unsigned short values into the reporter, supporting clear formatting of test output across all test cases and folders.

Declaration at line 310 of file test-reporter.h, definition at line 246 of file test-reporter.cpp.

246 test_reporter::operator<<(unsigned short v)
247 {
248 out_.append (std::to_string (static_cast<long> (v)));
249 out_.append ("us");
250 return *this;
251 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

operator=()

test_reporter_tap & micro_os_plus::micro_test_plus::test_reporter_tap::operator= (const test_reporter_tap &)
delete

Deleted copy assignment operator to prevent copying.

Definition at line 109 of file test-reporter-tap.h.

Reference test_reporter_tap.

operator=()

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

Deleted move assignment operator to prevent moving.

Definition at line 116 of file test-reporter-tap.h.

Reference test_reporter_tap.

Public Member Functions

begin_test()

void micro_os_plus::micro_test_plus::test_reporter_tap::begin_test (size_t test_suites_count)
virtual

Mark the beginning of a test.

Parameters
test_suites_count

The number of test suites, or zero if unknown.

Returns

Nothing.

Declaration at line 183 of file test-reporter-tap.h, definition at line 460 of file test-reporter-tap.cpp.

460 test_reporter_tap::begin_test (size_t test_suites_count)
461 {
463 {
464 printf ("\nTAP version 14\n");
465 printf ("1..%zu\n", test_suites_count ? test_suites_count : 1);
466 flush ();
467 }
468 add_empty_line = false;
469 }

References micro_os_plus::micro_test_plus::test_reporter::add_empty_line, flush, micro_os_plus::micro_test_plus::silent and micro_os_plus::micro_test_plus::test_reporter::verbosity.

begin_test_case()

void micro_os_plus::micro_test_plus::test_reporter_tap::begin_test_case (const char * name)
virtual

Mark the beginning of a test case.

Parameters
name

The name of the test case.

Returns

Nothing.

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

Declaration at line 143 of file test-reporter-tap.h, definition at line 219 of file test-reporter-tap.cpp.

219 test_reporter_tap::begin_test_case ([[maybe_unused]] const char* name)
220 {
221 is_in_test_case_ = true;
222
223 if (!out_.empty () && (verbosity == verbosity::verbose))
224 {
226 {
227 printf ("\n");
228 }
229 output ();
230 add_empty_line = true;
231 }
232
233 out_.clear ();
234
235 flush ();
236 }

References micro_os_plus::micro_test_plus::test_reporter::add_empty_line, flush, micro_os_plus::micro_test_plus::test_reporter::is_in_test_case_, micro_os_plus::micro_test_plus::test_reporter::out_, output, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::test_reporter::verbosity.

begin_test_suite()

void micro_os_plus::micro_test_plus::test_reporter_tap::begin_test_suite (const char * name)
virtual

Mark the beginning of a test suite.

Parameters
name

The name of the test suite.

Returns

Nothing.

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

Declaration at line 163 of file test-reporter-tap.h, definition at line 347 of file test-reporter-tap.cpp.

348 {
350 {
351 flush ();
352 printf ("\n");
353 }
354
356 {
357 add_empty_line = false;
358 return;
359 }
360
361#pragma GCC diagnostic push
362#if defined(__clang__)
363#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
364#endif
365 printf ("# Subtest: %s - test suite\n", name);
366#pragma GCC diagnostic pop
367
368 add_empty_line = false;
369 }

References micro_os_plus::micro_test_plus::test_reporter::add_empty_line, flush, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::silent and micro_os_plus::micro_test_plus::test_reporter::verbosity.

color()

end_test()

void micro_os_plus::micro_test_plus::test_reporter_tap::end_test (test_runner & runner)
virtual

Mark the end of a test.

Parameters
runner

Reference to the test runner.

Returns

Nothing.

Declaration at line 193 of file test-reporter-tap.h, definition at line 474 of file test-reporter-tap.cpp.

475 {
477 {
478#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
479 long milliseconds = 0;
480 long microseconds = 0;
481 runner.default_test_suite->compute_elapsed_time (
482 runner.begin_time, runner.end_time, milliseconds, microseconds);
483#endif
484
485#pragma GCC diagnostic push
486#if defined(__clang__)
487#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
488#endif
489 printf ("\n# { total: %zu check%s passed, %zu failed, in %zu test "
490 "case%s, %zu test suite%s",
491 runner.totals.successful_checks,
492 runner.totals.successful_checks == 1 ? "" : "s",
493 runner.totals.failed_checks, runner.totals.test_cases_count,
494 runner.totals.test_cases_count == 1 ? "" : "s",
495 runner.test_suites_count (),
496 runner.test_suites_count () == 1 ? "" : "s");
497
498#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
499 if (milliseconds > 0 || microseconds > 0)
500 {
501 printf (", time: %ld.%03ld ms", milliseconds, microseconds);
502 }
503#endif
504 printf (" }\n");
505#pragma GCC diagnostic pop
506 flush ();
507 }
508 }

References flush, micro_os_plus::micro_test_plus::runner, micro_os_plus::micro_test_plus::silent and micro_os_plus::micro_test_plus::test_reporter::verbosity.

end_test_case()

void micro_os_plus::micro_test_plus::test_reporter_tap::end_test_case (const char * name)
virtual

Mark the end of a test case.

Parameters
name

The name of the test case.

Returns

Nothing.

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

Declaration at line 153 of file test-reporter-tap.h, definition at line 251 of file test-reporter-tap.cpp.

251 test_reporter_tap::end_test_case ([[maybe_unused]] const char* name)
252 {
254 {
255 if (current_test_suite->current_test_case.failed_checks > 0)
256 {
257 if (true /* add_empty_line */)
258 {
259 printf ("\n");
260 }
261#pragma GCC diagnostic push
262#if defined(__clang__)
263#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
264#endif
265 printf (" # Subtest: %s - test case started\n", name);
266 output ();
267 printf (" 1..%zu\n",
268 current_test_suite->current_test_case.index);
269 printf (" not ok %zu - %s # { test case FAILED, %zu check%s "
270 "passed, %zu failed }\n",
271 current_test_suite->test_cases_count (), name,
272 current_test_suite->current_test_case.successful_checks,
273 current_test_suite->current_test_case.successful_checks
274 == 1
275 ? ""
276 : "s",
277 current_test_suite->current_test_case.failed_checks);
278
279#pragma GCC diagnostic pop
280 add_empty_line = true;
281 }
282 else
283 {
285 {
286 printf ("\n");
287 }
289 {
290#pragma GCC diagnostic push
291#if defined(__clang__)
292#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
293#endif
294 printf (" # Subtest: %s - test case\n", name);
295 output ();
296 printf (" 1..%zu\n",
297 current_test_suite->current_test_case.index);
298 printf (
299 " ok %zu - %s # { test case passed, %zu check%s }\n",
300 current_test_suite->test_cases_count (), name,
301 current_test_suite->current_test_case.successful_checks,
302 current_test_suite->current_test_case.successful_checks
303 == 1
304 ? ""
305 : "s");
306#pragma GCC diagnostic pop
307 add_empty_line = true;
308 }
309 else
310 {
311#pragma GCC diagnostic push
312#if defined(__clang__)
313#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
314#endif
315 printf (
316 " ok %zu - %s # { test case passed, %zu check%s }\n",
317 current_test_suite->test_cases_count (), name,
318 current_test_suite->current_test_case.successful_checks,
319 current_test_suite->current_test_case.successful_checks
320 == 1
321 ? ""
322 : "s");
323#pragma GCC diagnostic pop
324
325 add_empty_line = false;
326 }
327 }
328 }
329
330 out_.clear ();
331 flush ();
332
333 is_in_test_case_ = false;
334 }

References micro_os_plus::micro_test_plus::test_reporter::add_empty_line, micro_os_plus::micro_test_plus::current_test_suite, flush, micro_os_plus::micro_test_plus::test_reporter::is_in_test_case_, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::test_reporter::out_, output, micro_os_plus::micro_test_plus::verbose and micro_os_plus::micro_test_plus::test_reporter::verbosity.

end_test_suite()

void micro_os_plus::micro_test_plus::test_reporter_tap::end_test_suite (test_suite_base & suite)
virtual

Mark the end of a test suite.

Parameters
suite

Reference to the test suite base.

Returns

Nothing.

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

Declaration at line 173 of file test-reporter-tap.h, definition at line 384 of file test-reporter-tap.cpp.

385 {
387 {
388 return;
389 }
390
391#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
392 long milliseconds = 0;
393 long microseconds = 0;
394 suite.compute_elapsed_time (suite.begin_time, suite.end_time, milliseconds,
395 microseconds);
396#endif
397
398 if (suite.test_cases_count () > 0 && verbosity != verbosity::quiet)
399 {
400 // printf ("\n");
401 add_empty_line = true;
402 }
403
404 // Also fail if none passed.
405 if (suite.failed_checks () == 0 && suite.successful_checks () != 0)
406 {
407#pragma GCC diagnostic push
408#if defined(__clang__)
409#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
410#endif
412 {
413 printf (" 1..%zu\n", suite.test_cases_count ());
414 }
415 printf ("ok %zu - %s # { test suite passed, %zu check%s in %zu test "
416 "case%s",
417 suite.index, suite.name (), suite.successful_checks (),
418 suite.successful_checks () == 1 ? "" : "s",
419 suite.test_cases_count (),
420 suite.test_cases_count () == 1 ? "" : "s");
421#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
422 if (milliseconds > 0 || microseconds > 0)
423 {
424 printf (", time: %ld.%03ld ms", milliseconds, microseconds);
425 }
426#endif
427 printf (" }\n");
428#pragma GCC diagnostic pop
429 }
430 else
431 {
432#pragma GCC diagnostic push
433#if defined(__clang__)
434#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
435#endif
437 {
438 printf (" 1..%zu\n", suite.test_cases_count ());
439 }
440 printf ("not ok %zu - %s # { test suite FAILED, %zu check%s passed, "
441 "%zu failed, in %zu test case%s",
442 suite.index, suite.name (), suite.successful_checks (),
443 suite.successful_checks () == 1 ? "" : "s",
444 suite.failed_checks (), suite.test_cases_count (),
445 suite.test_cases_count () == 1 ? "" : "s");
446#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
447 if (milliseconds > 0 || microseconds > 0)
448 {
449 printf (", time: %ld.%03ld ms", milliseconds, microseconds);
450 }
451#endif
452 printf (" }\n");
453#pragma GCC diagnostic pop
454 }
455
456 flush ();
457 }

References micro_os_plus::micro_test_plus::test_reporter::add_empty_line, micro_os_plus::micro_test_plus::test_suite_base::failed_checks, flush, micro_os_plus::micro_test_plus::test_suite_base::index, micro_os_plus::micro_test_plus::test_suite_base::name, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::silent, micro_os_plus::micro_test_plus::test_suite_base::successful_checks, micro_os_plus::micro_test_plus::test_suite_base::test_cases_count and micro_os_plus::micro_test_plus::test_reporter::verbosity.

endline()

void micro_os_plus::micro_test_plus::test_reporter_tap::endline (void)
virtual

Inserts a line ending into the output buffer.

Parameters

None.

Returns

Nothing.

This method appends a newline character to the internal output buffer of the test_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.

Declaration at line 133 of file test-reporter-tap.h, definition at line 188 of file test-reporter-tap.cpp.

189 {
190 out_.append ("\n");
191 flush ();
192 }

References flush and micro_os_plus::micro_test_plus::test_reporter::out_.

fail()

template <class Expr_T>
void micro_os_plus::micro_test_plus::test_reporter::fail (Expr_T & expr, bool abort, std::string & message, const reflection::source_location & location)

Report a failed condition.

Template Parameters
Expr_T

The expression type.

Parameters
expr

The evaluated expression.

abort

Whether to abort execution after failure.

message

The message to display.

location

The source location of the failure.

Returns

Nothing.

This function reports a test failure and formats the output in a clear and consistent manner. It provides contextual information, including the precise source location, and appends the evaluated expression when applicable. The failure handling process ensures uniformity in the presentation of unsuccessful test cases, aiding in the rapid identification and diagnosis of issues within test reports.

Declaration at line 656 of file test-reporter.h, definition at line 445 of file test-reporter-inlines.h.

445 test_reporter::fail (Expr_T& expr, bool abort, std::string& message,
446 const reflection::source_location& location)
447 {
448 current_test_suite->current_test_case.index++;
449
450 const bool hasExpression = type_traits::is_op_v<Expr_T>;
451 output_fail_prefix_ (message, hasExpression, location);
452
453 if constexpr (type_traits::is_op_v<Expr_T>)
454 {
455 *this << expr;
456 }
457
458 output_fail_suffix_ (location, abort);
459 }

References micro_os_plus::micro_test_plus::current_test_suite, micro_os_plus::micro_test_plus::type_traits::is_op_v, micro_os_plus::micro_test_plus::test_reporter::output_fail_prefix_ and micro_os_plus::micro_test_plus::test_reporter::output_fail_suffix_.

flush()

void micro_os_plus::micro_test_plus::test_reporter_tap::flush (void)
virtual

Flush the current buffered content.

Parameters

None.

Returns

Nothing.

This method flushes the output buffer of the test_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.

Declaration at line 204 of file test-reporter-tap.h, definition at line 202 of file test-reporter-tap.cpp.

203 {
204 fflush (stdout); // Sync STDOUT.
205 }

Referenced by begin_test, begin_test_case, begin_test_suite, end_test, end_test_case, end_test_suite, endline, output_fail_suffix_ and output_pass_suffix_.

output()

void micro_os_plus::micro_test_plus::test_reporter_tap::output (void)
virtual

Output the current buffered content.

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.

Declaration at line 215 of file test-reporter-tap.h, definition at line 521 of file test-reporter-tap.cpp.

522 {
523 printf ("%s", out_.c_str ()); // No `\n` here.
524 out_.clear ();
525 }

Reference micro_os_plus::micro_test_plus::test_reporter::out_.

Referenced by begin_test_case and end_test_case.

pass()

template <class Expr_T>
void micro_os_plus::micro_test_plus::test_reporter::pass (Expr_T & expr, std::string & message)

Report a passed condition.

Template Parameters
Expr_T

The expression type.

Parameters
expr

The evaluated expression.

message

The message to display.

Returns

Nothing.

This operator overload formats output for expressions that do not throw exceptions. It applies colour styling for clarity and ensures a structured representation of exception safety.

When invoked, the function outputs a pass prefix, followed by either the provided message or, if the message is empty, the evaluated expression itself. It then appends a pass suffix to complete the output. This approach guarantees that successful test outcomes are presented in a clear and consistent manner, enhancing the readability and professionalism of test reports.

Declaration at line 640 of file test-reporter.h, definition at line 419 of file test-reporter-inlines.h.

419 test_reporter::pass (Expr_T& expr, std::string& message)
420 {
421 current_test_suite->current_test_case.index++;
422
423 output_pass_prefix_ (message);
424
425 if (message.empty ())
426 {
427 // If there is no message, display the evaluated expression.
428 *this << expr;
429 }
430
432 }

References micro_os_plus::micro_test_plus::current_test_suite, micro_os_plus::micro_test_plus::test_reporter::output_pass_prefix_ and micro_os_plus::micro_test_plus::test_reporter::output_pass_suffix_.

Protected Member Functions

output_fail_prefix_()

void micro_os_plus::micro_test_plus::test_reporter_tap::output_fail_prefix_ (std::string & message, const bool hasExpression, const reflection::source_location & location)
protected virtual

Outputs the prefix for a failing condition.

Parameters
message

The message to display.

hasExpression

Whether the failure is associated with an expression.

location

The source location of the failure.

Returns

Nothing.

This method outputs the prefix for a failing test result, applying the appropriate colour formatting and symbols to clearly indicate failure. If the output occurs within a test case, additional indentation is applied for readability. The prefix includes a cross symbol (), an optional message, and the label "FAILED". The source location is appended in parentheses, showing the file or folder name and line number where the failure occurred. Colour formatting is reset after the prefix to maintain consistent output style across all test cases and folders.

Declaration at line 250 of file test-reporter-tap.h, definition at line 121 of file test-reporter-tap.cpp.

122 std::string& message, [[maybe_unused]] const bool hasExpression,
123 [[maybe_unused]] const reflection::source_location& location)
124 {
126 {
127 *this << " ";
128 }
129 *this << "not ok "
130 << static_cast<int> (current_test_suite->current_test_case.index);
131
132 if (!message.empty ())
133 {
134 *this << " - " << message.c_str ();
135 *this << " ";
136 }
137 *this << endl;
138
139 *this << " ---";
140 if (hasExpression)
141 {
142 *this << endl;
143 *this << " expect: ";
144 }
145 }

References micro_os_plus::micro_test_plus::current_test_suite, micro_os_plus::micro_test_plus::endl and micro_os_plus::micro_test_plus::test_reporter::is_in_test_case_.

output_fail_suffix_()

void micro_os_plus::micro_test_plus::test_reporter_tap::output_fail_suffix_ (const reflection::source_location & location, bool abort)
protected virtual

Outputs the suffix for a failing condition.

Parameters
location

The source location of the failure.

abort

Whether to abort execution after failure.

Returns

Nothing.

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

Declaration at line 262 of file test-reporter-tap.h, definition at line 157 of file test-reporter-tap.cpp.

158 const reflection::source_location& location, bool abort)
159 {
160 if (abort)
161 {
162 *this << " aborted...";
163 }
164 *this << endl;
165 *this << " at:" << endl;
166
167 *this << " filename: "
168 << reflection::short_name (location.file_name ()) << endl;
169 *this << " line: "
171 .line () }
172 << endl;
173
174 *this << " ..." << endl;
175
176 flush ();
177 }

References micro_os_plus::micro_test_plus::endl, micro_os_plus::micro_test_plus::reflection::source_location::file_name, flush, micro_os_plus::micro_test_plus::reflection::source_location::line and micro_os_plus::micro_test_plus::reflection::short_name.

output_pass_prefix_()

void micro_os_plus::micro_test_plus::test_reporter_tap::output_pass_prefix_ (std::string & message)
protected virtual

Outputs the prefix for a passing condition.

Parameters
message

The message to display.

Returns

Nothing.

This method outputs the prefix for a passing test result, applying the appropriate colour formatting and symbols to clearly indicate success. If the output occurs within a test case, additional indentation is applied for readability. The prefix includes a tick symbol () and, if provided, an associated message. Colour formatting is reset after the prefix to maintain consistent output style across all test cases and folders.

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

Declaration at line 226 of file test-reporter-tap.h, definition at line 71 of file test-reporter-tap.cpp.

72 {
74 {
75 *this << " ";
76 }
77 *this << "ok "
78 << static_cast<int> (current_test_suite->current_test_case.index)
79 << " - ";
80 if (!message.empty ())
81 {
82 *this << message.c_str ();
83 }
84 }

References micro_os_plus::micro_test_plus::current_test_suite and micro_os_plus::micro_test_plus::test_reporter::is_in_test_case_.

output_pass_suffix_()

void micro_os_plus::micro_test_plus::test_reporter_tap::output_pass_suffix_ (void)
protected virtual

Outputs the suffix for a passing condition.

Parameters

None.

Returns

Nothing.

The endl function acts as a stream manipulator for the test_reporter, inserting a line ending into the output buffer and flushing the current content if necessary. This ensures that test report output is clearly separated and formatted, improving readability and professionalism in the presentation of test results.

Using endl in conjunction with the test_reporter output operators provides a familiar and convenient mechanism for managing line breaks, similar to standard C++ stream manipulators.

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

Declaration at line 237 of file test-reporter-tap.h, definition at line 102 of file test-reporter-tap.cpp.

103 {
104 *this << endl;
105
106 flush ();
107 }

References micro_os_plus::micro_test_plus::endl and flush.

Protected Member Attributes

colors_

is_in_test_case_

out_

std::string micro_os_plus::micro_test_plus::test_reporter::out_ {}
protected

Internal output buffer for accumulating report content.

Definition at line 823 of file test-reporter.h.

823 std::string out_{};

Referenced by micro_os_plus::micro_test_plus::test_reporter_basic::begin_test_case, begin_test_case, micro_os_plus::micro_test_plus::test_reporter_basic::end_test_case, end_test_case, micro_os_plus::micro_test_plus::test_reporter_basic::endline, endline, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter::operator<<, micro_os_plus::micro_test_plus::test_reporter_basic::output and output.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.