micro-test-plus 5.0.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
reporter-inlines.h
Go to the documentation of this file.
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.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
48
49#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_REPORTER_INLINES_H_
50#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_REPORTER_INLINES_H_
51
52// ----------------------------------------------------------------------------
53
54#if defined(__cplusplus)
55
56// ----------------------------------------------------------------------------
57
58#include <cstdio>
59#include <cstring>
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 "-Wunknown-warning-option"
69#pragma clang diagnostic ignored "-Wc++98-compat"
70#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
71#endif // defined(__clang__)
72#endif // defined(__GNUC__)
73
74// ============================================================================
75
77{
78 // --------------------------------------------------------------------------
79
80 inline detail::indent_t
81 indent (size_t level)
82 {
83 return { level };
84 }
85
86 // ==========================================================================
87
92 inline auto
94 {
95 return verbosity_;
96 }
97
109 {
110 return expression_;
111 }
112
118 inline auto
119 reporter::colour_ (const bool cond) const
120 {
121 return cond ? colours_.pass : colours_.fail;
122 }
123
124 // --------------------------------------------------------------------------
125
144 template <typename T>
147 {
148 if (v == nullptr)
149 {
150 // Explicitly render null pointers as "0x0" to avoid platform-specific
151 // representations such as "(nil)" on Linux/glibc.
152 buffer_.append ("0x0");
153 return *this;
154 }
155
156#if defined(__GNUC__)
157#pragma GCC diagnostic push
158
159#if defined(__clang__)
160#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
161#endif // defined(__clang__)
162#endif // defined(__GNUC__)
163
164 char buff[20];
165 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
166 buffer_.append (buff);
167
168#if defined(__GNUC__)
169#pragma GCC diagnostic pop
170#endif // defined(__GNUC__)
171
172 return *this;
173 }
174
187 template <class T>
188 requires std::is_arithmetic_v<T>
191 {
193 return *this;
194 }
195
196 // --------------------------------------------------------------------------
197} // namespace micro_os_plus::micro_test_plus
198
199#if defined(__GNUC__)
200#pragma GCC diagnostic pop
201#endif // defined(__GNUC__)
202
203// ----------------------------------------------------------------------------
204
205#endif // defined(__cplusplus)
206
207// ----------------------------------------------------------------------------
208
209#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_REPORTER_INLINES_H_
210
211// ----------------------------------------------------------------------------
Formats values and expressions into an owned string buffer.
reporter(std::unique_ptr< std::vector< std::string_view > > argvs)
Constructor for the reporter class.
Definition reporter.cpp:80
auto verbosity() const -> micro_test_plus::verbosity
Returns the current verbosity level.
detail::expression_formatter expression_
Expression formatter for pass and fail reporting.
Definition reporter.h:572
std::string buffer_
Output accumulation buffer.
Definition reporter.h:561
auto colour_(const bool cond) const
Selects the appropriate colour code based on a condition.
detail::expression_formatter & expression()
Provides access to the expression formatter for this reporter.
reporter & operator<<(std::string_view sv)
Output operator for std::string_view.
Definition reporter.cpp:385
detail::colours colours_
ANSI colour codes for output formatting.
Definition reporter.h:551
enum verbosity verbosity_
The verbosity level for test reporting.
Definition reporter.h:546
void append_number_(std::string &buffer, T v)
Appends the string representation of a numeric value to a buffer, using std::to_chars for allocation-...
Primary namespace for the µTest++ testing framework.
detail::indent_t indent(size_t level)
Factory function that creates an indent_t manipulator.
Parameterised stream manipulator for outputting indentation.
Definition reporter.h:147