micro-test-plus
5.0.0
µTest++ Testing Framework
Toggle main menu visibility
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_TEST_PLUS_TEST_REPORTER_INLINES_H_
50
#define MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
51
52
// ----------------------------------------------------------------------------
53
54
#ifdef __cplusplus
55
56
// ----------------------------------------------------------------------------
57
58
#include <cstdio>
59
#include <cstring>
60
61
// ----------------------------------------------------------------------------
62
63
#if defined(__GNUC__)
64
#pragma GCC diagnostic push
65
#pragma GCC diagnostic ignored "-Waggregate-return"
66
#if defined(__clang__)
67
#pragma clang diagnostic ignored "-Wunknown-warning-option"
68
#pragma clang diagnostic ignored "-Wc++98-compat"
69
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
70
#endif
71
#endif
72
73
// ============================================================================
74
75
namespace
micro_os_plus::micro_test_plus
76
{
77
// --------------------------------------------------------------------------
78
79
inline
detail::indent_t
80
indent
(
size_t
level)
81
{
82
return
{ level };
83
}
84
85
// ==========================================================================
86
91
inline
auto
92
reporter::verbosity
() const ->
micro_test_plus
::
verbosity
93
{
94
return
verbosity_
;
95
}
96
106
inline
detail::expression_formatter
&
107
reporter::expression
()
108
{
109
return
expression_
;
110
}
111
117
inline
auto
118
reporter::colour_
(
const
bool
cond)
const
119
{
120
return
cond ?
colours_
.pass :
colours_
.fail;
121
}
122
123
// --------------------------------------------------------------------------
124
143
template
<
typename
T>
144
reporter
&
145
reporter::operator<<
(T* v)
146
{
147
if
(v ==
nullptr
)
148
{
149
// Explicitly render null pointers as "0x0" to avoid platform-specific
150
// representations such as "(nil)" on Linux/glibc.
151
buffer_
.append (
"0x0"
);
152
return
*
this
;
153
}
154
#if defined(__GNUC__)
155
#pragma GCC diagnostic push
156
#if defined(__clang__)
157
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
158
#endif
159
#endif
160
char
buff[20];
161
snprintf (buff,
sizeof
(buff),
"%p"
,
reinterpret_cast<
void
*
>
(v));
162
buffer_
.append (buff);
163
#if defined(__GNUC__)
164
#pragma GCC diagnostic pop
165
#endif
166
167
return
*
this
;
168
}
169
182
template
<
class
T>
183
requires
std::is_arithmetic_v<T>
184
reporter
&
185
reporter::operator<<
(T v)
186
{
187
detail::append_number_
(
buffer_
, v);
188
return
*
this
;
189
}
190
191
// --------------------------------------------------------------------------
192
}
// namespace micro_os_plus::micro_test_plus
193
194
#if defined(__GNUC__)
195
#pragma GCC diagnostic pop
196
#endif
197
198
// ----------------------------------------------------------------------------
199
200
#endif
// __cplusplus
201
202
// ----------------------------------------------------------------------------
203
204
#endif
// MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
205
206
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::detail::expression_formatter
Formats values and expressions into an owned string buffer.
Definition
expression-formatter.h:151
micro_os_plus::micro_test_plus::reporter::reporter
reporter(std::unique_ptr< std::vector< std::string_view > > argvs)
Constructor for the reporter class.
Definition
reporter.cpp:85
micro_os_plus::micro_test_plus::reporter::verbosity
auto verbosity() const -> micro_test_plus::verbosity
Returns the current verbosity level.
Definition
reporter-inlines.h:92
micro_os_plus::micro_test_plus::reporter::expression_
detail::expression_formatter expression_
Expression formatter for pass and fail reporting.
Definition
reporter.h:563
micro_os_plus::micro_test_plus::reporter::buffer_
std::string buffer_
Output accumulation buffer.
Definition
reporter.h:552
micro_os_plus::micro_test_plus::reporter::colour_
auto colour_(const bool cond) const
Selects the appropriate colour code based on a condition.
Definition
reporter-inlines.h:118
micro_os_plus::micro_test_plus::reporter::expression
detail::expression_formatter & expression()
Provides access to the expression formatter for this reporter.
Definition
reporter-inlines.h:107
micro_os_plus::micro_test_plus::reporter::operator<<
reporter & operator<<(std::string_view sv)
Output operator for std::string_view.
Definition
reporter.cpp:408
micro_os_plus::micro_test_plus::reporter::colours_
detail::colours colours_
ANSI colour codes for output formatting.
Definition
reporter.h:542
micro_os_plus::micro_test_plus::reporter::verbosity_
enum verbosity verbosity_
The verbosity level for test reporting.
Definition
reporter.h:537
micro_os_plus::micro_test_plus::detail::append_number_
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-...
Definition
detail-inlines.h:654
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
micro_os_plus::micro_test_plus::indent
detail::indent_t indent(size_t level)
Factory function that creates an indent_t manipulator.
Definition
reporter-inlines.h:80
micro_os_plus::micro_test_plus::detail::indent_t
Parameterised stream manipulator for outputting indentation.
Definition
reporter.h:138
include
micro-os-plus
micro-test-plus
inlines
reporter-inlines.h
Generated by
1.17.0