Skip to main content

detail.h File

C++ header file with declarations for the µTest++ internals. More...

Included Headers

#include <cstdio> #include <string> #include "type-traits.h" #include "reflection.h" #include "inlines/detail-inlines.h"

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacedetail

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

Classes Index

structand_<Lhs_T, Rhs_T>

Logical AND comparator struct template. More...

structassertion<Expr_T>

Assertion struct template for parameter passing to the evaluator. More...

structbinary_op_<Lhs_T, Rhs_T>

Common base struct template for binary comparators. More...

structcallable_op_

Common base struct for callable-wrapping operators. More...

structeq_<Lhs_T, Rhs_T>

Equality comparator struct template. More...

structge_<Lhs_T, Rhs_T>

Greater than or equal comparator struct template. More...

structgt_<Lhs_T, Rhs_T>

Greater than comparator struct template. More...

structle_<Lhs_T, Rhs_T>

Less than or equal comparator struct template. More...

structlt_<Lhs_T, Rhs_T>

Less than comparator struct template. More...

structne_<Lhs_T, Rhs_T>

Non-equality comparator struct template. More...

structnot_<T>

Logical NOT comparator struct template. More...

structnothrow_<Callable_T>

Operator struct template to check if an expression does not throw any exception. More...

structor_<Lhs_T, Rhs_T>

Logical OR comparator struct template. More...

structthrows_<Callable_T, Exception_T>

Operator struct template to check if an expression throws a specific exception. More...

structthrows_<Callable_T, void>

Operator struct template to check if an expression throws any exception. More...

structunary_op_<T>

Common base struct template for unary comparators. More...

Functions Index

template <typename Lhs_T, typename Rhs_T>
and_ (const Lhs_T &, const Rhs_T &) -> and_< Lhs_T, Rhs_T >
template <class T>
voidappend_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. More...

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 autoget (const T &t)

Generic getter function template for value retrieval. More...

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 >

Description

C++ header file with declarations for the µTest++ internals.

This header provides the declarations for the internal components of the µTest++ framework, encapsulated within the micro_os_plus::micro_test_plus::detail namespace. It defines the core mechanisms, helper structures, and utility templates that underpin the framework's assertion handling, value retrieval, comparator logic, deferred reporting, and exception checking facilities.

All definitions reside within the micro_os_plus::micro_test_plus::detail namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

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

This file is intended solely for internal use within the framework and should not be included directly by user code.

Functions

and_()

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

Definition at line 515 of file detail.h.

append_number_()

template <class T>
void micro_os_plus::micro_test_plus::detail::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 Parameters
T

The numeric type to format.

Parameters
buffer

The string to append to.

v

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

653 append_number_ (std::string& buffer, const T v)
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 &)

Definition at line 318 of file detail.h.

ge_()

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

Definition at line 416 of file detail.h.

get()

template <class T>
auto micro_os_plus::micro_test_plus::detail::get (const T & t)
nodiscard constexpr

Generic getter function template for value retrieval.

Template Parameters
T

The type from which the value is to be retrieved.

Parameters
t

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

81 get (const T& t)
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 &)

Definition at line 382 of file detail.h.

le_()

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

Definition at line 482 of file detail.h.

lt_()

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

Definition at line 448 of file detail.h.

ne_()

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

Definition at line 350 of file detail.h.

not_()

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

Definition at line 578 of file detail.h.

or_()

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

Definition at line 548 of file detail.h.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
41
42#ifndef MICRO_TEST_PLUS_DETAIL_H_
43#define MICRO_TEST_PLUS_DETAIL_H_
44
45// ----------------------------------------------------------------------------
46
47#ifdef __cplusplus
48
49// ----------------------------------------------------------------------------
50
51#include <cstdio>
52#include <string>
53
54#include "type-traits.h"
55#include "reflection.h"
56
57// ----------------------------------------------------------------------------
58
59#if defined(__GNUC__)
60#pragma GCC diagnostic push
61#pragma GCC diagnostic ignored "-Wpadded"
62#pragma GCC diagnostic ignored "-Waggregate-return"
63#if defined(__clang__)
64#pragma clang diagnostic ignored "-Wc++98-compat"
65#endif
66#endif
67
68// ============================================================================
69
71{
72 class test_node;
73
74 // --------------------------------------------------------------------------
75
99 namespace detail
100 {
101 // ========================================================================
102
116 template <class Expr_T>
117 struct assertion
118 {
122 Expr_T expr{};
123
128 };
129
130 // ========================================================================
131
140 template <class T>
141 [[nodiscard]] constexpr auto
142 get (const T& t);
143
144 // ========================================================================
145
160 template <class T>
162 {
170 constexpr unary_op_ (const T& t, bool value);
171
179 [[nodiscard]] constexpr
180 operator bool () const;
181
189 [[nodiscard]] constexpr auto
190 operand () const;
191
192 private:
196 const T t_{};
197
201 const bool value_{};
202 };
203
204 // ========================================================================
205
222 template <class Lhs_T, class Rhs_T>
224 {
233 constexpr binary_op_ (const Lhs_T& lhs, const Rhs_T& rhs, bool value);
234
242 [[nodiscard]] constexpr
243 operator bool () const;
244
252 [[nodiscard]] constexpr auto
253 lhs (void) const;
254
262 [[nodiscard]] constexpr auto
263 rhs (void) const;
264
265 private:
272 const Lhs_T lhs_{};
273
280 const Rhs_T rhs_{};
281
285 const bool value_{};
286 };
287
288 // ========================================================================
289
304 template <class Lhs_T, class Rhs_T>
305 struct eq_ : binary_op_<Lhs_T, Rhs_T>
306 {
313 constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
314 };
315
316 // Deduction guide.
317 template <typename Lhs_T, typename Rhs_T>
318 eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
319
320 // ========================================================================
321
336 template <class Lhs_T, class Rhs_T>
337 struct ne_ : binary_op_<Lhs_T, Rhs_T>
338 {
345 constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
346 };
347
348 // Deduction guide.
349 template <typename Lhs_T, typename Rhs_T>
350 ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
351
352 // ========================================================================
353
368 template <class Lhs_T, class Rhs_T>
369 struct gt_ : binary_op_<Lhs_T, Rhs_T>
370 {
377 constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
378 };
379
380 // Deduction guide.
381 template <typename Lhs_T, typename Rhs_T>
382 gt_ (const Lhs_T&, const Rhs_T&) -> gt_<Lhs_T, Rhs_T>;
383
384 // ========================================================================
385
401 template <class Lhs_T, class Rhs_T>
402 struct ge_ : binary_op_<Lhs_T, Rhs_T>
403 {
411 constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
412 };
413
414 // Deduction guide.
415 template <typename Lhs_T, typename Rhs_T>
416 ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
417
418 // ========================================================================
419
434 template <class Lhs_T, class Rhs_T>
435 struct lt_ : binary_op_<Lhs_T, Rhs_T>
436 {
443 constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
444 };
445
446 // Deduction guide.
447 template <typename Lhs_T, typename Rhs_T>
448 lt_ (const Lhs_T&, const Rhs_T&) -> lt_<Lhs_T, Rhs_T>;
449
450 // ========================================================================
451
467 template <class Lhs_T, class Rhs_T>
468 struct le_ : binary_op_<Lhs_T, Rhs_T>
469 {
477 constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
478 };
479
480 // Deduction guide.
481 template <typename Lhs_T, typename Rhs_T>
482 le_ (const Lhs_T&, const Rhs_T&) -> le_<Lhs_T, Rhs_T>;
483
484 // ========================================================================
485
501 template <class Lhs_T, class Rhs_T>
502 struct and_ : binary_op_<Lhs_T, Rhs_T>
503 {
510 constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
511 };
512
513 // Deduction guide.
514 template <typename Lhs_T, typename Rhs_T>
515 and_ (const Lhs_T&, const Rhs_T&) -> and_<Lhs_T, Rhs_T>;
516
517 // ========================================================================
518
534 template <class Lhs_T, class Rhs_T>
535 struct or_ : binary_op_<Lhs_T, Rhs_T>
536 {
543 constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
544 };
545
546 // Deduction guide.
547 template <typename Lhs_T, typename Rhs_T>
548 or_ (const Lhs_T&, const Rhs_T&) -> or_<Lhs_T, Rhs_T>;
549
550 // ========================================================================
551
565 template <class T>
566 struct not_ : unary_op_<T>
567 {
573 explicit constexpr not_ (const T& t = {});
574 };
575
576 // Deduction guide.
577 template <typename T>
578 not_ (const T&) -> not_<T>;
579
580 // ========================================================================
581
582#if defined(__cpp_exceptions)
583
598 {
605 constexpr explicit callable_op_ (bool value);
606
614 [[nodiscard]] constexpr
615 operator bool () const;
616
617 private:
621 const bool value_{};
622 };
623
624 // ========================================================================
625
643 template <class Callable_T, class Exception_T = void>
645 {
652 constexpr explicit throws_ (const Callable_T& func);
653 };
654
655 // ========================================================================
656
672 template <class Callable_T>
673 struct throws_<Callable_T, void> : callable_op_
674 {
681 constexpr explicit throws_ (const Callable_T& func);
682 };
683
684 // ========================================================================
685
700 template <class Callable_T>
702 {
709 constexpr explicit nothrow_ (const Callable_T& func);
710 };
711
712#endif
713
714 // ========================================================================
715
727 template <class T>
728 requires std::is_arithmetic_v<T>
729 void
730 append_number_ (std::string& buffer, T v);
731
732 // ------------------------------------------------------------------------
733 } // namespace detail
734
735 // --------------------------------------------------------------------------
736} // namespace micro_os_plus::micro_test_plus
737
738#if defined(__GNUC__)
739#pragma GCC diagnostic pop
740#endif
741
742// ----------------------------------------------------------------------------
743
744#endif // __cplusplus
745
746// ============================================================================
747// Templates & constexpr implementations.
748
750
751// ----------------------------------------------------------------------------
752
753#endif // MICRO_TEST_PLUS_DETAIL_H_
754
755// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.