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 "-Wc++98-compat"
64#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
65#endif
66#endif
67
68// ============================================================================
69
71{
72 // --------------------------------------------------------------------------
73
81 {
82 }
83
84 // --------------------------------------------------------------------------
85
91 inline auto
92 expression_formatter::colour_ (const bool cond) const
93 {
94 return cond ? colours_.pass : colours_.fail;
95 }
96
97 // --------------------------------------------------------------------------
98
103 inline const std::string&
104 expression_formatter::str () const noexcept
105 {
106 return buffer_;
107 }
108
114 inline const char*
116 {
117 return buffer_.c_str ();
118 }
119
125 inline void
127 {
128 buffer_.clear ();
129 }
130
136 inline bool
138 {
139 return buffer_.empty ();
140 }
141
147 inline void
148 expression_formatter::append (size_t count, char ch)
149 {
150 buffer_.append (count, ch);
151 }
152
158 inline void
160 {
161 buffer_.reserve (capacity);
162 }
163
164 // --------------------------------------------------------------------------
165
166#if defined(__GNUC__)
167#pragma GCC diagnostic push
168#if defined(__clang__)
169#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
170#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
171#endif
172#endif
173
174 // --------------------------------------------------------------------------
175
183 template <typename T>
186 {
187 if (v == nullptr)
188 {
189 buffer_.append ("0x0");
190 return *this;
191 }
192#if defined(__GNUC__)
193#pragma GCC diagnostic push
194#if defined(__clang__)
195#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
196#endif
197#endif
198 char buff[20];
199 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
200 buffer_.append (buff);
201#if defined(__GNUC__)
202#pragma GCC diagnostic pop
203#endif
204 return *this;
205 }
206
213 template <class T>
217 {
218 *this << detail::get (t);
219 return *this;
220 }
221
227 template <class T>
231 {
232 detail::append_number_ (buffer_, static_cast<long long> (v.get ()));
233 return *this;
234 }
235
242 template <class T>
245 expression_formatter::operator<< (const T& t)
246 {
247 *this << '{';
248 auto first = true;
249 for (const auto& arg : t)
250 {
251 *this << (first ? "" : ", ") << arg;
252 first = false;
253 }
254 *this << '}';
255 return *this;
256 }
257
258 // --------------------------------------------------------------------------
259 // Compound expression operators (without colour codes).
260
272 template <class Lhs_T, class Rhs_T>
275 {
276 return (*this << colour_ (op) << op.lhs () << " == " << op.rhs ()
277 << colours_.none);
278 }
279
292 template <class Lhs_T, class Rhs_T>
295 {
296 return (*this << colour_ (op) << op.lhs () << " != " << op.rhs ()
297 << colours_.none);
298 }
299
312 template <class Lhs_T, class Rhs_T>
315 {
316 return (*this << colour_ (op) << op.lhs () << " > " << op.rhs ()
317 << colours_.none);
318 }
319
333 template <class Lhs_T, class Rhs_T>
336 {
337 return (*this << colour_ (op) << op.lhs () << " >= " << op.rhs ()
338 << colours_.none);
339 }
340
352 template <class Lhs_T, class Rhs_T>
355 {
356 return (*this << colour_ (op) << op.lhs () << " < " << op.rhs ()
357 << colours_.none);
358 }
359
373 template <class Lhs_T, class Rhs_T>
376 {
377 return (*this << colour_ (op) << op.lhs () << " <= " << op.rhs ()
378 << colours_.none);
379 }
380
393 template <class Lhs_T, class Rhs_T>
396 {
397 return (*this << '(' << op.lhs () << colour_ (op) << " and "
398 << colours_.none << op.rhs () << ')');
399 }
400
413 template <class Lhs_T, class Rhs_T>
416 {
417 return (*this << '(' << op.lhs () << colour_ (op) << " or "
418 << colours_.none << op.rhs () << ')');
419 }
420
429 template <class T>
432 {
433 return (*this << colour_ (op) << "not " << op.operand () << colours_.none);
434 }
435
436#if defined(__cpp_exceptions)
449 template <class Callable_T, class Exception_T>
453 {
454 return (*this << colour_ (op) << "throws<"
456 << colours_.none);
457 }
458
469 template <class Callable_T>
473 {
474 return (*this << colour_ (op) << "throws" << colours_.none);
475 }
476
487 template <class Callable_T>
490 {
491 return (*this << colour_ (op) << "nothrow" << colours_.none);
492 }
493#endif
494
495 // --------------------------------------------------------------------------
496} // namespace micro_os_plus::micro_test_plus::detail
497
498#if defined(__GNUC__)
499#pragma GCC diagnostic pop
500#endif
501
502// ----------------------------------------------------------------------------
503
504#endif // __cplusplus
505
506// ----------------------------------------------------------------------------
507
508#endif // MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
509
510// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.