@micro-os-plus/micro-test-plus 3.2.2 → 3.3.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/.cmake-format.yaml +11 -0
- package/CHANGELOG.md +417 -2
- package/CMakeLists.txt +33 -30
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/{xcdl.json → config/xcdl-build.json} +6 -6
- package/include/micro-os-plus/micro-test-plus/detail.h +1908 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +333 -0
- package/include/micro-os-plus/micro-test-plus/inlines/details-inlines.h +172 -0
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +341 -0
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +604 -0
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +315 -0
- package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +313 -0
- package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +170 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-reporter-inlines.h +476 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +115 -0
- package/include/micro-os-plus/micro-test-plus/literals.h +912 -0
- package/include/micro-os-plus/micro-test-plus/math.h +217 -0
- package/include/micro-os-plus/micro-test-plus/operators.h +514 -0
- package/include/micro-os-plus/micro-test-plus/reflection.h +233 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter-basic.h +289 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter-tap.h +281 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter.h +846 -0
- package/include/micro-os-plus/micro-test-plus/test-runner.h +281 -0
- package/include/micro-os-plus/micro-test-plus/test-suite.h +492 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
- package/include/micro-os-plus/micro-test-plus.h +172 -552
- package/meson.build +7 -5
- package/package.json +29 -34
- package/src/micro-test-plus.cpp +134 -37
- package/src/test-reporter-basic.cpp +466 -0
- package/src/test-reporter-tap.cpp +530 -0
- package/src/test-reporter.cpp +207 -240
- package/src/test-runner.cpp +135 -23
- package/src/test-suite.cpp +182 -10
- package/include/micro-os-plus/detail.h +0 -765
- package/include/micro-os-plus/inlines.h +0 -209
- package/include/micro-os-plus/literals.h +0 -512
- package/include/micro-os-plus/math.h +0 -204
- package/include/micro-os-plus/reflection.h +0 -139
- package/include/micro-os-plus/test-reporter-inlines.h +0 -230
- package/include/micro-os-plus/test-reporter.h +0 -356
- package/include/micro-os-plus/test-runner.h +0 -132
- package/include/micro-os-plus/test-suite.h +0 -306
- package/include/micro-os-plus/type-traits.h +0 -389
|
@@ -0,0 +1,846 @@
|
|
|
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 <functional>
|
|
58
|
+
#include <string_view>
|
|
59
|
+
#include <string>
|
|
60
|
+
|
|
61
|
+
#include "type-traits.h"
|
|
62
|
+
#include "test-suite.h"
|
|
63
|
+
#include "detail.h"
|
|
64
|
+
|
|
65
|
+
// ----------------------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
#if defined(__GNUC__)
|
|
68
|
+
#pragma GCC diagnostic push
|
|
69
|
+
#pragma GCC diagnostic ignored "-Wpadded"
|
|
70
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
71
|
+
#if defined(__clang__)
|
|
72
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
73
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
74
|
+
#endif
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
namespace micro_os_plus::micro_test_plus
|
|
78
|
+
{
|
|
79
|
+
// --------------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @struct colors
|
|
83
|
+
* @brief Colours used to highlight pass and fail results in test reports.
|
|
84
|
+
*
|
|
85
|
+
* @details
|
|
86
|
+
* The `colors` structure defines ANSI escape sequences for terminal output,
|
|
87
|
+
* enabling colour-coded highlighting of test outcomes. The `pass` member
|
|
88
|
+
* specifies the colour for successful results (typically green), while the
|
|
89
|
+
* `fail` member specifies the colour for failed results (typically red). The
|
|
90
|
+
* `none` member resets the colour to the terminal default.
|
|
91
|
+
*
|
|
92
|
+
* These colour codes enhance the clarity and professionalism of test reports
|
|
93
|
+
* by making it immediately apparent which tests have passed or failed,
|
|
94
|
+
* thereby improving the overall user experience when reviewing test results.
|
|
95
|
+
*
|
|
96
|
+
* @var colors::none
|
|
97
|
+
* ANSI escape sequence to reset the terminal colour to default.
|
|
98
|
+
* @var colors::pass
|
|
99
|
+
* ANSI escape sequence to set the terminal colour for passing results
|
|
100
|
+
* (green).
|
|
101
|
+
* @var colors::fail
|
|
102
|
+
* ANSI escape sequence to set the terminal colour for failing results (red).
|
|
103
|
+
*
|
|
104
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
105
|
+
*/
|
|
106
|
+
struct colors
|
|
107
|
+
{
|
|
108
|
+
const char* none = ""; /**< @brief Default colour. */
|
|
109
|
+
const char* pass = ""; /**< @brief Green colour. */
|
|
110
|
+
const char* fail = ""; /**< @brief Red colour. */
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const colors colors_red_green = {
|
|
114
|
+
"\033[0m", /**< @brief Default colour. */
|
|
115
|
+
"\033[32m", /**< @brief Green colour. */
|
|
116
|
+
"\033[31m" /**< @brief Red colour. */
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @brief The verbosity levels for test reporting.
|
|
121
|
+
*
|
|
122
|
+
* @details
|
|
123
|
+
* The `verbosity` enumeration defines the available levels of detail for
|
|
124
|
+
* test output produced by the reporting system. These levels control the
|
|
125
|
+
* amount and type of information displayed during test execution, allowing
|
|
126
|
+
* users to tailor the output to their specific requirements.
|
|
127
|
+
*
|
|
128
|
+
* Selecting an appropriate verbosity level enhances the usability of test
|
|
129
|
+
* reports, whether for concise summaries or comprehensive diagnostics.
|
|
130
|
+
*
|
|
131
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
132
|
+
*/
|
|
133
|
+
enum class verbosity
|
|
134
|
+
{
|
|
135
|
+
silent = 0, /**< No output is produced; only the exit code is returned. */
|
|
136
|
+
quiet = 1, /**< Displays results for test suites only. */
|
|
137
|
+
normal = 2, /**< Displays results for test suites and failed test cases. */
|
|
138
|
+
verbose = 3 /**< Displays all results, including passed checks, for maximum
|
|
139
|
+
detail. */
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @brief Type alias for the verbosity enumeration used in test reporting.
|
|
144
|
+
*
|
|
145
|
+
* @details
|
|
146
|
+
* The `verbosity_t` type alias provides a convenient shorthand for referring
|
|
147
|
+
* to the `verbosity` enumeration, which defines the available levels of
|
|
148
|
+
* detail for test output within the reporting system.
|
|
149
|
+
*
|
|
150
|
+
* Using this alias improves code readability and consistency throughout the
|
|
151
|
+
* framework, especially when specifying or configuring verbosity levels for
|
|
152
|
+
* test reporters.
|
|
153
|
+
*/
|
|
154
|
+
typedef verbosity verbosity_t;
|
|
155
|
+
|
|
156
|
+
// Forward definition.
|
|
157
|
+
class test_reporter;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @brief Output stream manipulator for ending a line in test reports.
|
|
161
|
+
*
|
|
162
|
+
* @param stream Reference to the `test_reporter` instance.
|
|
163
|
+
* @return Reference to the same `test_reporter` instance, enabling chaining
|
|
164
|
+
* of output operations.
|
|
165
|
+
*/
|
|
166
|
+
test_reporter&
|
|
167
|
+
endl (test_reporter& stream);
|
|
168
|
+
|
|
169
|
+
// Requires events::assertion_* for and detailed operators.
|
|
170
|
+
|
|
171
|
+
class test_runner;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @brief Reporter to display test results, including operand values and
|
|
175
|
+
* types for failures.
|
|
176
|
+
*
|
|
177
|
+
* @details
|
|
178
|
+
* The `test_reporter` class is responsible for formatting and presenting
|
|
179
|
+
* test results within the µTest++ framework. It provides a comprehensive
|
|
180
|
+
* suite of output operators for a wide range of data types, containers, and
|
|
181
|
+
* comparator expressions, enabling detailed and informative reporting of
|
|
182
|
+
* test outcomes.
|
|
183
|
+
*
|
|
184
|
+
* For failed tests, the reporter prints the actual values of the operands
|
|
185
|
+
* along with their types, supporting precise diagnostics and efficient
|
|
186
|
+
* debugging. The class supports multiple verbosity levels and colour-coded
|
|
187
|
+
* output to distinguish between successful and failed tests, thereby
|
|
188
|
+
* enhancing the clarity and professionalism of test reports.
|
|
189
|
+
*
|
|
190
|
+
* The `test_reporter` also offers methods for reporting the commencement and
|
|
191
|
+
* completion of test cases and suites, as well as for handling pass and fail
|
|
192
|
+
* conditions. Additional features include output stream manipulators,
|
|
193
|
+
* support for exception-related expressions, and configurable formatting
|
|
194
|
+
* options.
|
|
195
|
+
*
|
|
196
|
+
* All members and methods are defined within the
|
|
197
|
+
* `micro_os_plus::micro_test_plus` namespace, ensuring clear separation from
|
|
198
|
+
* user code and minimising the risk of naming conflicts.
|
|
199
|
+
*
|
|
200
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
201
|
+
*/
|
|
202
|
+
class test_reporter
|
|
203
|
+
{
|
|
204
|
+
public:
|
|
205
|
+
/**
|
|
206
|
+
* @brief Default constructor for the test_reporter class.
|
|
207
|
+
*/
|
|
208
|
+
virtual ~test_reporter ();
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @brief Selects the appropriate colour code based on a condition.
|
|
212
|
+
*
|
|
213
|
+
* @param cond Boolean value indicating pass (true) or fail (false).
|
|
214
|
+
* @return The corresponding ANSI colour code as a string.
|
|
215
|
+
*
|
|
216
|
+
* @details
|
|
217
|
+
* Returns the ANSI colour code for pass or fail, depending on the boolean
|
|
218
|
+
* condition provided.
|
|
219
|
+
*/
|
|
220
|
+
[[nodiscard]] inline auto
|
|
221
|
+
color (const bool cond)
|
|
222
|
+
{
|
|
223
|
+
return cond ? colors_.pass : colors_.fail;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @brief Output operator for std::string_view.
|
|
228
|
+
*
|
|
229
|
+
* @param sv The string view to output.
|
|
230
|
+
* @return Reference to the current test_reporter instance.
|
|
231
|
+
*/
|
|
232
|
+
test_reporter&
|
|
233
|
+
operator<< (std::string_view sv);
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @brief Output operator for a single character.
|
|
237
|
+
*
|
|
238
|
+
* @param c The character to output.
|
|
239
|
+
* @return Reference to the current test_reporter instance.
|
|
240
|
+
*/
|
|
241
|
+
test_reporter&
|
|
242
|
+
operator<< (char c);
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @brief Output operator for a constant character string.
|
|
246
|
+
*
|
|
247
|
+
* @param s The string to output.
|
|
248
|
+
* @return Reference to the current test_reporter instance.
|
|
249
|
+
*/
|
|
250
|
+
test_reporter&
|
|
251
|
+
operator<< (const char* s);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @brief Output operator for a mutable character string.
|
|
255
|
+
*
|
|
256
|
+
* @param s The string to output.
|
|
257
|
+
* @return Reference to the current test_reporter instance.
|
|
258
|
+
*/
|
|
259
|
+
test_reporter&
|
|
260
|
+
operator<< (char* s);
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @brief Output operator for boolean values.
|
|
264
|
+
*
|
|
265
|
+
* @param v The boolean value to output.
|
|
266
|
+
* @return Reference to the current test_reporter instance.
|
|
267
|
+
*/
|
|
268
|
+
test_reporter&
|
|
269
|
+
operator<< (bool v);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @brief Output operator for nullptr.
|
|
273
|
+
* @return Reference to the current test_reporter instance.
|
|
274
|
+
*/
|
|
275
|
+
test_reporter& operator<< (std::nullptr_t);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @brief Output operator for signed char values.
|
|
279
|
+
*
|
|
280
|
+
* @param c The signed char value to output.
|
|
281
|
+
* @return Reference to the current test_reporter instance.
|
|
282
|
+
*/
|
|
283
|
+
test_reporter&
|
|
284
|
+
operator<< (signed char c);
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @brief Output operator for unsigned char values.
|
|
288
|
+
*
|
|
289
|
+
* @param c The unsigned char value to output.
|
|
290
|
+
* @return Reference to the current test_reporter instance.
|
|
291
|
+
*/
|
|
292
|
+
test_reporter&
|
|
293
|
+
operator<< (unsigned char c);
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* @brief Output operator for signed short values.
|
|
297
|
+
*
|
|
298
|
+
* @param v The signed short value to output.
|
|
299
|
+
* @return Reference to the current test_reporter instance.
|
|
300
|
+
*/
|
|
301
|
+
test_reporter&
|
|
302
|
+
operator<< (signed short v);
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @brief Output operator for unsigned short values.
|
|
306
|
+
*
|
|
307
|
+
* @param v The unsigned short value to output.
|
|
308
|
+
* @return Reference to the current test_reporter instance.
|
|
309
|
+
*/
|
|
310
|
+
test_reporter&
|
|
311
|
+
operator<< (unsigned short v);
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* @brief Output operator for signed int values.
|
|
315
|
+
*
|
|
316
|
+
* @param v The signed int value to output.
|
|
317
|
+
* @return Reference to the current test_reporter instance.
|
|
318
|
+
*/
|
|
319
|
+
test_reporter&
|
|
320
|
+
operator<< (signed int v);
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @brief Output operator for unsigned int values.
|
|
324
|
+
*
|
|
325
|
+
* @param v The unsigned int value to output.
|
|
326
|
+
* @return Reference to the current test_reporter instance.
|
|
327
|
+
*/
|
|
328
|
+
test_reporter&
|
|
329
|
+
operator<< (unsigned int v);
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @brief Output operator for signed long values.
|
|
333
|
+
*
|
|
334
|
+
* @param v The signed long value to output.
|
|
335
|
+
* @return Reference to the current test_reporter instance.
|
|
336
|
+
*/
|
|
337
|
+
test_reporter&
|
|
338
|
+
operator<< (signed long v);
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @brief Output operator for unsigned long values.
|
|
342
|
+
*
|
|
343
|
+
* @param v The unsigned long value to output.
|
|
344
|
+
* @return Reference to the current test_reporter instance.
|
|
345
|
+
*/
|
|
346
|
+
test_reporter&
|
|
347
|
+
operator<< (unsigned long v);
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* @brief Output operator for signed long long values.
|
|
351
|
+
*
|
|
352
|
+
* @param v The signed long long value to output.
|
|
353
|
+
* @return Reference to the current test_reporter instance.
|
|
354
|
+
*/
|
|
355
|
+
test_reporter&
|
|
356
|
+
operator<< (signed long long v);
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @brief Output operator for unsigned long long values.
|
|
360
|
+
*
|
|
361
|
+
* @param v The unsigned long long value to output.
|
|
362
|
+
* @return Reference to the current test_reporter instance.
|
|
363
|
+
*/
|
|
364
|
+
test_reporter&
|
|
365
|
+
operator<< (unsigned long long v);
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @brief Output operator for float values.
|
|
369
|
+
*
|
|
370
|
+
* @param v The float value to output.
|
|
371
|
+
* @return Reference to the current test_reporter instance.
|
|
372
|
+
*/
|
|
373
|
+
test_reporter&
|
|
374
|
+
operator<< (float v);
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @brief Output operator for double values.
|
|
378
|
+
*
|
|
379
|
+
* @param v The double value to output.
|
|
380
|
+
* @return Reference to the current test_reporter instance.
|
|
381
|
+
*/
|
|
382
|
+
test_reporter&
|
|
383
|
+
operator<< (double v);
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @brief Output operator for long double values.
|
|
387
|
+
*
|
|
388
|
+
* @param v The long double value to output.
|
|
389
|
+
* @return Reference to the current test_reporter instance.
|
|
390
|
+
*/
|
|
391
|
+
test_reporter&
|
|
392
|
+
operator<< (long double v);
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @brief Output operator to display any pointer.
|
|
396
|
+
*
|
|
397
|
+
* @tparam T The type of the pointer.
|
|
398
|
+
*
|
|
399
|
+
* @param v The pointer value to output.
|
|
400
|
+
* @return Reference to the current test_reporter instance.
|
|
401
|
+
*/
|
|
402
|
+
template <typename T>
|
|
403
|
+
test_reporter&
|
|
404
|
+
operator<< (T* v);
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* @brief Output operator to display the endl.
|
|
408
|
+
*
|
|
409
|
+
* @param func Function pointer to the stream manipulator.
|
|
410
|
+
* @return Reference to the current test_reporter instance.
|
|
411
|
+
*/
|
|
412
|
+
test_reporter&
|
|
413
|
+
operator<< (test_reporter& (*func) (test_reporter&));
|
|
414
|
+
|
|
415
|
+
// ------------------------------------------------------------------------
|
|
416
|
+
// Specific operators.
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* @brief Output operator for types with a getter.
|
|
420
|
+
*
|
|
421
|
+
* @tparam T The type with a getter method.
|
|
422
|
+
*
|
|
423
|
+
* @param t The object to output.
|
|
424
|
+
* @return Reference to the current test_reporter instance.
|
|
425
|
+
*/
|
|
426
|
+
template <class T>
|
|
427
|
+
test_reporter&
|
|
428
|
+
operator<< (const T& t);
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @brief Output operator to display genuine integers, without the type
|
|
432
|
+
* suffix.
|
|
433
|
+
*
|
|
434
|
+
* @tparam T The underlying integral type.
|
|
435
|
+
*
|
|
436
|
+
* @param v The strongly-typed integral value to output.
|
|
437
|
+
* @return Reference to the current test_reporter instance.
|
|
438
|
+
*/
|
|
439
|
+
template <class T>
|
|
440
|
+
test_reporter&
|
|
441
|
+
operator<< (const type_traits::genuine_integral_value<T>& v);
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @brief Output operator to display containers. Iterates all members.
|
|
445
|
+
*
|
|
446
|
+
* @tparam T The container type.
|
|
447
|
+
*
|
|
448
|
+
* @param t The container to output.
|
|
449
|
+
* @return Reference to the current test_reporter instance.
|
|
450
|
+
*/
|
|
451
|
+
template <class T,
|
|
452
|
+
type_traits::requires_t<type_traits::is_container_v<T>
|
|
453
|
+
and not type_traits::has_npos_v<T>>
|
|
454
|
+
= 0>
|
|
455
|
+
test_reporter&
|
|
456
|
+
operator<< (T&& t);
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* @brief Output operator to display eq() expressions.
|
|
460
|
+
*
|
|
461
|
+
* @tparam Lhs_T The left-hand side type.
|
|
462
|
+
* @tparam Rhs_T The right-hand side type.
|
|
463
|
+
*
|
|
464
|
+
* @param op The equality comparator expression.
|
|
465
|
+
* @return Reference to the current test_reporter instance.
|
|
466
|
+
*/
|
|
467
|
+
template <class Lhs_T, class Rhs_T>
|
|
468
|
+
test_reporter&
|
|
469
|
+
operator<< (const detail::eq_<Lhs_T, Rhs_T>& op);
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* @brief Output operator to display ne() expressions.
|
|
473
|
+
*
|
|
474
|
+
* @tparam Lhs_T The left-hand side type.
|
|
475
|
+
* @tparam Rhs_T The right-hand side type.
|
|
476
|
+
*
|
|
477
|
+
* @param op The inequality comparator expression.
|
|
478
|
+
* @return Reference to the current test_reporter instance.
|
|
479
|
+
*/
|
|
480
|
+
template <class Lhs_T, class Rhs_T>
|
|
481
|
+
test_reporter&
|
|
482
|
+
operator<< (const detail::ne_<Lhs_T, Rhs_T>& op);
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @brief Output operator to display gt() expressions.
|
|
486
|
+
*
|
|
487
|
+
* @tparam Lhs_T The left-hand side type.
|
|
488
|
+
* @tparam Rhs_T The right-hand side type.
|
|
489
|
+
*
|
|
490
|
+
* @param op The greater-than comparator expression.
|
|
491
|
+
* @return Reference to the current test_reporter instance.
|
|
492
|
+
*/
|
|
493
|
+
template <class Lhs_T, class Rhs_T>
|
|
494
|
+
test_reporter&
|
|
495
|
+
operator<< (const detail::gt_<Lhs_T, Rhs_T>& op);
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @brief Output operator to display ge() expressions.
|
|
499
|
+
*
|
|
500
|
+
* @tparam Lhs_T The left-hand side type.
|
|
501
|
+
* @tparam Rhs_T The right-hand side type.
|
|
502
|
+
*
|
|
503
|
+
* @param op The greater-than-or-equal-to comparator expression.
|
|
504
|
+
* @return Reference to the current test_reporter instance.
|
|
505
|
+
*/
|
|
506
|
+
template <class Lhs_T, class Rhs_T>
|
|
507
|
+
test_reporter&
|
|
508
|
+
operator<< (const detail::ge_<Lhs_T, Rhs_T>& op);
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @brief Output operator to display lt() expressions.
|
|
512
|
+
*
|
|
513
|
+
* @tparam Lhs_T The left-hand side type.
|
|
514
|
+
* @tparam Rhs_T The right-hand side type.
|
|
515
|
+
*
|
|
516
|
+
* @param op The less-than comparator expression.
|
|
517
|
+
* @return Reference to the current test_reporter instance.
|
|
518
|
+
*/
|
|
519
|
+
template <class Lhs_T, class Rhs_T>
|
|
520
|
+
test_reporter&
|
|
521
|
+
operator<< (const detail::lt_<Rhs_T, Lhs_T>& op);
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @brief Output operator to display le() expressions.
|
|
525
|
+
*
|
|
526
|
+
* @tparam Lhs_T The left-hand side type.
|
|
527
|
+
* @tparam Rhs_T The right-hand side type.
|
|
528
|
+
*
|
|
529
|
+
* @param op The less-than-or-equal-to comparator expression.
|
|
530
|
+
* @return Reference to the current test_reporter instance.
|
|
531
|
+
*/
|
|
532
|
+
template <class Lhs_T, class Rhs_T>
|
|
533
|
+
test_reporter&
|
|
534
|
+
operator<< (const detail::le_<Rhs_T, Lhs_T>& op);
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @brief Output operator to display and() expressions.
|
|
538
|
+
*
|
|
539
|
+
* @tparam Lhs_T The left-hand side type.
|
|
540
|
+
* @tparam Rhs_T The right-hand side type.
|
|
541
|
+
*
|
|
542
|
+
* @param op The logical conjunction (AND) expression.
|
|
543
|
+
* @return Reference to the current test_reporter instance.
|
|
544
|
+
*/
|
|
545
|
+
template <class Lhs_T, class Rhs_T>
|
|
546
|
+
test_reporter&
|
|
547
|
+
operator<< (const detail::and_<Lhs_T, Rhs_T>& op);
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* @brief Output operator to display or() expressions.
|
|
551
|
+
*
|
|
552
|
+
* @tparam Lhs_T The left-hand side type.
|
|
553
|
+
* @tparam Rhs_T The right-hand side type.
|
|
554
|
+
*
|
|
555
|
+
* @param op The logical disjunction (OR) expression.
|
|
556
|
+
* @return Reference to the current test_reporter instance.
|
|
557
|
+
*/
|
|
558
|
+
template <class Lhs_T, class Rhs_T>
|
|
559
|
+
test_reporter&
|
|
560
|
+
operator<< (const detail::or_<Lhs_T, Rhs_T>& op);
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @brief Output operator to display not() expressions.
|
|
564
|
+
*
|
|
565
|
+
* @tparam T The operand type.
|
|
566
|
+
*
|
|
567
|
+
* @param op The logical negation expression.
|
|
568
|
+
* @return Reference to the current test_reporter instance.
|
|
569
|
+
*/
|
|
570
|
+
template <class T>
|
|
571
|
+
test_reporter&
|
|
572
|
+
operator<< (const detail::not_<T>& op);
|
|
573
|
+
|
|
574
|
+
#if defined(__cpp_exceptions)
|
|
575
|
+
/**
|
|
576
|
+
* @brief Output operator to display throws expressions for a specific
|
|
577
|
+
* exception type.
|
|
578
|
+
*
|
|
579
|
+
* @tparam Expr_T The expression type.
|
|
580
|
+
* @tparam Exception_T The exception type.
|
|
581
|
+
*
|
|
582
|
+
* @param op The throws comparator expression.
|
|
583
|
+
* @return Reference to the current test_reporter instance.
|
|
584
|
+
*/
|
|
585
|
+
template <class Expr_T, class Exception_T>
|
|
586
|
+
test_reporter&
|
|
587
|
+
operator<< (const detail::throws_<Expr_T, Exception_T>& op);
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* @brief Output operator to display throws expressions for any exception.
|
|
591
|
+
*
|
|
592
|
+
* @tparam Expr_T The expression type.
|
|
593
|
+
*
|
|
594
|
+
* @param op The throws comparator expression.
|
|
595
|
+
* @return Reference to the current test_reporter instance.
|
|
596
|
+
*/
|
|
597
|
+
template <class Expr_T>
|
|
598
|
+
test_reporter&
|
|
599
|
+
operator<< (const detail::throws_<Expr_T, void>& op);
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* @brief Output operator to display nothrow expressions.
|
|
603
|
+
*
|
|
604
|
+
* @tparam Expr_T The expression type.
|
|
605
|
+
*
|
|
606
|
+
* @param op The nothrow comparator expression.
|
|
607
|
+
* @return Reference to the current test_reporter instance.
|
|
608
|
+
*/
|
|
609
|
+
template <class Expr_T>
|
|
610
|
+
test_reporter&
|
|
611
|
+
operator<< (const detail::nothrow_<Expr_T>& op);
|
|
612
|
+
#endif
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* @brief Inserts a line ending into the output buffer.
|
|
616
|
+
*
|
|
617
|
+
* @par Parameters
|
|
618
|
+
* None.
|
|
619
|
+
* @par Returns
|
|
620
|
+
* Nothing.
|
|
621
|
+
*/
|
|
622
|
+
virtual void
|
|
623
|
+
endline (void)
|
|
624
|
+
= 0;
|
|
625
|
+
|
|
626
|
+
// ------------------------------------------------------------------------
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* @brief Report a passed condition.
|
|
630
|
+
*
|
|
631
|
+
* @tparam Expr_T The expression type.
|
|
632
|
+
*
|
|
633
|
+
* @param expr The evaluated expression.
|
|
634
|
+
* @param message The message to display.
|
|
635
|
+
* @par Returns
|
|
636
|
+
* Nothing.
|
|
637
|
+
*/
|
|
638
|
+
template <class Expr_T>
|
|
639
|
+
void
|
|
640
|
+
pass (Expr_T& expr, std::string& message);
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* @brief Report a failed condition.
|
|
644
|
+
*
|
|
645
|
+
* @tparam Expr_T The expression type.
|
|
646
|
+
*
|
|
647
|
+
* @param expr The evaluated expression.
|
|
648
|
+
* @param abort Whether to abort execution after failure.
|
|
649
|
+
* @param message The message to display.
|
|
650
|
+
* @param location The source location of the failure.
|
|
651
|
+
* @par Returns
|
|
652
|
+
* Nothing.
|
|
653
|
+
*/
|
|
654
|
+
template <class Expr_T>
|
|
655
|
+
void
|
|
656
|
+
fail (Expr_T& expr, bool abort, std::string& message,
|
|
657
|
+
const reflection::source_location& location);
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* @brief Mark the beginning of a test case.
|
|
661
|
+
*
|
|
662
|
+
* @param name The name of the test case.
|
|
663
|
+
* @par Returns
|
|
664
|
+
* Nothing.
|
|
665
|
+
*/
|
|
666
|
+
virtual void
|
|
667
|
+
begin_test_case (const char* name)
|
|
668
|
+
= 0;
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* @brief Mark the end of a test case.
|
|
672
|
+
*
|
|
673
|
+
* @param name The name of the test case.
|
|
674
|
+
* @par Returns
|
|
675
|
+
* Nothing.
|
|
676
|
+
*/
|
|
677
|
+
virtual void
|
|
678
|
+
end_test_case (const char* name)
|
|
679
|
+
= 0;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* @brief Mark the beginning of a test suite.
|
|
683
|
+
*
|
|
684
|
+
* @param name The name of the test suite.
|
|
685
|
+
* @par Returns
|
|
686
|
+
* Nothing.
|
|
687
|
+
*/
|
|
688
|
+
virtual void
|
|
689
|
+
begin_test_suite (const char* name)
|
|
690
|
+
= 0;
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* @brief Mark the end of a test suite.
|
|
694
|
+
*
|
|
695
|
+
* @param suite Reference to the test suite base.
|
|
696
|
+
* @par Returns
|
|
697
|
+
* Nothing.
|
|
698
|
+
*/
|
|
699
|
+
virtual void
|
|
700
|
+
end_test_suite (test_suite_base& suite)
|
|
701
|
+
= 0;
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* @brief Mark the beginning of a test.
|
|
705
|
+
*
|
|
706
|
+
* @param test_suites_count The number of test suites.
|
|
707
|
+
* @par Returns
|
|
708
|
+
* Nothing.
|
|
709
|
+
*/
|
|
710
|
+
virtual void
|
|
711
|
+
begin_test (size_t test_suites_count)
|
|
712
|
+
= 0;
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* @brief Mark the end of a test.
|
|
716
|
+
*
|
|
717
|
+
* @param runner Reference to the test runner.
|
|
718
|
+
* @par Returns
|
|
719
|
+
* Nothing.
|
|
720
|
+
*/
|
|
721
|
+
virtual void
|
|
722
|
+
end_test (test_runner& runner)
|
|
723
|
+
= 0;
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* @brief Flush the current buffered content.
|
|
727
|
+
*
|
|
728
|
+
* @par Parameters
|
|
729
|
+
* None.
|
|
730
|
+
* @par Returns
|
|
731
|
+
* Nothing.
|
|
732
|
+
*/
|
|
733
|
+
virtual void
|
|
734
|
+
flush (void)
|
|
735
|
+
= 0;
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* @brief Output the current buffered content.
|
|
739
|
+
*
|
|
740
|
+
* @par Parameters
|
|
741
|
+
* None.
|
|
742
|
+
* @par Returns
|
|
743
|
+
* Nothing.
|
|
744
|
+
*/
|
|
745
|
+
virtual void
|
|
746
|
+
output (void)
|
|
747
|
+
= 0;
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* @brief Controls whether to add an empty line between successful test
|
|
751
|
+
* cases.
|
|
752
|
+
*
|
|
753
|
+
* @details
|
|
754
|
+
* Used to nicely format the output.
|
|
755
|
+
*/
|
|
756
|
+
bool add_empty_line{ true };
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* @brief The verbosity level for test reporting.
|
|
760
|
+
*/
|
|
761
|
+
verbosity_t verbosity{};
|
|
762
|
+
|
|
763
|
+
protected:
|
|
764
|
+
/**
|
|
765
|
+
* @brief Outputs the prefix for a passing condition.
|
|
766
|
+
*
|
|
767
|
+
* @param message The message to display.
|
|
768
|
+
* @par Returns
|
|
769
|
+
* Nothing.
|
|
770
|
+
*/
|
|
771
|
+
virtual void
|
|
772
|
+
output_pass_prefix_ (std::string& message)
|
|
773
|
+
= 0;
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* @brief Outputs the suffix for a passing condition.
|
|
777
|
+
*
|
|
778
|
+
* @par Parameters
|
|
779
|
+
* None.
|
|
780
|
+
* @par Returns
|
|
781
|
+
* Nothing.
|
|
782
|
+
*/
|
|
783
|
+
virtual void
|
|
784
|
+
output_pass_suffix_ (void)
|
|
785
|
+
= 0;
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* @brief Outputs the prefix for a failing condition.
|
|
789
|
+
*
|
|
790
|
+
* @param message The message to display.
|
|
791
|
+
* @param hasExpression Whether the failure is associated with an
|
|
792
|
+
* expression.
|
|
793
|
+
* @param location The source location of the failure.
|
|
794
|
+
* @par Returns
|
|
795
|
+
* Nothing.
|
|
796
|
+
*/
|
|
797
|
+
virtual void
|
|
798
|
+
output_fail_prefix_ (std::string& message, const bool hasExpression,
|
|
799
|
+
const reflection::source_location& location)
|
|
800
|
+
= 0;
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* @brief Outputs the suffix for a failing condition.
|
|
804
|
+
*
|
|
805
|
+
* @param location The source location of the failure.
|
|
806
|
+
* @param abort Whether to abort execution after failure.
|
|
807
|
+
* @par Returns
|
|
808
|
+
* Nothing.
|
|
809
|
+
*/
|
|
810
|
+
virtual void
|
|
811
|
+
output_fail_suffix_ (const reflection::source_location& location,
|
|
812
|
+
bool abort)
|
|
813
|
+
= 0;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* @brief ANSI colour codes for output formatting.
|
|
817
|
+
*/
|
|
818
|
+
colors colors_{};
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* @brief Internal output buffer for accumulating report content.
|
|
822
|
+
*/
|
|
823
|
+
std::string out_{};
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* @brief Indicates whether the reporter is currently within a test case.
|
|
827
|
+
*/
|
|
828
|
+
bool is_in_test_case_ = false;
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// --------------------------------------------------------------------------
|
|
832
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
833
|
+
|
|
834
|
+
#if defined(__GNUC__)
|
|
835
|
+
#pragma GCC diagnostic pop
|
|
836
|
+
#endif
|
|
837
|
+
|
|
838
|
+
// ----------------------------------------------------------------------------
|
|
839
|
+
|
|
840
|
+
#endif // __cplusplus
|
|
841
|
+
|
|
842
|
+
// ----------------------------------------------------------------------------
|
|
843
|
+
|
|
844
|
+
#endif // MICRO_TEST_PLUS_TEST_REPORTER_H_
|
|
845
|
+
|
|
846
|
+
// ----------------------------------------------------------------------------
|