@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
|
@@ -0,0 +1,619 @@
|
|
|
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++ header file with declarations for the µTest++ test reporter.
|
|
21
|
+
*
|
|
22
|
+
* @details
|
|
23
|
+
* This header provides the declarations for the test reporting facilities used
|
|
24
|
+
* within the µTest++ framework. It defines the interfaces for formatting and
|
|
25
|
+
* outputting test results, including operator overloads for a wide range of
|
|
26
|
+
* value types, containers, and comparison expressions, as well as structured
|
|
27
|
+
* output for logical and exception-related assertions.
|
|
28
|
+
*
|
|
29
|
+
* The test reporter is responsible for presenting test outcomes in a clear,
|
|
30
|
+
* consistent, and expressive manner, supporting both value and pointer
|
|
31
|
+
* semantics, and providing detailed diagnostics for both successful and failed
|
|
32
|
+
* test cases. Special attention is given to formatting, colour highlighting,
|
|
33
|
+
* and extensibility, enabling professional and readable test reports suitable
|
|
34
|
+
* for embedded and general C++ development.
|
|
35
|
+
*
|
|
36
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
37
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
38
|
+
* of naming conflicts.
|
|
39
|
+
*
|
|
40
|
+
* The header files are organised within the
|
|
41
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
42
|
+
* modular codebase.
|
|
43
|
+
*
|
|
44
|
+
* This file is intended solely for internal use within the framework and
|
|
45
|
+
* should not be included directly by user code.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
#ifndef MICRO_TEST_PLUS_TEST_REPORTER_H_
|
|
49
|
+
#define MICRO_TEST_PLUS_TEST_REPORTER_H_
|
|
50
|
+
|
|
51
|
+
// ----------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
#ifdef __cplusplus
|
|
54
|
+
|
|
55
|
+
// ----------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
#include <cstdio>
|
|
58
|
+
#include <string_view>
|
|
59
|
+
#include <string>
|
|
60
|
+
#include <memory>
|
|
61
|
+
#include <vector>
|
|
62
|
+
#include <charconv>
|
|
63
|
+
|
|
64
|
+
#include "type-traits.h"
|
|
65
|
+
#include "detail.h"
|
|
66
|
+
#include "expression-formatter.h"
|
|
67
|
+
#include "reflection.h"
|
|
68
|
+
|
|
69
|
+
// ----------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
#if defined(__GNUC__)
|
|
72
|
+
#pragma GCC diagnostic push
|
|
73
|
+
#pragma GCC diagnostic ignored "-Wpadded"
|
|
74
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
75
|
+
#if defined(__clang__)
|
|
76
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
77
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
78
|
+
#endif
|
|
79
|
+
#endif
|
|
80
|
+
|
|
81
|
+
// =============================================================================
|
|
82
|
+
|
|
83
|
+
namespace micro_os_plus::micro_test_plus
|
|
84
|
+
{
|
|
85
|
+
// --------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @brief The verbosity levels for test reporting.
|
|
89
|
+
*
|
|
90
|
+
* @details
|
|
91
|
+
* The `verbosity` enumeration defines the available levels of detail for
|
|
92
|
+
* test output produced by the reporting system. These levels control the
|
|
93
|
+
* amount and type of information displayed during test execution, allowing
|
|
94
|
+
* users to tailor the output to their specific requirements.
|
|
95
|
+
*
|
|
96
|
+
* Selecting an appropriate verbosity level enhances the usability of test
|
|
97
|
+
* reports, whether for concise summaries or comprehensive diagnostics.
|
|
98
|
+
*
|
|
99
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
100
|
+
*/
|
|
101
|
+
enum class verbosity
|
|
102
|
+
{
|
|
103
|
+
silent = 0, /**< No output is produced; only the exit code is returned. */
|
|
104
|
+
quiet = 1, /**< Displays results for test suites only. */
|
|
105
|
+
normal = 2, /**< Displays results for test suites and failed test cases. */
|
|
106
|
+
verbose = 3 /**< Displays all results, including passed checks, for maximum
|
|
107
|
+
detail. */
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Forward definitions.
|
|
111
|
+
class reporter;
|
|
112
|
+
class runner;
|
|
113
|
+
class suite;
|
|
114
|
+
class subtest;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @brief Output stream manipulator for ending a line in test reports.
|
|
118
|
+
*
|
|
119
|
+
* @param stream Reference to the `reporter` instance.
|
|
120
|
+
* @return Reference to the same `reporter` instance, enabling chaining
|
|
121
|
+
* of output operations.
|
|
122
|
+
*/
|
|
123
|
+
reporter&
|
|
124
|
+
endl (reporter& stream);
|
|
125
|
+
|
|
126
|
+
namespace detail
|
|
127
|
+
{
|
|
128
|
+
// ------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @brief Parameterised stream manipulator for outputting indentation.
|
|
132
|
+
*
|
|
133
|
+
* @details
|
|
134
|
+
* Holds the indentation level; used with `operator<<` on `reporter`
|
|
135
|
+
* so that `*this << indent(n) << "text"` works naturally in chains.
|
|
136
|
+
*/
|
|
137
|
+
struct indent_t
|
|
138
|
+
{
|
|
139
|
+
size_t level; /**< @brief Number of four-space indentation levels. */
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// ------------------------------------------------------------------------
|
|
143
|
+
} // namespace detail
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @brief Factory function that creates an `indent_t` manipulator.
|
|
147
|
+
*
|
|
148
|
+
* @param level The number of four-space indentation levels.
|
|
149
|
+
* @return An `indent_t` value for use with `operator<<`.
|
|
150
|
+
*/
|
|
151
|
+
[[nodiscard]] detail::indent_t
|
|
152
|
+
indent (size_t level);
|
|
153
|
+
|
|
154
|
+
// ==========================================================================
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @brief Reporter to display test results, including operand values and
|
|
158
|
+
* types for failures.
|
|
159
|
+
*
|
|
160
|
+
* @details
|
|
161
|
+
* The `reporter` class is responsible for formatting and presenting
|
|
162
|
+
* test results within the µTest++ framework. It provides a comprehensive
|
|
163
|
+
* suite of output operators for a wide range of data types, containers, and
|
|
164
|
+
* comparator expressions, enabling detailed and informative reporting of
|
|
165
|
+
* test outcomes.
|
|
166
|
+
*
|
|
167
|
+
* For failed tests, the reporter prints the actual values of the operands
|
|
168
|
+
* along with their types, supporting precise diagnostics and efficient
|
|
169
|
+
* debugging. The class supports multiple verbosity levels and colour-coded
|
|
170
|
+
* output to distinguish between successful and failed tests, thereby
|
|
171
|
+
* enhancing the clarity and professionalism of test reports.
|
|
172
|
+
*
|
|
173
|
+
* The `reporter` also offers methods for reporting the commencement and
|
|
174
|
+
* completion of test cases and suites, as well as for handling pass and fail
|
|
175
|
+
* conditions. Additional features include output stream manipulators,
|
|
176
|
+
* support for exception-related expressions, and configurable formatting
|
|
177
|
+
* options.
|
|
178
|
+
*
|
|
179
|
+
* All members and methods are defined within the
|
|
180
|
+
* `micro_os_plus::micro_test_plus` namespace, ensuring clear separation from
|
|
181
|
+
* user code and minimising the risk of naming conflicts.
|
|
182
|
+
*
|
|
183
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
184
|
+
*/
|
|
185
|
+
class reporter
|
|
186
|
+
{
|
|
187
|
+
public:
|
|
188
|
+
/**
|
|
189
|
+
* @brief Constructor for the reporter class.
|
|
190
|
+
*
|
|
191
|
+
* @param argvs Owning pointer to the command-line arguments vector;
|
|
192
|
+
* the reporter takes ownership via move.
|
|
193
|
+
*/
|
|
194
|
+
reporter (std::unique_ptr<std::vector<std::string_view>> argvs);
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @brief Virtual destructor for the reporter class.
|
|
198
|
+
*/
|
|
199
|
+
virtual ~reporter ();
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @brief Output operator for std::string_view.
|
|
203
|
+
*
|
|
204
|
+
* @param sv The string view to output.
|
|
205
|
+
* @return Reference to the current reporter instance.
|
|
206
|
+
*/
|
|
207
|
+
reporter&
|
|
208
|
+
operator<< (std::string_view sv);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @brief Output operator for a single character.
|
|
212
|
+
*
|
|
213
|
+
* @param c The character to output.
|
|
214
|
+
* @return Reference to the current reporter instance.
|
|
215
|
+
*/
|
|
216
|
+
reporter&
|
|
217
|
+
operator<< (char c);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @brief Output operator for a constant character string.
|
|
221
|
+
*
|
|
222
|
+
* @param s The string to output.
|
|
223
|
+
* @return Reference to the current reporter instance.
|
|
224
|
+
*/
|
|
225
|
+
reporter&
|
|
226
|
+
operator<< (const char* s);
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @brief Output operator for boolean values.
|
|
230
|
+
*
|
|
231
|
+
* @param v The boolean value to output.
|
|
232
|
+
* @return Reference to the current reporter instance.
|
|
233
|
+
*/
|
|
234
|
+
reporter&
|
|
235
|
+
operator<< (bool v);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @brief Output operator for nullptr.
|
|
239
|
+
* @return Reference to the current reporter instance.
|
|
240
|
+
*/
|
|
241
|
+
reporter& operator<< (std::nullptr_t);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @brief Output operator for arithmetic types, with type suffixes.
|
|
245
|
+
*
|
|
246
|
+
* @tparam T The arithmetic type.
|
|
247
|
+
*
|
|
248
|
+
* @param v The value to output.
|
|
249
|
+
* @return Reference to the current reporter instance.
|
|
250
|
+
*/
|
|
251
|
+
template <class T>
|
|
252
|
+
requires std::is_arithmetic_v<T>
|
|
253
|
+
reporter&
|
|
254
|
+
operator<< (T v);
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @brief Output operator to display any pointer.
|
|
258
|
+
*
|
|
259
|
+
* @tparam T The type of the pointer.
|
|
260
|
+
*
|
|
261
|
+
* @param v The pointer value to output.
|
|
262
|
+
* @return Reference to the current reporter instance.
|
|
263
|
+
*/
|
|
264
|
+
template <typename T>
|
|
265
|
+
reporter&
|
|
266
|
+
operator<< (T* v);
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @brief Output operator to display the endl.
|
|
270
|
+
*
|
|
271
|
+
* @param func Function pointer to the stream manipulator.
|
|
272
|
+
* @return Reference to the current reporter instance.
|
|
273
|
+
*/
|
|
274
|
+
reporter&
|
|
275
|
+
operator<< (reporter& (*func) (reporter&));
|
|
276
|
+
|
|
277
|
+
// ------------------------------------------------------------------------
|
|
278
|
+
// Specific operators.
|
|
279
|
+
|
|
280
|
+
// ------------------------------------------------------------------------
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @brief Inserts a line ending into the output buffer.
|
|
284
|
+
*
|
|
285
|
+
* @par Parameters
|
|
286
|
+
* None.
|
|
287
|
+
* @par Returns
|
|
288
|
+
* Nothing.
|
|
289
|
+
*/
|
|
290
|
+
void
|
|
291
|
+
endline (void);
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @brief Output the current buffered content.
|
|
295
|
+
*
|
|
296
|
+
* @note Public because `deferred_reporter_base` calls this
|
|
297
|
+
* from its destructor when aborting, after the subtest
|
|
298
|
+
* instance is no longer accessible via the normal
|
|
299
|
+
* reporting path.
|
|
300
|
+
*
|
|
301
|
+
* @par Parameters
|
|
302
|
+
* None.
|
|
303
|
+
* @par Returns
|
|
304
|
+
* Nothing.
|
|
305
|
+
*/
|
|
306
|
+
void
|
|
307
|
+
write_buffer_to_stdout (void);
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* @brief Flush the current buffered content.
|
|
311
|
+
*
|
|
312
|
+
* @par Parameters
|
|
313
|
+
* None.
|
|
314
|
+
* @par Returns
|
|
315
|
+
* Nothing.
|
|
316
|
+
*/
|
|
317
|
+
void
|
|
318
|
+
flush (void);
|
|
319
|
+
|
|
320
|
+
// ------------------------------------------------------------------------
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @brief Report a passed condition.
|
|
324
|
+
*
|
|
325
|
+
* @param message The message to display.
|
|
326
|
+
* @param expression The string representation of the expression.
|
|
327
|
+
* @param subtest The subtest that owns this check.
|
|
328
|
+
* @par Returns
|
|
329
|
+
* Nothing.
|
|
330
|
+
*/
|
|
331
|
+
void
|
|
332
|
+
pass (std::string& message, const std::string& expression,
|
|
333
|
+
subtest& subtest);
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @brief Report a failed condition.
|
|
337
|
+
*
|
|
338
|
+
* @param abort Whether to abort execution after failure.
|
|
339
|
+
* @param message The message to display.
|
|
340
|
+
* @param expression The string representation of the expression.
|
|
341
|
+
* @param has_expression Whether the expression is a compound op to
|
|
342
|
+
* display.
|
|
343
|
+
* @param location The source location of the failure.
|
|
344
|
+
* @param subtest The subtest that owns this check.
|
|
345
|
+
* @par Returns
|
|
346
|
+
* Nothing.
|
|
347
|
+
*/
|
|
348
|
+
void
|
|
349
|
+
fail (bool abort, std::string& message, const std::string& expression,
|
|
350
|
+
bool has_expression, const reflection::source_location& location,
|
|
351
|
+
subtest& subtest);
|
|
352
|
+
|
|
353
|
+
// ------------------------------------------------------------------------
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @brief Mark the beginning of a test session.
|
|
357
|
+
*
|
|
358
|
+
* @param runner Reference to the test runner.
|
|
359
|
+
* @par Returns
|
|
360
|
+
* Nothing.
|
|
361
|
+
*/
|
|
362
|
+
virtual void
|
|
363
|
+
begin_session (runner& runner)
|
|
364
|
+
= 0;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @brief Mark the end of a test session.
|
|
368
|
+
*
|
|
369
|
+
* @param runner Reference to the test runner.
|
|
370
|
+
* @par Returns
|
|
371
|
+
* Nothing.
|
|
372
|
+
*/
|
|
373
|
+
virtual void
|
|
374
|
+
end_session (runner& runner)
|
|
375
|
+
= 0;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @brief Mark the beginning of a test suite.
|
|
379
|
+
*
|
|
380
|
+
* @param suite Reference to the test suite.
|
|
381
|
+
* @par Returns
|
|
382
|
+
* Nothing.
|
|
383
|
+
*/
|
|
384
|
+
virtual void
|
|
385
|
+
begin_suite (suite& suite)
|
|
386
|
+
= 0;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @brief Mark the end of a test suite.
|
|
390
|
+
*
|
|
391
|
+
* @param suite Reference to the test suite.
|
|
392
|
+
* @par Returns
|
|
393
|
+
* Nothing.
|
|
394
|
+
*/
|
|
395
|
+
virtual void
|
|
396
|
+
end_suite (suite& suite)
|
|
397
|
+
= 0;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* @brief Mark the beginning of a subtest.
|
|
401
|
+
*
|
|
402
|
+
* @param subtest Reference to the subtest.
|
|
403
|
+
* @par Returns
|
|
404
|
+
* Nothing.
|
|
405
|
+
*/
|
|
406
|
+
virtual void
|
|
407
|
+
begin_subtest (subtest& subtest)
|
|
408
|
+
= 0;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @brief Mark the end of a subtest.
|
|
412
|
+
*
|
|
413
|
+
* @param subtest Reference to the subtest.
|
|
414
|
+
* @par Returns
|
|
415
|
+
* Nothing.
|
|
416
|
+
*/
|
|
417
|
+
virtual void
|
|
418
|
+
end_subtest (subtest& subtest)
|
|
419
|
+
= 0;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* @brief Returns the comment-prefix string used by this reporter format.
|
|
423
|
+
*
|
|
424
|
+
* @par Parameters
|
|
425
|
+
* None.
|
|
426
|
+
* @return A null-terminated prefix string.
|
|
427
|
+
*/
|
|
428
|
+
virtual const char*
|
|
429
|
+
get_comment_prefix (void)
|
|
430
|
+
= 0;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* @brief Returns the current verbosity level.
|
|
434
|
+
*
|
|
435
|
+
* @par Parameters
|
|
436
|
+
* None.
|
|
437
|
+
* @return The active `verbosity` value.
|
|
438
|
+
*/
|
|
439
|
+
auto
|
|
440
|
+
verbosity () const -> micro_test_plus::verbosity;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* @brief Provides access to the expression formatter for this reporter.
|
|
444
|
+
*
|
|
445
|
+
* @par Parameters
|
|
446
|
+
* None.
|
|
447
|
+
* @return Reference to the `expression_formatter` instance used by this
|
|
448
|
+
* reporter.
|
|
449
|
+
*/
|
|
450
|
+
detail::expression_formatter&
|
|
451
|
+
expression ();
|
|
452
|
+
|
|
453
|
+
// ------------------------------------------------------------------------
|
|
454
|
+
|
|
455
|
+
protected:
|
|
456
|
+
/**
|
|
457
|
+
* @brief Selects the appropriate colour code based on a condition.
|
|
458
|
+
*
|
|
459
|
+
* @param cond Boolean value indicating pass (true) or fail (false).
|
|
460
|
+
* @return The corresponding ANSI colour code as a string.
|
|
461
|
+
*/
|
|
462
|
+
[[nodiscard]] inline auto
|
|
463
|
+
colour_ (const bool cond) const;
|
|
464
|
+
|
|
465
|
+
void
|
|
466
|
+
write_buffer_to_file_ (void);
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @brief Appends informational (non-result) text to the output buffer.
|
|
470
|
+
*
|
|
471
|
+
* @par Parameters
|
|
472
|
+
* None.
|
|
473
|
+
* @par Returns
|
|
474
|
+
* Nothing.
|
|
475
|
+
*/
|
|
476
|
+
void
|
|
477
|
+
write_info_ (void);
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* @brief Outputs the prefix for a passing condition.
|
|
481
|
+
*
|
|
482
|
+
* @param message The message to display.
|
|
483
|
+
* @param subtest The subtest that owns this check.
|
|
484
|
+
* @par Returns
|
|
485
|
+
* Nothing.
|
|
486
|
+
*/
|
|
487
|
+
virtual void
|
|
488
|
+
output_pass_prefix_ (std::string& message, subtest& subtest)
|
|
489
|
+
= 0;
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* @brief Outputs the suffix for a passing condition.
|
|
493
|
+
*
|
|
494
|
+
* @param subtest The subtest that owns this check.
|
|
495
|
+
* @par Returns
|
|
496
|
+
* Nothing.
|
|
497
|
+
*/
|
|
498
|
+
virtual void
|
|
499
|
+
output_pass_suffix_ (subtest& subtest)
|
|
500
|
+
= 0;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* @brief Outputs the prefix for a failing condition.
|
|
504
|
+
*
|
|
505
|
+
* @param message The message to display.
|
|
506
|
+
* @param has_expression Whether the failure is associated with an
|
|
507
|
+
* expression.
|
|
508
|
+
* @param location The source location of the failure.
|
|
509
|
+
* @param subtest The subtest that owns this check.
|
|
510
|
+
* @par Returns
|
|
511
|
+
* Nothing.
|
|
512
|
+
*/
|
|
513
|
+
virtual void
|
|
514
|
+
output_fail_prefix_ (std::string& message, const bool has_expression,
|
|
515
|
+
const reflection::source_location& location,
|
|
516
|
+
subtest& subtest)
|
|
517
|
+
= 0;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* @brief Outputs the suffix for a failing condition.
|
|
521
|
+
*
|
|
522
|
+
* @param location The source location of the failure.
|
|
523
|
+
* @param abort Whether to abort execution after failure.
|
|
524
|
+
* @param subtest The subtest that owns this check.
|
|
525
|
+
* @par Returns
|
|
526
|
+
* Nothing.
|
|
527
|
+
*/
|
|
528
|
+
virtual void
|
|
529
|
+
output_fail_suffix_ (const reflection::source_location& location,
|
|
530
|
+
bool abort, subtest& subtest)
|
|
531
|
+
= 0;
|
|
532
|
+
|
|
533
|
+
protected:
|
|
534
|
+
/**
|
|
535
|
+
* @brief The verbosity level for test reporting.
|
|
536
|
+
*/
|
|
537
|
+
enum verbosity verbosity_ = verbosity::normal;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* @brief ANSI colour codes for output formatting.
|
|
541
|
+
*/
|
|
542
|
+
detail::colours colours_{};
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* @brief Output accumulation buffer.
|
|
546
|
+
*
|
|
547
|
+
* @details
|
|
548
|
+
* Accumulates all reporter output until it is written to standard
|
|
549
|
+
* output or the output file via `write_buffer_to_stdout()` or
|
|
550
|
+
* `write_buffer_to_file_()`.
|
|
551
|
+
*/
|
|
552
|
+
std::string buffer_{};
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* @brief Expression formatter for pass and fail reporting.
|
|
556
|
+
*
|
|
557
|
+
* @details
|
|
558
|
+
* Used in `pass()` and `fail()` to format expression values before
|
|
559
|
+
* appending the result to `buffer_`. Will also be used by
|
|
560
|
+
* `detail::deferred_reporter` to pre-format expressions at
|
|
561
|
+
* construction time.
|
|
562
|
+
*/
|
|
563
|
+
detail::expression_formatter expression_{ colours_ };
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* @brief Controls whether to add an empty line between successful test
|
|
567
|
+
* cases.
|
|
568
|
+
*
|
|
569
|
+
* @details
|
|
570
|
+
* Used to nicely format the output.
|
|
571
|
+
*/
|
|
572
|
+
bool add_empty_line_{ true };
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* @brief Optional file path for redirecting test report output.
|
|
576
|
+
*
|
|
577
|
+
* @details
|
|
578
|
+
* When non-null, `write_buffer_to_file_()` writes accumulated output
|
|
579
|
+
* to this path in addition to (or instead of) standard output.
|
|
580
|
+
*/
|
|
581
|
+
const char* output_file_path_{ nullptr };
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @brief Optional output file for redirecting test report output.
|
|
585
|
+
*
|
|
586
|
+
* @details
|
|
587
|
+
* When non-null, all output is written to this file instead of
|
|
588
|
+
* standard output. The reporter does not own the file; the caller
|
|
589
|
+
* is responsible for its lifetime.
|
|
590
|
+
*/
|
|
591
|
+
FILE* output_file_{ nullptr };
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* @brief Owns the command-line arguments passed to the test runner.
|
|
595
|
+
*/
|
|
596
|
+
std::unique_ptr<std::vector<std::string_view>> argvs_{};
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// --------------------------------------------------------------------------
|
|
600
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
601
|
+
|
|
602
|
+
#if defined(__GNUC__)
|
|
603
|
+
#pragma GCC diagnostic pop
|
|
604
|
+
#endif
|
|
605
|
+
|
|
606
|
+
// ----------------------------------------------------------------------------
|
|
607
|
+
|
|
608
|
+
#endif // __cplusplus
|
|
609
|
+
|
|
610
|
+
// ============================================================================
|
|
611
|
+
// Templates & constexpr implementations.
|
|
612
|
+
|
|
613
|
+
#include "inlines/reporter-inlines.h"
|
|
614
|
+
|
|
615
|
+
// ----------------------------------------------------------------------------
|
|
616
|
+
|
|
617
|
+
#endif // MICRO_TEST_PLUS_TEST_REPORTER_H_
|
|
618
|
+
|
|
619
|
+
// ----------------------------------------------------------------------------
|