Skip to main content

expression-formatter.h File

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

Included Headers

#include <charconv> #include <cstdio> #include <string> #include <string_view> #include "type-traits.h" #include "detail.h" #include "inlines/expression-formatter-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

structcolours

Colours used to highlight pass and fail results in test reports. More...

classexpression_formatter

Formats values and expressions into an owned string buffer. More...

Variables Index

constexpr colourscolours_red_green = ...

Description

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

This header provides the expression_formatter class, which encapsulates all value-formatting logic used by the µTest++ framework. The class owns a std::string buffer and exposes operator<< overloads for every standard arithmetic type, character type, string, pointer, container, and framework expression type derived from detail::op.

By consolidating the formatting operators and their shared append_number_ helper into a single class, the reporter is relieved of those responsibilities, and detail::deferred_reporter can pre-format expression text at construction time without requiring reporter or subtest to be complete at that point.

Colour-code processing is intentionally excluded from this class; it remains the responsibility of the owning reporter.

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

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

Variables

colours_red_green

colours micro_os_plus::micro_test_plus::detail::colours_red_green
constexpr
Initialiser
                                           = {   "\033[0m",   "\033[32m",   "\033[31m" }

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

123 inline constexpr colours colours_red_green = {
124 "\033[0m",
125 "\033[32m",
126 "\033[31m"
127 };

Referenced by micro_os_plus::micro_test_plus::reporter_human::reporter_human.

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
46
47#ifndef MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
48#define MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
49
50// ----------------------------------------------------------------------------
51
52#ifdef __cplusplus
53
54// ----------------------------------------------------------------------------
55
56#include <charconv>
57#include <cstdio>
58#include <string>
59#include <string_view>
60
61#include "type-traits.h"
62#include "detail.h"
63
64// ----------------------------------------------------------------------------
65
66#if defined(__GNUC__)
67#pragma GCC diagnostic push
68#pragma GCC diagnostic ignored "-Wpadded"
69#pragma GCC diagnostic ignored "-Waggregate-return"
70#if defined(__clang__)
71#pragma clang diagnostic ignored "-Wc++98-compat"
72#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
73#endif
74#endif
75
76// ============================================================================
77
79{
80 // --------------------------------------------------------------------------
81
82 namespace detail
83 {
84 // ------------------------------------------------------------------------
85
114 struct colours
115 {
116 const char* none = "";
117 const char* pass
118 = "";
119 const char* fail
120 = "";
121 };
122
123 inline constexpr colours colours_red_green = {
124 "\033[0m",
125 "\033[32m",
126 "\033[31m"
127 };
128
129 // ========================================================================
130
151 {
152 public:
160
165
170
176 = delete;
177
183 = delete;
184
189
190 // ----------------------------------------------------------------------
191 // Primitive operator<< overloads.
192
200 operator<<(std::string_view sv);
201
209 operator<<(char c);
210
218 operator<<(const char* s);
219
227 operator<<(bool v);
228
234 expression_formatter& operator<<(std::nullptr_t);
235
243 operator<<(signed char c);
244
252 operator<<(unsigned char c);
253
261 operator<<(signed short v);
262
270 operator<<(unsigned short v);
271
279 operator<<(signed int v);
280
288 operator<<(unsigned int v);
289
297 operator<<(signed long v);
298
306 operator<<(unsigned long v);
307
315 operator<<(signed long long v);
316
324 operator<<(unsigned long long v);
325
333 operator<<(float v);
334
342 operator<<(double v);
343
351 operator<<(long double v);
352
353 // ----------------------------------------------------------------------
354 // Template operator<< overloads.
355
367 template <typename T>
369 operator<<(T* v);
370
378 template <class T>
381 operator<<(const T& t);
382
390 template <class T>
393
406 template <class T>
410 operator<< (const T& t);
411
412 // ----------------------------------------------------------------------
413 // Compound expression operator<< overloads (without colour).
414
423 template <class Lhs_T, class Rhs_T>
426
435 template <class Lhs_T, class Rhs_T>
438
447 template <class Lhs_T, class Rhs_T>
450
459 template <class Lhs_T, class Rhs_T>
462
471 template <class Lhs_T, class Rhs_T>
474
483 template <class Lhs_T, class Rhs_T>
486
495 template <class Lhs_T, class Rhs_T>
498
507 template <class Lhs_T, class Rhs_T>
510
518 template <class T>
520 operator<<(const detail::not_<T>& op);
521
522#if defined(__cpp_exceptions)
532 template <class Callable_T, class Exception_T>
535
543 template <class Callable_T>
546
554 template <class Callable_T>
557#endif
558
559 // ----------------------------------------------------------------------
560 // Buffer accessors.
561
569 [[nodiscard]] const std::string&
570 str () const noexcept;
571
579 [[nodiscard]] const char*
580 c_str () const noexcept;
581
590 void
591 clear () noexcept;
592
601 [[nodiscard]] bool
602 empty () const noexcept;
603
612 void
613 append (size_t count, char ch);
614
622 void
623 reserve (size_t capacity);
624
625 protected:
632 [[nodiscard]] inline auto
633 colour_ (const bool cond) const;
634
639
643 std::string buffer_{};
644 };
645
646 // ------------------------------------------------------------------------
647 } // namespace detail
648
649 // --------------------------------------------------------------------------
650} // namespace micro_os_plus::micro_test_plus
651
652#if defined(__GNUC__)
653#pragma GCC diagnostic pop
654#endif
655
656// ----------------------------------------------------------------------------
657
658#endif // __cplusplus
659
660// ============================================================================
661// Templates & constexpr implementations.
662
664
665// ----------------------------------------------------------------------------
666
667#endif // MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
668
669// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.