Skip to main content

expression-formatter.h File

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

Included Headers

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

132 inline constexpr colours colours_red_green = {
133 "\033[0m",
134 "\033[32m",
135 "\033[31m"
136 };

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_OS_PLUS_MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
48#define MICRO_OS_PLUS_MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
49
50// ----------------------------------------------------------------------------
51
52#if defined(__cplusplus)
53
54// ----------------------------------------------------------------------------
55
56#if __has_include("micro-os-plus/project-config.h")
57#include "micro-os-plus/project-config.h"
58#endif // __has_include("micro-os-plus/project-config.h")
59
60#if __has_include("micro-os-plus/micro-test-plus-defines.h")
61#include "micro-os-plus/micro-test-plus-defines.h"
62#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
63
64#include "type-traits.h"
65#include "detail.h"
66
67#include <charconv>
68#include <cstdio>
69#include <string>
70#include <string_view>
71
72// ----------------------------------------------------------------------------
73
74#if defined(__GNUC__)
75#pragma GCC diagnostic push
76
77#pragma GCC diagnostic ignored "-Wpadded"
78#pragma GCC diagnostic ignored "-Waggregate-return"
79#if defined(__clang__)
80#pragma clang diagnostic ignored "-Wc++98-compat"
81#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
82#endif // defined(__clang__)
83#endif // defined(__GNUC__)
84
85// ============================================================================
86
88{
89 // --------------------------------------------------------------------------
90
91 namespace detail
92 {
93 // ------------------------------------------------------------------------
94
123 struct colours
124 {
125 const char* none = "";
126 const char* pass
127 = "";
128 const char* fail
129 = "";
130 };
131
132 inline constexpr colours colours_red_green = {
133 "\033[0m",
134 "\033[32m",
135 "\033[31m"
136 };
137
138 // ========================================================================
139
160 {
161 public:
169
174
179
185 = delete;
186
192 = delete;
193
198
199 // ----------------------------------------------------------------------
200 // Primitive operator<< overloads.
201
209 operator<<(std::string_view sv);
210
218 operator<<(char c);
219
227 operator<<(const char* s);
228
236 operator<<(bool v);
237
243 expression_formatter& operator<<(std::nullptr_t);
244
252 operator<<(signed char c);
253
261 operator<<(unsigned char c);
262
270 operator<<(signed short v);
271
279 operator<<(unsigned short v);
280
288 operator<<(signed int v);
289
297 operator<<(unsigned int v);
298
306 operator<<(signed long v);
307
315 operator<<(unsigned long v);
316
324 operator<<(signed long long v);
325
333 operator<<(unsigned long long v);
334
342 operator<<(float v);
343
351 operator<<(double v);
352
360 operator<<(long double v);
361
362 // ----------------------------------------------------------------------
363 // Template operator<< overloads.
364
376 template <typename T>
378 operator<<(T* v);
379
387 template <class T>
390 operator<<(const T& t);
391
399 template <class T>
402
415 template <class T>
419 operator<< (const T& t);
420
421 // ----------------------------------------------------------------------
422 // Compound expression operator<< overloads (without colour).
423
432 template <class Lhs_T, class Rhs_T>
435
444 template <class Lhs_T, class Rhs_T>
447
456 template <class Lhs_T, class Rhs_T>
459
468 template <class Lhs_T, class Rhs_T>
471
480 template <class Lhs_T, class Rhs_T>
483
492 template <class Lhs_T, class Rhs_T>
495
504 template <class Lhs_T, class Rhs_T>
507
516 template <class Lhs_T, class Rhs_T>
519
527 template <class T>
529 operator<<(const detail::not_<T>& op);
530
531#if defined(__cpp_exceptions)
532
542 template <class Callable_T, class Exception_T>
545
553 template <class Callable_T>
556
564 template <class Callable_T>
567
568#endif // defined(__cpp_exceptions)
569
570 // ----------------------------------------------------------------------
571 // Buffer accessors.
572
580 [[nodiscard]] const std::string&
581 str () const noexcept;
582
590 [[nodiscard]] const char*
591 c_str () const noexcept;
592
601 void
602 clear () noexcept;
603
612 [[nodiscard]] bool
613 empty () const noexcept;
614
623 void
624 append (size_t count, char ch);
625
633 void
634 reserve (size_t capacity);
635
636 protected:
643 [[nodiscard]] inline auto
644 colour_ (const bool cond) const;
645
650
654 std::string buffer_{};
655 };
656
657 // ------------------------------------------------------------------------
658 } // namespace detail
659
660 // --------------------------------------------------------------------------
661} // namespace micro_os_plus::micro_test_plus
662
663#if defined(__GNUC__)
664#pragma GCC diagnostic pop
665#endif // defined(__GNUC__)
666
667// ----------------------------------------------------------------------------
668
669#endif // defined(__cplusplus)
670
671// ============================================================================
672// Templates, inlines & constexpr implementations.
673
675
676// ----------------------------------------------------------------------------
677
678#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
679
680// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.