Skip to main content

deferred-reporter-inlines.h File

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

Included Headers

#include <charconv> #include <cstdio>

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

Description

C++ header file with inline implementations for the µTest++ internals.

This header provides the inline implementations for internal components of the µTest++ framework, including operator overloads and constructors for deferred reporting mechanisms.

It defines the logic for accumulating expectation messages, handling both arithmetic and string-like types, as well as the construction and destruction behaviour of deferred reporters, ensuring that test outcomes are accurately captured and reported.

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.

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
44
45#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_DEFERRED_REPORTER_INLINES_H_
46#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_DEFERRED_REPORTER_INLINES_H_
47
48// ----------------------------------------------------------------------------
49
50#if defined(__cplusplus)
51
52// ----------------------------------------------------------------------------
53
54#if __has_include("micro-os-plus/diag/trace.h")
55#include "micro-os-plus/diag/trace.h"
56#endif // __has_include("micro-os-plus/diag/trace.h")
57
58#include <charconv>
59#include <cstdio>
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65
66#pragma GCC diagnostic ignored "-Waggregate-return"
67#if defined(__clang__)
68#pragma clang diagnostic ignored "-Wc++98-compat"
69#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
70#endif // defined(__clang__)
71#endif // defined(__GNUC__)
72
73// ============================================================================
74
76{
77 // --------------------------------------------------------------------------
78
79 namespace detail
80 {
81 // ========================================================================
82
87 inline bool
89 {
90 return value_;
91 }
92
93 // ------------------------------------------------------------------------
94
106 template <class T>
108 auto&
110 {
111 if constexpr (std::is_same_v<T, char>)
112 {
113 deferred_output_.push_back (msg);
114 }
115 else if constexpr (std::is_arithmetic_v<T>)
116 {
117 // Optimise to avoid dynamic memory allocation in std::to_string by
118 // using a fixed-size buffer and std::to_chars.
119#if defined(__GNUC__)
120#pragma GCC diagnostic push
121
122#if defined(__clang__)
123#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
124#endif // defined(__clang__)
125#endif // defined(__GNUC__)
126
127 char buf[64];
128 // 64 bytes is sufficient for the longest decimal representation
129 // of any standard arithmetic type (long double ~45 chars).
130 static_assert (sizeof (buf) >= 50,
131 "buf must be large enough for any arithmetic type");
132 auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), msg);
133 if (ec == std::errc{})
134 deferred_output_.append (buf, ptr);
135
136#if defined(__GNUC__)
137#pragma GCC diagnostic pop
138#endif // defined(__GNUC__)
139 }
140 else
141 {
142 deferred_output_.append (msg);
143 }
144 return *this;
145 }
146
147 // ------------------------------------------------------------------------
148
160 template <class Expr_T>
162 const Expr_T& expr, bool abort,
164 expression_formatter& expression)
165 : deferred_reporter_base{ static_cast<bool> (expr), location, subtest }
166
167 {
168#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
169 trace::printf ("%s\n", __PRETTY_FUNCTION__);
170#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
171 abort_ = abort;
173
174 expression.clear ();
175
176 expression << expr;
177 }
178
179 // ------------------------------------------------------------------------
180 } // namespace detail
181
182 // --------------------------------------------------------------------------
183} // namespace micro_os_plus::micro_test_plus
184
185#if defined(__GNUC__)
186#pragma GCC diagnostic pop
187#endif // defined(__GNUC__)
188
189// ----------------------------------------------------------------------------
190
191#endif // defined(__cplusplus)
192
193// ----------------------------------------------------------------------------
194
195#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_DEFERRED_REPORTER_INLINES_H_
196
197// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.