@micro-os-plus/micro-test-plus 3.3.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +412 -2
- package/CMakeLists.txt +134 -28
- package/README.md +3 -2
- package/config/xcdl-build.json +11 -4
- package/include/micro-os-plus/micro-test-plus/README.md +6 -0
- package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +267 -0
- package/include/micro-os-plus/micro-test-plus/detail.h +272 -1425
- package/include/micro-os-plus/micro-test-plus/exceptions.h +125 -0
- package/include/micro-os-plus/micro-test-plus/expression-formatter.h +669 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +15 -7
- package/include/micro-os-plus/micro-test-plus/inlines/{details-inlines.h → deferred-reporter-inlines.h} +66 -44
- package/include/micro-os-plus/micro-test-plus/inlines/detail-inlines.h +711 -0
- package/include/micro-os-plus/micro-test-plus/inlines/exceptions-inline.h +137 -0
- package/include/micro-os-plus/micro-test-plus/inlines/{test-reporter-inlines.h → expression-formatter-inlines.h} +232 -198
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +24 -20
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +50 -31
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +25 -19
- package/include/micro-os-plus/micro-test-plus/inlines/operators-inlines.h +275 -0
- package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +39 -21
- package/include/micro-os-plus/micro-test-plus/inlines/reporter-inlines.h +205 -0
- package/include/micro-os-plus/micro-test-plus/inlines/runner-inlines.h +151 -0
- package/include/micro-os-plus/micro-test-plus/inlines/runner-totals-inlines.h +152 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-inlines.h +555 -0
- package/include/micro-os-plus/micro-test-plus/inlines/timings-inlines.h +120 -0
- package/include/micro-os-plus/micro-test-plus/inlines/type-traits-inlines.h +231 -0
- package/include/micro-os-plus/micro-test-plus/inlines/utility-inlines.h +126 -0
- package/include/micro-os-plus/micro-test-plus/literals.h +12 -17
- package/include/micro-os-plus/micro-test-plus/math.h +14 -6
- package/include/micro-os-plus/micro-test-plus/operators.h +53 -209
- package/include/micro-os-plus/micro-test-plus/reflection.h +8 -4
- package/include/micro-os-plus/micro-test-plus/{test-reporter-basic.h → reporter-human.h} +80 -74
- package/include/micro-os-plus/micro-test-plus/{test-reporter-tap.h → reporter-tap.h} +77 -71
- package/include/micro-os-plus/micro-test-plus/reporter.h +619 -0
- package/include/micro-os-plus/micro-test-plus/runner-totals.h +250 -0
- package/include/micro-os-plus/micro-test-plus/runner.h +472 -0
- package/include/micro-os-plus/micro-test-plus/test.h +1013 -0
- package/include/micro-os-plus/micro-test-plus/timings.h +363 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +223 -577
- package/include/micro-os-plus/micro-test-plus/utility.h +136 -0
- package/include/micro-os-plus/micro-test-plus.h +42 -236
- package/meson.build +11 -6
- package/package.json +11 -3
- package/src/deferred-reporter.cpp +137 -0
- package/src/expression-formatter.cpp +289 -0
- package/src/reflection.cpp +97 -0
- package/src/reporter-human.cpp +816 -0
- package/src/reporter-tap.cpp +772 -0
- package/src/reporter.cpp +481 -0
- package/src/runner-totals.cpp +98 -0
- package/src/runner.cpp +669 -0
- package/src/test.cpp +503 -0
- package/src/timings.cpp +210 -0
- package/src/utility.cpp +163 -0
- package/.cmake-format.yaml +0 -11
- package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +0 -313
- package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +0 -115
- package/include/micro-os-plus/micro-test-plus/test-reporter.h +0 -846
- package/include/micro-os-plus/micro-test-plus/test-runner.h +0 -281
- package/include/micro-os-plus/micro-test-plus/test-suite.h +0 -492
- package/src/micro-test-plus.cpp +0 -316
- package/src/test-reporter-basic.cpp +0 -466
- package/src/test-reporter-tap.cpp +0 -530
- package/src/test-reporter.cpp +0 -399
- package/src/test-runner.cpp +0 -311
- package/src/test-suite.cpp +0 -304
package/src/reporter.cpp
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
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
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @file
|
|
20
|
+
* @brief C++ source file with implementations for the µTest++ test reporter
|
|
21
|
+
* methods.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This source file contains the core implementations for the test reporting
|
|
25
|
+
* facilities of the µTest++ framework. It provides lifecycle and utility
|
|
26
|
+
* behaviour for reporters, including command-line option parsing,
|
|
27
|
+
* output-file handling, informational banner emission, buffering helpers,
|
|
28
|
+
* stream operators, and pass/fail dispatch to reporter-specific prefix/
|
|
29
|
+
* suffix hooks.
|
|
30
|
+
*
|
|
31
|
+
* Concrete formatting behaviour is implemented by derived reporters
|
|
32
|
+
* (`reporter_human` and `reporter_tap`).
|
|
33
|
+
*
|
|
34
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
35
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
36
|
+
* of naming conflicts.
|
|
37
|
+
*
|
|
38
|
+
* This file must be included when building the µTest++ library.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
// ----------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
44
|
+
#include <micro-os-plus/config.h>
|
|
45
|
+
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
46
|
+
|
|
47
|
+
#if defined(MICRO_OS_PLUS_TRACE)
|
|
48
|
+
#include <micro-os-plus/diag/trace.h>
|
|
49
|
+
#endif // MICRO_OS_PLUS_TRACE
|
|
50
|
+
|
|
51
|
+
#include "micro-os-plus/micro-test-plus/reporter.h"
|
|
52
|
+
|
|
53
|
+
// ----------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
#if defined(__GNUC__)
|
|
56
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
57
|
+
#if defined(__clang__)
|
|
58
|
+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
59
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
60
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
61
|
+
#endif
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
// =============================================================================
|
|
65
|
+
|
|
66
|
+
namespace micro_os_plus::micro_test_plus
|
|
67
|
+
{
|
|
68
|
+
// --------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @details
|
|
72
|
+
* Moves the supplied argument vector into `argvs_` and scans it for
|
|
73
|
+
* the `--verbose`, `--quiet`, `--silent`, and `--output-file=` options,
|
|
74
|
+
* adjusting `verbosity_` and optionally opening the output file. If
|
|
75
|
+
* the output file path is specified but the file cannot be opened, the
|
|
76
|
+
* process exits with a diagnostic error message. The internal string
|
|
77
|
+
* buffer is pre-allocated to reduce dynamic allocation overhead.
|
|
78
|
+
*/
|
|
79
|
+
reporter::reporter (std::unique_ptr<std::vector<std::string_view>> argvs)
|
|
80
|
+
{
|
|
81
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
82
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
83
|
+
trace::printf ("%s\n", __PRETTY_FUNCTION__);
|
|
84
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
85
|
+
|
|
86
|
+
std::string_view output_file_sv{};
|
|
87
|
+
|
|
88
|
+
argvs_ = std::move (argvs);
|
|
89
|
+
|
|
90
|
+
static constexpr std::string_view output_file_prefix{ "--output-file=" };
|
|
91
|
+
if (argvs_)
|
|
92
|
+
{
|
|
93
|
+
const auto& args = *argvs_;
|
|
94
|
+
for (size_t i = 0; i < args.size (); ++i)
|
|
95
|
+
{
|
|
96
|
+
if (args[i] == "--verbose")
|
|
97
|
+
{
|
|
98
|
+
verbosity_ = verbosity::verbose;
|
|
99
|
+
}
|
|
100
|
+
else if (args[i] == "--quiet")
|
|
101
|
+
{
|
|
102
|
+
verbosity_ = verbosity::quiet;
|
|
103
|
+
}
|
|
104
|
+
else if (args[i] == "--silent")
|
|
105
|
+
{
|
|
106
|
+
verbosity_ = verbosity::silent;
|
|
107
|
+
}
|
|
108
|
+
else if (args[i].starts_with (output_file_prefix))
|
|
109
|
+
{
|
|
110
|
+
output_file_sv = args[i].substr (output_file_prefix.size ());
|
|
111
|
+
}
|
|
112
|
+
else if (args[i]
|
|
113
|
+
== output_file_prefix.substr (
|
|
114
|
+
0, output_file_prefix.size () - 1))
|
|
115
|
+
{
|
|
116
|
+
if (i + 1 < args.size ())
|
|
117
|
+
{
|
|
118
|
+
output_file_sv = args[++i];
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
{
|
|
122
|
+
fprintf (stderr, "error: --output-file option requires a "
|
|
123
|
+
"file path argument\n");
|
|
124
|
+
exit (1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!output_file_sv.empty ())
|
|
131
|
+
{
|
|
132
|
+
// .data() is safe: all string_views are views into argv[]
|
|
133
|
+
// entries, which are null-terminated C strings.
|
|
134
|
+
output_file_ = fopen (output_file_sv.data (), "w");
|
|
135
|
+
if (output_file_ == nullptr)
|
|
136
|
+
{
|
|
137
|
+
#if defined(__GNUC__)
|
|
138
|
+
#pragma GCC diagnostic push
|
|
139
|
+
#if defined(__clang__)
|
|
140
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
141
|
+
#endif
|
|
142
|
+
#endif
|
|
143
|
+
fprintf (stderr, "error: Failed to open output file '%.*s'\n",
|
|
144
|
+
static_cast<int> (output_file_sv.size ()),
|
|
145
|
+
output_file_sv.data ());
|
|
146
|
+
#if defined(__GNUC__)
|
|
147
|
+
#pragma GCC diagnostic pop
|
|
148
|
+
#endif
|
|
149
|
+
exit (1);
|
|
150
|
+
}
|
|
151
|
+
// The original string is zero terminated, so we can safely use .data()
|
|
152
|
+
// here.
|
|
153
|
+
output_file_path_ = output_file_sv.data ();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Pre-allocate buffer to reduce dynamic allocations.
|
|
157
|
+
buffer_.reserve (128);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @details
|
|
162
|
+
* If an output file was opened, it is flushed and closed, and a
|
|
163
|
+
* confirmation message naming the output file is written to `stdout`.
|
|
164
|
+
* If tracing is enabled, the function signature is output for
|
|
165
|
+
* diagnostic purposes.
|
|
166
|
+
*/
|
|
167
|
+
reporter::~reporter ()
|
|
168
|
+
{
|
|
169
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
170
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
171
|
+
trace::printf ("%s\n", __PRETTY_FUNCTION__);
|
|
172
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
173
|
+
|
|
174
|
+
if (output_file_ != nullptr)
|
|
175
|
+
{
|
|
176
|
+
fflush (output_file_);
|
|
177
|
+
fclose (output_file_);
|
|
178
|
+
|
|
179
|
+
#if defined(__GNUC__)
|
|
180
|
+
#pragma GCC diagnostic push
|
|
181
|
+
#if defined(__clang__)
|
|
182
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
183
|
+
#endif
|
|
184
|
+
#endif
|
|
185
|
+
printf ("Test output written to '%s'.\n", output_file_path_);
|
|
186
|
+
#if defined(__GNUC__)
|
|
187
|
+
#pragma GCC diagnostic pop
|
|
188
|
+
#endif
|
|
189
|
+
|
|
190
|
+
output_file_ = nullptr;
|
|
191
|
+
output_file_path_ = nullptr;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// --------------------------------------------------------------------------
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @details
|
|
199
|
+
* The `endl` function inserts a newline character into the specified
|
|
200
|
+
* `reporter` stream and flushes its output buffer. This operation
|
|
201
|
+
* ensures that each test output line is clearly separated and immediately
|
|
202
|
+
* visible, facilitating the readability and clarity of test results across
|
|
203
|
+
* all test cases and folders within the µTest++ framework.
|
|
204
|
+
*/
|
|
205
|
+
reporter&
|
|
206
|
+
endl (reporter& stream)
|
|
207
|
+
{
|
|
208
|
+
stream.endline ();
|
|
209
|
+
return stream;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @details
|
|
214
|
+
* This method appends a newline character to the internal output buffer of
|
|
215
|
+
* the `reporter` and immediately flushes the stream. This ensures that
|
|
216
|
+
* each line of test output is clearly separated and promptly displayed,
|
|
217
|
+
* enhancing the readability and organisation of test results across all test
|
|
218
|
+
* cases and folders.
|
|
219
|
+
*/
|
|
220
|
+
void
|
|
221
|
+
reporter::endline (void)
|
|
222
|
+
{
|
|
223
|
+
buffer_.append ("\n");
|
|
224
|
+
flush ();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @details
|
|
229
|
+
* This method writes the contents of the internal output buffer to the
|
|
230
|
+
* standard output stream without appending a newline character. After
|
|
231
|
+
* outputting the buffer, it is cleared to prepare for subsequent output.
|
|
232
|
+
* This approach ensures that test results are presented promptly and
|
|
233
|
+
* efficiently, supporting clear and organised reporting across all test
|
|
234
|
+
* cases and folders.
|
|
235
|
+
*/
|
|
236
|
+
void
|
|
237
|
+
reporter::write_buffer_to_stdout (void)
|
|
238
|
+
{
|
|
239
|
+
// Pass only the string, do not add an `\n` here.
|
|
240
|
+
printf ("%s", buffer_.c_str ());
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @details
|
|
245
|
+
* Writes the contents of `buffer_` to `output_file_` using `fprintf`
|
|
246
|
+
* without appending a newline. If `output_file_` is null, the call is
|
|
247
|
+
* a no-op.
|
|
248
|
+
*/
|
|
249
|
+
void
|
|
250
|
+
reporter::write_buffer_to_file_ (void)
|
|
251
|
+
{
|
|
252
|
+
// Pass only the string, do not add an `\n` here.
|
|
253
|
+
if (output_file_ != nullptr)
|
|
254
|
+
{
|
|
255
|
+
fprintf (output_file_, "%s", buffer_.c_str ());
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @details
|
|
261
|
+
* Constructs and emits two informational lines: the first lists the
|
|
262
|
+
* programme name and any command-line arguments; the second identifies
|
|
263
|
+
* the compiler (Clang, GCC, or MSVC) together with the version string,
|
|
264
|
+
* floating-point availability on bare-metal targets, exception support,
|
|
265
|
+
* and any active debug or trace macros. Both lines are written to the
|
|
266
|
+
* output file when one is open, and to `stdout` unless verbosity is
|
|
267
|
+
* set to `silent`.
|
|
268
|
+
*/
|
|
269
|
+
void
|
|
270
|
+
reporter::write_info_ (void)
|
|
271
|
+
{
|
|
272
|
+
if (argvs_ && !argvs_->empty ())
|
|
273
|
+
{
|
|
274
|
+
const auto& args = *argvs_;
|
|
275
|
+
std::string line;
|
|
276
|
+
line.reserve (256);
|
|
277
|
+
line.append (get_comment_prefix ());
|
|
278
|
+
line.append ("Running: ");
|
|
279
|
+
|
|
280
|
+
// Append only the file name part of argv[0].
|
|
281
|
+
const std::string_view arg0 = args[0];
|
|
282
|
+
const auto sep = arg0.rfind ('/');
|
|
283
|
+
line.append ((sep != std::string_view::npos) ? arg0.substr (sep + 1)
|
|
284
|
+
: arg0);
|
|
285
|
+
|
|
286
|
+
for (size_t i = 1; i < args.size (); ++i)
|
|
287
|
+
{
|
|
288
|
+
line.append (" ");
|
|
289
|
+
line.append (args[i]);
|
|
290
|
+
}
|
|
291
|
+
line.append ("\n");
|
|
292
|
+
|
|
293
|
+
if (output_file_ != nullptr)
|
|
294
|
+
fprintf (output_file_, "%s", line.c_str ());
|
|
295
|
+
|
|
296
|
+
#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
|
|
297
|
+
if (verbosity_ == verbosity::normal
|
|
298
|
+
|| verbosity_ == verbosity::verbose)
|
|
299
|
+
printf ("%s", line.c_str ());
|
|
300
|
+
#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
{
|
|
304
|
+
// Build the "Built with ..." line. For the output file the compiler
|
|
305
|
+
// version is omitted; for stdout it is appended via __VERSION__.
|
|
306
|
+
std::string line;
|
|
307
|
+
line.reserve (256);
|
|
308
|
+
line.append (get_comment_prefix ());
|
|
309
|
+
line.append ("Built with ");
|
|
310
|
+
#if defined(__clang__)
|
|
311
|
+
line.append ("clang " __VERSION__);
|
|
312
|
+
#elif defined(__GNUC__)
|
|
313
|
+
line.append ("GCC " __VERSION__);
|
|
314
|
+
#elif defined(_MSC_VER)
|
|
315
|
+
line.append ("MSVC");
|
|
316
|
+
char msvc_ver[16];
|
|
317
|
+
snprintf (msvc_ver, sizeof (msvc_ver), " - %d", _MSC_VER);
|
|
318
|
+
line.append (msvc_ver);
|
|
319
|
+
#else
|
|
320
|
+
line.append ("an unknown compiler");
|
|
321
|
+
#endif
|
|
322
|
+
#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
|
|
323
|
+
|| defined(WIN32))
|
|
324
|
+
// This is relevant only on bare-metal.
|
|
325
|
+
#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
|
|
326
|
+
line.append (", with FP");
|
|
327
|
+
#else
|
|
328
|
+
line.append (", no FP");
|
|
329
|
+
#endif
|
|
330
|
+
#endif
|
|
331
|
+
#if defined(__EXCEPTIONS)
|
|
332
|
+
line.append (", with exceptions");
|
|
333
|
+
#else
|
|
334
|
+
line.append (", no exceptions");
|
|
335
|
+
#endif
|
|
336
|
+
#if defined(MICRO_OS_PLUS_DEBUG)
|
|
337
|
+
line.append (", with MICRO_OS_PLUS_DEBUG");
|
|
338
|
+
#endif
|
|
339
|
+
#if defined(MICRO_OS_PLUS_TRACE)
|
|
340
|
+
line.append (", with MICRO_OS_PLUS_TRACE");
|
|
341
|
+
#endif
|
|
342
|
+
|
|
343
|
+
if (output_file_ != nullptr)
|
|
344
|
+
{
|
|
345
|
+
fprintf (output_file_, "%s\n", line.c_str ());
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
|
|
349
|
+
if (verbosity_ == verbosity::normal || verbosity_ == verbosity::verbose)
|
|
350
|
+
{
|
|
351
|
+
printf ("%s\n", line.c_str ());
|
|
352
|
+
}
|
|
353
|
+
#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* @details
|
|
359
|
+
* This method flushes the output buffer of the `reporter` by
|
|
360
|
+
* synchronising it with the standard output stream. This guarantees that all
|
|
361
|
+
* pending test output is immediately written and visible, ensuring prompt
|
|
362
|
+
* and reliable reporting of test results across all test cases and folders.
|
|
363
|
+
*/
|
|
364
|
+
void
|
|
365
|
+
reporter::flush (void)
|
|
366
|
+
{
|
|
367
|
+
fflush (stdout);
|
|
368
|
+
if (output_file_ != nullptr)
|
|
369
|
+
{
|
|
370
|
+
fflush (output_file_);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// --------------------------------------------------------------------------
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @details
|
|
378
|
+
* This operator overload enables manipulators, such as `endl`, to be used
|
|
379
|
+
* with the `reporter` stream in a manner similar to standard C++
|
|
380
|
+
* streams. When a manipulator function is passed, it is invoked with the
|
|
381
|
+
* current `reporter` instance, allowing for seamless integration of
|
|
382
|
+
* stream operations and improved readability of test output across all test
|
|
383
|
+
* cases and folders.
|
|
384
|
+
*/
|
|
385
|
+
reporter&
|
|
386
|
+
reporter::operator<< (reporter& (*func) (reporter&))
|
|
387
|
+
{
|
|
388
|
+
// Call the endl function.
|
|
389
|
+
(*func) (*this);
|
|
390
|
+
return *this;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* @details
|
|
395
|
+
* This operator overload appends the contents of the provided
|
|
396
|
+
* `std::string_view` to the internal output buffer of the `reporter`.
|
|
397
|
+
* It enables seamless streaming of string data into the reporter, supporting
|
|
398
|
+
* clear and efficient formatting of test output across all test cases and
|
|
399
|
+
* folders.
|
|
400
|
+
*/
|
|
401
|
+
reporter&
|
|
402
|
+
reporter::operator<< (std::string_view sv)
|
|
403
|
+
{
|
|
404
|
+
buffer_.append (sv);
|
|
405
|
+
return *this;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* @details
|
|
410
|
+
* This operator overload appends the specified character to the internal
|
|
411
|
+
* output buffer of the `reporter`. It enables efficient streaming of
|
|
412
|
+
* individual characters into the reporter, supporting precise and flexible
|
|
413
|
+
* formatting of test output across all test cases and folders.
|
|
414
|
+
*/
|
|
415
|
+
reporter&
|
|
416
|
+
reporter::operator<< (char c)
|
|
417
|
+
{
|
|
418
|
+
buffer_.append (1, c);
|
|
419
|
+
return *this;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* @details
|
|
424
|
+
* This operator overload appends the contents of the provided C-style string
|
|
425
|
+
* to the internal output buffer of the `reporter`. It enables efficient
|
|
426
|
+
* streaming of string literals and character arrays into the reporter,
|
|
427
|
+
* supporting clear and flexible formatting of test output across all test
|
|
428
|
+
* cases and folders.
|
|
429
|
+
*/
|
|
430
|
+
reporter&
|
|
431
|
+
reporter::operator<< (const char* s)
|
|
432
|
+
{
|
|
433
|
+
buffer_.append (s);
|
|
434
|
+
return *this;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @details
|
|
439
|
+
* Outputs a pass prefix, followed by either the provided message or, if
|
|
440
|
+
* the message is empty, the evaluated expression string itself. A pass
|
|
441
|
+
* suffix is then appended to complete the output.
|
|
442
|
+
*/
|
|
443
|
+
void
|
|
444
|
+
reporter::pass (std::string& message, const std::string& expression,
|
|
445
|
+
subtest& subtest)
|
|
446
|
+
{
|
|
447
|
+
output_pass_prefix_ (message, subtest);
|
|
448
|
+
|
|
449
|
+
if (message.empty ())
|
|
450
|
+
{
|
|
451
|
+
*this << expression;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
output_pass_suffix_ (subtest);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @details
|
|
459
|
+
* Reports a test failure, formatting the output with source location and,
|
|
460
|
+
* when `has_expression` is true, the pre-formatted expression string.
|
|
461
|
+
*/
|
|
462
|
+
void
|
|
463
|
+
reporter::fail (bool abort, std::string& message,
|
|
464
|
+
const std::string& expression, bool has_expression,
|
|
465
|
+
const reflection::source_location& location,
|
|
466
|
+
subtest& subtest)
|
|
467
|
+
{
|
|
468
|
+
output_fail_prefix_ (message, has_expression, location, subtest);
|
|
469
|
+
|
|
470
|
+
if (has_expression)
|
|
471
|
+
{
|
|
472
|
+
*this << expression;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
output_fail_suffix_ (location, abort, subtest);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// --------------------------------------------------------------------------
|
|
479
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
480
|
+
|
|
481
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @file
|
|
20
|
+
* @brief C++ source file with implementations for the µTest++ runner
|
|
21
|
+
* totals methods.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This source file contains the implementation of the
|
|
25
|
+
* `runner_totals::operator+=` method, which aggregates test result
|
|
26
|
+
* counters from one `runner_totals` instance into another. It
|
|
27
|
+
* accumulates successful checks, failed checks, and executed subtests.
|
|
28
|
+
*
|
|
29
|
+
* All definitions reside within the
|
|
30
|
+
* `micro_os_plus::micro_test_plus` namespace.
|
|
31
|
+
*
|
|
32
|
+
* This file must be included when building the µTest++ library.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// ----------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
38
|
+
#include <micro-os-plus/config.h>
|
|
39
|
+
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
40
|
+
|
|
41
|
+
#if defined(MICRO_OS_PLUS_TRACE)
|
|
42
|
+
#include <micro-os-plus/diag/trace.h>
|
|
43
|
+
#endif // MICRO_OS_PLUS_TRACE
|
|
44
|
+
|
|
45
|
+
#include "micro-os-plus/micro-test-plus/runner-totals.h"
|
|
46
|
+
|
|
47
|
+
// ----------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
#if defined(__GNUC__)
|
|
50
|
+
#if defined(__clang__)
|
|
51
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
52
|
+
#pragma clang diagnostic ignored "-Wpre-c++17-compat"
|
|
53
|
+
#endif
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
namespace micro_os_plus::micro_test_plus::detail
|
|
59
|
+
{
|
|
60
|
+
// ===========================================================================
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @details
|
|
64
|
+
* Adds the successful check count, failed check count, and executed
|
|
65
|
+
* subtest count of @p other to the corresponding members of this
|
|
66
|
+
* instance. Returns a reference to `*this` to support chaining.
|
|
67
|
+
* When tracing is enabled, the updated totals are output for
|
|
68
|
+
* diagnostic purposes.
|
|
69
|
+
*/
|
|
70
|
+
runner_totals&
|
|
71
|
+
runner_totals::operator+= (const runner_totals& other) noexcept
|
|
72
|
+
{
|
|
73
|
+
successful_checks_ += other.successful_checks ();
|
|
74
|
+
failed_checks_ += other.failed_checks ();
|
|
75
|
+
executed_subtests_ += other.executed_subtests ();
|
|
76
|
+
|
|
77
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
78
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
79
|
+
#if defined(__GNUC__)
|
|
80
|
+
#pragma GCC diagnostic push
|
|
81
|
+
#if defined(__clang__)
|
|
82
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
83
|
+
#endif
|
|
84
|
+
#endif
|
|
85
|
+
trace::printf ("%s -> +%zu -%zu in xs%zu\n", __PRETTY_FUNCTION__,
|
|
86
|
+
successful_checks_, failed_checks_, executed_subtests_);
|
|
87
|
+
#if defined(__GNUC__)
|
|
88
|
+
#pragma GCC diagnostic pop
|
|
89
|
+
#endif
|
|
90
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
91
|
+
|
|
92
|
+
return *this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// --------------------------------------------------------------------------
|
|
96
|
+
} // namespace micro_os_plus::micro_test_plus::detail
|
|
97
|
+
|
|
98
|
+
// ----------------------------------------------------------------------------
|