Skip to main content

expression-formatter-inlines.h File

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

Included Headers

#include <cstdio> #include "micro-os-plus/micro-test-plus/reflection.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...

Description

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

This header provides the inline and template method implementations for expression_formatter. The buffer accessors (str(), c_str(), clear(), empty(), append(), reserve()) are defined as inline functions for zero-overhead access. The template operators — operator<<(T*), operator<<(is_op<T>), operator<<(genuine_integral_value<T>), and operator<<(container) — are instantiated per concrete type at each call site.

The append_number_() helper is also a template, selecting between a std::to_chars path for standard numeric types and an snprintf fallback for long double on platforms where std::to_chars lacks support for 80-bit extended precision.

All definitions reside within the micro_os_plus::micro_test_plus namespace.

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
43
44#ifndef MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
45#define MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
46
47// ----------------------------------------------------------------------------
48
49#ifdef __cplusplus
50
51// ----------------------------------------------------------------------------
52
53#include <cstdio>
54
56
57// ----------------------------------------------------------------------------
58
59#if defined(__GNUC__)
60#pragma GCC diagnostic push
61#pragma GCC diagnostic ignored "-Waggregate-return"
62#if defined(__clang__)
63#pragma clang diagnostic ignored "-Wunknown-warning-option"
64#pragma clang diagnostic ignored "-Wc++98-compat"
65#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
66#endif
67#endif
68
69// ============================================================================
70
72{
73 // --------------------------------------------------------------------------
74
82 {
83 }
84
85 // --------------------------------------------------------------------------
86
92 inline auto
93 expression_formatter::colour_ (const bool cond) const
94 {
95 return cond ? colours_.pass : colours_.fail;
96 }
97
98 // --------------------------------------------------------------------------
99
104 inline const std::string&
105 expression_formatter::str () const noexcept
106 {
107 return buffer_;
108 }
109
115 inline const char*
117 {
118 return buffer_.c_str ();
119 }
120
126 inline void
128 {
129 buffer_.clear ();
130 }
131
137 inline bool
139 {
140 return buffer_.empty ();
141 }
142
148 inline void
149 expression_formatter::append (size_t count, char ch)
150 {
151 buffer_.append (count, ch);
152 }
153
159 inline void
161 {
162 buffer_.reserve (capacity);
163 }
164
165 // --------------------------------------------------------------------------
166
167#if defined(__GNUC__)
168#pragma GCC diagnostic push
169#if defined(__clang__)
170#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
171#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
172#endif
173#endif
174
175 // --------------------------------------------------------------------------
176
184 template <typename T>
187 {
188 if (v == nullptr)
189 {
190 buffer_.append ("0x0");
191 return *this;
192 }
193#if defined(__GNUC__)
194#pragma GCC diagnostic push
195#if defined(__clang__)
196#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
197#endif
198#endif
199 char buff[20];
200 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
201 buffer_.append (buff);
202#if defined(__GNUC__)
203#pragma GCC diagnostic pop
204#endif
205 return *this;
206 }
207
214 template <class T>
218 {
219 *this << detail::get (t);
220 return *this;
221 }
222
228 template <class T>
232 {
233 detail::append_number_ (buffer_, static_cast<long long> (v.get ()));
234 return *this;
235 }
236
243 template <class T>
246 expression_formatter::operator<< (const T& t)
247 {
248 *this << '{';
249 auto first = true;
250 for (const auto& arg : t)
251 {
252 *this << (first ? "" : ", ") << arg;
253 first = false;
254 }
255 *this << '}';
256 return *this;
257 }
258
259 // --------------------------------------------------------------------------
260 // Compound expression operators (without colour codes).
261
273 template <class Lhs_T, class Rhs_T>
276 {
277 return (*this << colour_ (op) << op.lhs () << " == " << op.rhs ()
278 << colours_.none);
279 }
280
293 template <class Lhs_T, class Rhs_T>
296 {
297 return (*this << colour_ (op) << op.lhs () << " != " << op.rhs ()
298 << colours_.none);
299 }
300
313 template <class Lhs_T, class Rhs_T>
316 {
317 return (*this << colour_ (op) << op.lhs () << " > " << op.rhs ()
318 << colours_.none);
319 }
320
334 template <class Lhs_T, class Rhs_T>
337 {
338 return (*this << colour_ (op) << op.lhs () << " >= " << op.rhs ()
339 << colours_.none);
340 }
341
353 template <class Lhs_T, class Rhs_T>
356 {
357 return (*this << colour_ (op) << op.lhs () << " < " << op.rhs ()
358 << colours_.none);
359 }
360
374 template <class Lhs_T, class Rhs_T>
377 {
378 return (*this << colour_ (op) << op.lhs () << " <= " << op.rhs ()
379 << colours_.none);
380 }
381
394 template <class Lhs_T, class Rhs_T>
397 {
398 return (*this << '(' << op.lhs () << colour_ (op) << " and "
399 << colours_.none << op.rhs () << ')');
400 }
401
414 template <class Lhs_T, class Rhs_T>
417 {
418 return (*this << '(' << op.lhs () << colour_ (op) << " or "
419 << colours_.none << op.rhs () << ')');
420 }
421
430 template <class T>
433 {
434 return (*this << colour_ (op) << "not " << op.operand () << colours_.none);
435 }
436
437#if defined(__cpp_exceptions)
450 template <class Callable_T, class Exception_T>
454 {
455 return (*this << colour_ (op) << "throws<"
457 << colours_.none);
458 }
459
470 template <class Callable_T>
474 {
475 return (*this << colour_ (op) << "throws" << colours_.none);
476 }
477
488 template <class Callable_T>
491 {
492 return (*this << colour_ (op) << "nothrow" << colours_.none);
493 }
494#endif
495
496 // --------------------------------------------------------------------------
497} // namespace micro_os_plus::micro_test_plus::detail
498
499#if defined(__GNUC__)
500#pragma GCC diagnostic pop
501#endif
502
503// ----------------------------------------------------------------------------
504
505#endif // __cplusplus
506
507// ----------------------------------------------------------------------------
508
509#endif // MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
510
511// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.17.0.