micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail Namespace Reference

Internal implementation details for the µTest++ framework. More...

Classes

struct  and_
 Logical AND comparator struct template. More...
struct  assertion
 Assertion struct template for parameter passing to the evaluator. More...
struct  binary_op_
 Common base struct template for binary comparators. More...
struct  callable_op_
 Common base struct for callable-wrapping operators. More...
struct  colours
 Colours used to highlight pass and fail results in test reports. More...
class  deferred_reporter
 Deferred reporter class for a specific expression. More...
class  deferred_reporter_base
 Base class for a deferred reporter that collects messages into a string. More...
struct  eq_
 Equality comparator struct template. More...
class  expression_formatter
 Formats values and expressions into an owned string buffer. More...
struct  ge_
 Greater than or equal comparator struct template. More...
struct  gt_
 Greater than comparator struct template. More...
struct  indent_t
 Parameterised stream manipulator for outputting indentation. More...
struct  le_
 Less than or equal comparator struct template. More...
struct  lt_
 Less than comparator struct template. More...
struct  ne_
 Non-equality comparator struct template. More...
struct  not_
 Logical NOT comparator struct template. More...
struct  nothrow_
 Operator struct template to check if an expression does not throw any exception. More...
struct  or_
 Logical OR comparator struct template. More...
class  runnable
 CRTP base class factoring out callable storage, rule-of-five, and run() logic shared by subtest and suite. More...
class  runnable_base
 Non-template base for all runnable objects (suites and subtests). More...
class  runner_totals
 Aggregated pass/fail/subtest counters for a node in the test tree. More...
class  test_node
 Base class for runners and runable tests. More...
struct  throws_
 Operator struct template to check if an expression throws a specific exception. More...
struct  throws_< Callable_T, void >
 Operator struct template to check if an expression throws any exception. More...
class  timestamp
 A single point-in-time measurement, wrapping a timespec value. More...
class  timestamps
 A begin/end timestamp pair used to measure elapsed time. More...
struct  unary_op_
 Common base struct template for unary comparators. More...

Functions

template<typename Lhs_T, typename Rhs_T>
 and_ (const Lhs_T &, const Rhs_T &) -> and_< Lhs_T, Rhs_T >
template<class T>
requires std::is_arithmetic_v<T>
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-free, locale-independent formatting.
template<typename Lhs_T, typename Rhs_T>
 eq_ (const Lhs_T &, const Rhs_T &) -> eq_< Lhs_T, Rhs_T >
template<typename Lhs_T, typename Rhs_T>
 ge_ (const Lhs_T &, const Rhs_T &) -> ge_< Lhs_T, Rhs_T >
template<class T>
constexpr auto get (const T &t)
 Generic getter function template for value retrieval.
template<typename Lhs_T, typename Rhs_T>
 gt_ (const Lhs_T &, const Rhs_T &) -> gt_< Lhs_T, Rhs_T >
template<typename Lhs_T, typename Rhs_T>
 le_ (const Lhs_T &, const Rhs_T &) -> le_< Lhs_T, Rhs_T >
template<typename Lhs_T, typename Rhs_T>
 lt_ (const Lhs_T &, const Rhs_T &) -> lt_< Lhs_T, Rhs_T >
template<typename Lhs_T, typename Rhs_T>
 ne_ (const Lhs_T &, const Rhs_T &) -> ne_< Lhs_T, Rhs_T >
template<typename T>
 not_ (const T &) -> not_< T >
template<typename Lhs_T, typename Rhs_T>
 or_ (const Lhs_T &, const Rhs_T &) -> or_< Lhs_T, Rhs_T >
void register_static_suite (static_runner &static_runner_ref, static_suite &static_suite_ref)
 Registers a static suite with a static runner.
runnerto_runner (static_runner &static_runner_ref) noexcept
 Converts a static_runner reference to a runner reference.

Variables

constexpr colours colours_red_green

Detailed Description

The detail namespace encapsulates the internal mechanisms, helper structures, and implementation utilities employed by the µTest++ testing framework. These components do not form part of the public API and may be modified without prior notice.

Within this namespace, one will find assertion handling, generic getter utilities, comparator structures for logical and relational operations, mechanisms for exception checking, and base classes for deferred reporting of test results.

All definitions within detail are intended exclusively for internal use, ensuring a clear distinction between user-facing and internal components. This approach enhances maintainability, mitigates the risk of naming conflicts, and keeps the public API succinct.

The relevant header files are organised within the include/micro-os-plus folder to maintain a structured and modular codebase.

Function Documentation

◆ and_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::and_ ( const Lhs_T & ,
const Rhs_T &  ) -> and_< Lhs_T, Rhs_T >

◆ append_number_()

template<class T>
requires std::is_arithmetic_v<T>
void micro_os_plus::micro_test_plus::detail::append_number_ ( std::string & buffer,
T v )
Template Parameters
TThe numeric type to format.
Parameters
bufferThe string to append to.
vThe value to format.
Returns
Nothing.

For long double, a platform-specific path is chosen:

  • On Windows and on platforms where long double has the same storage width as double (e.g., ARM, RISC-V), the value is cast to double and formatted with std::to_chars.
  • On x86-64 Linux/macOS with 80-bit extended precision, snprintf with Lg is used as a portable fallback because std::to_chars for long double may be unavailable when linking with lld.

For all other numeric types, std::to_chars is called directly, providing locale-independent, allocation-free formatting.

Definition at line 653 of file detail-inlines.h.

654 {
655 char buf[32];
656 if constexpr (std::is_same_v<T, long double>)
657 {
658#if defined(_WIN32) \
659 || (defined(__SIZEOF_LONG_DOUBLE__) \
660 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
661 // On Windows (all toolchains: MinGW, Clang, MSVC), the C runtime
662 // does not handle the %Lg printf specifier correctly for 80-bit
663 // long double, producing garbage output. On platforms where long
664 // double has the same width as double (ARM, RISC-V), the cast is
665 // lossless. In both cases, cast to double and use std::to_chars.
666 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
667 static_cast<double> (v));
668 if (ec == std::errc{})
669 buffer.append (buf, ptr);
670#else
671 // On x86-64 Linux/macOS with 80-bit extended-precision long double,
672 // std::to_chars for long double may be unavailable (e.g., with lld).
673 // Use snprintf as a portable fallback; %Lg is supported correctly
674 // by glibc and libc++ on these platforms.
675 snprintf (buf, sizeof (buf), "%Lg", v);
676 buffer.append (buf);
677#endif
678 }
679 else
680 {
681 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
682 if (ec == std::errc{})
683 buffer.append (buf, ptr);
684 }
685 }

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

◆ eq_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::eq_ ( const Lhs_T & ,
const Rhs_T &  ) -> eq_< Lhs_T, Rhs_T >

◆ ge_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::ge_ ( const Lhs_T & ,
const Rhs_T &  ) -> ge_< Lhs_T, Rhs_T >

◆ get()

template<class T>
auto micro_os_plus::micro_test_plus::detail::get ( const T & t)
nodiscardconstexpr
Template Parameters
TThe type from which the value is to be retrieved.
Parameters
tThe object or value to be accessed.
Returns
The value obtained via the relevant getter implementation.

If the type T provides a get() member function, it is invoked and its result returned. Otherwise the argument itself is returned unchanged. The selection is performed at compile time via if constexpr with an inline requires expression.

Definition at line 81 of file detail-inlines.h.

82 {
83 if constexpr (requires { t.get (); })
84 return t.get ();
85 else
86 return t;
87 }

Referenced by micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::eq_(), micro_os_plus::micro_test_plus::detail::ge_< Lhs_T, Rhs_T >::ge_(), micro_os_plus::micro_test_plus::detail::gt_< Lhs_T, Rhs_T >::gt_(), micro_os_plus::micro_test_plus::detail::le_< Lhs_T, Rhs_T >::le_(), micro_os_plus::micro_test_plus::detail::lt_< Lhs_T, Rhs_T >::lt_(), micro_os_plus::micro_test_plus::detail::ne_< Lhs_T, Rhs_T >::ne_(), micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::lhs(), micro_os_plus::micro_test_plus::detail::unary_op_< T >::operand(), micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<(), and micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::rhs().

◆ gt_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::gt_ ( const Lhs_T & ,
const Rhs_T &  ) -> gt_< Lhs_T, Rhs_T >

◆ le_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::le_ ( const Lhs_T & ,
const Rhs_T &  ) -> le_< Lhs_T, Rhs_T >

◆ lt_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::lt_ ( const Lhs_T & ,
const Rhs_T &  ) -> lt_< Lhs_T, Rhs_T >

◆ ne_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::ne_ ( const Lhs_T & ,
const Rhs_T &  ) -> ne_< Lhs_T, Rhs_T >

◆ not_()

template<typename T>
micro_os_plus::micro_test_plus::detail::not_ ( const T & ) -> not_< T >

◆ or_()

template<typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::or_ ( const Lhs_T & ,
const Rhs_T &  ) -> or_< Lhs_T, Rhs_T >

◆ register_static_suite()

void micro_os_plus::micro_test_plus::detail::register_static_suite ( static_runner & static_runner_ref,
static_suite & static_suite_ref )

This declaration allows test-inlines.h to request registration without requiring the complete static_runner type in that header.

Parameters
static_runner_refThe destination static runner.
static_suite_refThe static suite to register.

Performs static-suite registration where static_runner is complete, allowing header-only template code to avoid direct dependence on runner.h include order.

Definition at line 93 of file runner.cpp.

95 {
96 static_runner::register_static_suite (static_runner_ref, static_suite_ref);
97 }
static void register_static_suite(static_runner &runner, static_suite &suite)
Registers a static test suite with the runner.
Definition runner.cpp:637

References micro_os_plus::micro_test_plus::static_runner::register_static_suite().

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

◆ to_runner()

runner & micro_os_plus::micro_test_plus::detail::to_runner ( static_runner & static_runner_ref)
noexcept

This declaration breaks the include-order cycle between test and runner headers. The definition is provided in a translation unit where both types are complete, so the conversion remains type-safe.

Parameters
static_runner_refThe source static_runner reference.
Returns
The same object viewed as its runner base.

Performs the static_runner to runner upcast where both types are complete, allowing headers with only forward declarations to request this conversion safely.

Definition at line 81 of file runner.cpp.

82 {
83 return static_cast<runner&> (static_runner_ref);
84 }
The test runner for the µTest++ framework.
Definition runner.h:111

Variable Documentation

◆ colours_red_green

colours micro_os_plus::micro_test_plus::detail::colours_red_green
inlineconstexpr
Initial value:
= {
"\033[0m",
"\033[32m",
"\033[31m"
}

Definition at line 123 of file expression-formatter.h.

123 {
124 "\033[0m",
125 "\033[32m",
126 "\033[31m"
127 };

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