@micro-os-plus/micro-test-plus 4.0.0 → 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 +82 -0
- package/CMakeLists.txt +74 -24
- package/README.md +3 -2
- package/include/micro-os-plus/micro-test-plus/README.md +6 -0
- package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +29 -54
- package/include/micro-os-plus/micro-test-plus/detail.h +166 -705
- package/include/micro-os-plus/micro-test-plus/exceptions.h +5 -6
- package/include/micro-os-plus/micro-test-plus/expression-formatter.h +669 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +5 -0
- package/include/micro-os-plus/micro-test-plus/inlines/deferred-reporter-inlines.h +25 -30
- 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/expression-formatter-inlines.h +510 -0
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +17 -76
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +47 -25
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +7 -7
- 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 +4 -4
- package/include/micro-os-plus/micro-test-plus/inlines/reporter-inlines.h +53 -394
- package/include/micro-os-plus/micro-test-plus/inlines/runner-inlines.h +38 -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 +231 -45
- 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/literals.h +8 -14
- package/include/micro-os-plus/micro-test-plus/math.h +5 -0
- package/include/micro-os-plus/micro-test-plus/operators.h +19 -169
- package/include/micro-os-plus/micro-test-plus/reflection.h +5 -12
- package/include/micro-os-plus/micro-test-plus/reporter-human.h +17 -11
- package/include/micro-os-plus/micro-test-plus/reporter-tap.h +14 -8
- package/include/micro-os-plus/micro-test-plus/reporter.h +101 -424
- package/include/micro-os-plus/micro-test-plus/runner-totals.h +162 -176
- package/include/micro-os-plus/micro-test-plus/runner.h +61 -42
- package/include/micro-os-plus/micro-test-plus/test.h +450 -506
- package/include/micro-os-plus/micro-test-plus/timings.h +259 -262
- package/include/micro-os-plus/micro-test-plus/type-traits.h +19 -67
- package/include/micro-os-plus/micro-test-plus/utility.h +5 -4
- package/include/micro-os-plus/micro-test-plus.h +33 -24
- package/meson.build +1 -0
- package/package.json +11 -3
- package/src/deferred-reporter.cpp +21 -2
- package/src/expression-formatter.cpp +289 -0
- package/src/reflection.cpp +3 -1
- package/src/reporter-human.cpp +31 -37
- package/src/reporter-tap.cpp +25 -35
- package/src/reporter.cpp +36 -231
- package/src/runner-totals.cpp +6 -3
- package/src/runner.cpp +131 -25
- package/src/test.cpp +120 -113
- package/src/timings.cpp +6 -5
- package/src/utility.cpp +1 -1
|
@@ -45,12 +45,6 @@
|
|
|
45
45
|
|
|
46
46
|
// ----------------------------------------------------------------------------
|
|
47
47
|
|
|
48
|
-
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
49
|
-
#include <micro-os-plus/config.h>
|
|
50
|
-
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
51
|
-
|
|
52
|
-
// ----------------------------------------------------------------------------
|
|
53
|
-
|
|
54
48
|
#if defined(__GNUC__)
|
|
55
49
|
#pragma GCC diagnostic push
|
|
56
50
|
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
@@ -119,6 +113,11 @@ namespace micro_os_plus::micro_test_plus
|
|
|
119
113
|
|
|
120
114
|
#endif // __cplusplus
|
|
121
115
|
|
|
116
|
+
// ============================================================================
|
|
117
|
+
// Templates & constexpr implementations.
|
|
118
|
+
|
|
119
|
+
#include "inlines/exceptions-inline.h"
|
|
120
|
+
|
|
122
121
|
// ----------------------------------------------------------------------------
|
|
123
122
|
|
|
124
123
|
#endif // MICRO_TEST_PLUS_EXCEPTIONS_H_
|
|
@@ -0,0 +1,669 @@
|
|
|
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++ expression
|
|
21
|
+
* formatter.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the `expression_formatter` class, which encapsulates
|
|
25
|
+
* all value-formatting logic used by the µTest++ framework. The class owns
|
|
26
|
+
* a `std::string` buffer and exposes `operator<<` overloads for every
|
|
27
|
+
* standard arithmetic type, character type, string, pointer, container,
|
|
28
|
+
* and framework expression type derived from `detail::op`.
|
|
29
|
+
*
|
|
30
|
+
* By consolidating the formatting operators and their shared `append_number_`
|
|
31
|
+
* helper into a single class, the `reporter` is relieved of those
|
|
32
|
+
* responsibilities, and `detail::deferred_reporter` can pre-format expression
|
|
33
|
+
* text at construction time without requiring `reporter` or `subtest` to be
|
|
34
|
+
* complete at that point.
|
|
35
|
+
*
|
|
36
|
+
* Colour-code processing is intentionally excluded from this class; it
|
|
37
|
+
* remains the responsibility of the owning `reporter`.
|
|
38
|
+
*
|
|
39
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
40
|
+
* namespace, ensuring clear separation from user code and minimising the
|
|
41
|
+
* risk of naming conflicts.
|
|
42
|
+
*
|
|
43
|
+
* This file is intended solely for internal use within the framework and
|
|
44
|
+
* should not be included directly by user code.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
#ifndef MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
|
|
48
|
+
#define MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
|
|
49
|
+
|
|
50
|
+
// ----------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
#ifdef __cplusplus
|
|
53
|
+
|
|
54
|
+
// ----------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
#include <charconv>
|
|
57
|
+
#include <cstdio>
|
|
58
|
+
#include <string>
|
|
59
|
+
#include <string_view>
|
|
60
|
+
|
|
61
|
+
#include "type-traits.h"
|
|
62
|
+
#include "detail.h"
|
|
63
|
+
|
|
64
|
+
// ----------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
#if defined(__GNUC__)
|
|
67
|
+
#pragma GCC diagnostic push
|
|
68
|
+
#pragma GCC diagnostic ignored "-Wpadded"
|
|
69
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
70
|
+
#if defined(__clang__)
|
|
71
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
72
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
73
|
+
#endif
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
// ============================================================================
|
|
77
|
+
|
|
78
|
+
namespace micro_os_plus::micro_test_plus
|
|
79
|
+
{
|
|
80
|
+
// --------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
namespace detail
|
|
83
|
+
{
|
|
84
|
+
// ------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @struct colours
|
|
88
|
+
* @brief Colours used to highlight pass and fail results in test reports.
|
|
89
|
+
*
|
|
90
|
+
* @details
|
|
91
|
+
* The `colours` structure defines ANSI escape sequences for terminal
|
|
92
|
+
* output, enabling colour-coded highlighting of test outcomes. The `pass`
|
|
93
|
+
* member specifies the colour for successful results (typically green),
|
|
94
|
+
* while the `fail` member specifies the colour for failed results
|
|
95
|
+
* (typically red). The `none` member resets the colour to the terminal
|
|
96
|
+
* default.
|
|
97
|
+
*
|
|
98
|
+
* These colour codes enhance the clarity and professionalism of test
|
|
99
|
+
* reports by making it immediately apparent which tests have passed or
|
|
100
|
+
* failed, thereby improving the overall user experience when reviewing
|
|
101
|
+
* test results.
|
|
102
|
+
*
|
|
103
|
+
* @var colours::none
|
|
104
|
+
* ANSI escape sequence to reset the terminal colour to default.
|
|
105
|
+
* @var colours::pass
|
|
106
|
+
* ANSI escape sequence to set the terminal colour for passing results
|
|
107
|
+
* (green).
|
|
108
|
+
* @var colours::fail
|
|
109
|
+
* ANSI escape sequence to set the terminal colour for failing results
|
|
110
|
+
* (red).
|
|
111
|
+
*
|
|
112
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
113
|
+
*/
|
|
114
|
+
struct colours
|
|
115
|
+
{
|
|
116
|
+
const char* none = ""; /**< @brief Terminal colour reset sequence. */
|
|
117
|
+
const char* pass
|
|
118
|
+
= ""; /**< @brief Terminal colour sequence for passing tests. */
|
|
119
|
+
const char* fail
|
|
120
|
+
= ""; /**< @brief Terminal colour sequence for failing tests. */
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
inline constexpr colours colours_red_green = {
|
|
124
|
+
"\033[0m", /**< @brief Terminal colour reset sequence. */
|
|
125
|
+
"\033[32m", /**< @brief Green colour sequence for passing tests. */
|
|
126
|
+
"\033[31m" /**< @brief Red colour sequence for failing tests. */
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// ========================================================================
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @brief Formats values and expressions into an owned string buffer.
|
|
133
|
+
*
|
|
134
|
+
* @details
|
|
135
|
+
* `expression_formatter` owns a `std::string` buffer and provides
|
|
136
|
+
* `operator<<` overloads for all standard arithmetic types, character
|
|
137
|
+
* types, strings, pointers, containers, and framework expression types
|
|
138
|
+
* derived from `detail::op`.
|
|
139
|
+
*
|
|
140
|
+
* The numeric overloads append a type suffix (e.g., `42u`, `3l`, `1.0f`)
|
|
141
|
+
* matching the conventions used in the existing reporter output, so that
|
|
142
|
+
* the formatted text is identical whether produced by the reporter
|
|
143
|
+
* directly or pre-formatted by a deferred reporter.
|
|
144
|
+
*
|
|
145
|
+
* The class is non-copyable and non-movable to avoid accidental copying
|
|
146
|
+
* of the internal buffer.
|
|
147
|
+
*
|
|
148
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
149
|
+
*/
|
|
150
|
+
class expression_formatter
|
|
151
|
+
{
|
|
152
|
+
public:
|
|
153
|
+
/**
|
|
154
|
+
* @brief Constructor with colour configuration.
|
|
155
|
+
*
|
|
156
|
+
* @param colours Reference to a `colours` instance for output
|
|
157
|
+
* formatting.
|
|
158
|
+
*/
|
|
159
|
+
expression_formatter (colours& colours) noexcept;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @brief Deleted copy constructor to prevent copying.
|
|
163
|
+
*/
|
|
164
|
+
expression_formatter (const expression_formatter&) = delete;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @brief Deleted move constructor to prevent moving.
|
|
168
|
+
*/
|
|
169
|
+
expression_formatter (expression_formatter&&) = delete;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @brief Deleted copy assignment operator to prevent copying.
|
|
173
|
+
*/
|
|
174
|
+
expression_formatter&
|
|
175
|
+
operator= (const expression_formatter&)
|
|
176
|
+
= delete;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @brief Deleted move assignment operator to prevent moving.
|
|
180
|
+
*/
|
|
181
|
+
expression_formatter&
|
|
182
|
+
operator= (expression_formatter&&)
|
|
183
|
+
= delete;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @brief Default destructor.
|
|
187
|
+
*/
|
|
188
|
+
~expression_formatter () = default;
|
|
189
|
+
|
|
190
|
+
// ----------------------------------------------------------------------
|
|
191
|
+
// Primitive operator<< overloads.
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @brief Appends a string view to the buffer.
|
|
195
|
+
*
|
|
196
|
+
* @param sv The string view to append.
|
|
197
|
+
* @return Reference to this instance.
|
|
198
|
+
*/
|
|
199
|
+
expression_formatter&
|
|
200
|
+
operator<< (std::string_view sv);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @brief Appends a single character to the buffer.
|
|
204
|
+
*
|
|
205
|
+
* @param c The character to append.
|
|
206
|
+
* @return Reference to this instance.
|
|
207
|
+
*/
|
|
208
|
+
expression_formatter&
|
|
209
|
+
operator<< (char c);
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @brief Appends a null-terminated C string to the buffer.
|
|
213
|
+
*
|
|
214
|
+
* @param s The C string to append.
|
|
215
|
+
* @return Reference to this instance.
|
|
216
|
+
*/
|
|
217
|
+
expression_formatter&
|
|
218
|
+
operator<< (const char* s);
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @brief Appends the string representation of a boolean value.
|
|
222
|
+
*
|
|
223
|
+
* @param v The boolean value.
|
|
224
|
+
* @return Reference to this instance.
|
|
225
|
+
*/
|
|
226
|
+
expression_formatter&
|
|
227
|
+
operator<< (bool v);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @brief Appends the string `"nullptr"`.
|
|
231
|
+
*
|
|
232
|
+
* @return Reference to this instance.
|
|
233
|
+
*/
|
|
234
|
+
expression_formatter& operator<< (std::nullptr_t);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @brief Appends a signed char value with type suffix `"c"`.
|
|
238
|
+
*
|
|
239
|
+
* @param c The signed char value.
|
|
240
|
+
* @return Reference to this instance.
|
|
241
|
+
*/
|
|
242
|
+
expression_formatter&
|
|
243
|
+
operator<< (signed char c);
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @brief Appends an unsigned char value with type suffix `"uc"`.
|
|
247
|
+
*
|
|
248
|
+
* @param c The unsigned char value.
|
|
249
|
+
* @return Reference to this instance.
|
|
250
|
+
*/
|
|
251
|
+
expression_formatter&
|
|
252
|
+
operator<< (unsigned char c);
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @brief Appends a signed short value with type suffix `"s"`.
|
|
256
|
+
*
|
|
257
|
+
* @param v The signed short value.
|
|
258
|
+
* @return Reference to this instance.
|
|
259
|
+
*/
|
|
260
|
+
expression_formatter&
|
|
261
|
+
operator<< (signed short v);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @brief Appends an unsigned short value with type suffix `"us"`.
|
|
265
|
+
*
|
|
266
|
+
* @param v The unsigned short value.
|
|
267
|
+
* @return Reference to this instance.
|
|
268
|
+
*/
|
|
269
|
+
expression_formatter&
|
|
270
|
+
operator<< (unsigned short v);
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @brief Appends a signed int value (no suffix).
|
|
274
|
+
*
|
|
275
|
+
* @param v The signed int value.
|
|
276
|
+
* @return Reference to this instance.
|
|
277
|
+
*/
|
|
278
|
+
expression_formatter&
|
|
279
|
+
operator<< (signed int v);
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @brief Appends an unsigned int value with type suffix `"u"`.
|
|
283
|
+
*
|
|
284
|
+
* @param v The unsigned int value.
|
|
285
|
+
* @return Reference to this instance.
|
|
286
|
+
*/
|
|
287
|
+
expression_formatter&
|
|
288
|
+
operator<< (unsigned int v);
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @brief Appends a signed long value with type suffix `"l"`.
|
|
292
|
+
*
|
|
293
|
+
* @param v The signed long value.
|
|
294
|
+
* @return Reference to this instance.
|
|
295
|
+
*/
|
|
296
|
+
expression_formatter&
|
|
297
|
+
operator<< (signed long v);
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @brief Appends an unsigned long value with type suffix `"ul"`.
|
|
301
|
+
*
|
|
302
|
+
* @param v The unsigned long value.
|
|
303
|
+
* @return Reference to this instance.
|
|
304
|
+
*/
|
|
305
|
+
expression_formatter&
|
|
306
|
+
operator<< (unsigned long v);
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @brief Appends a signed long long value with type suffix `"ll"`.
|
|
310
|
+
*
|
|
311
|
+
* @param v The signed long long value.
|
|
312
|
+
* @return Reference to this instance.
|
|
313
|
+
*/
|
|
314
|
+
expression_formatter&
|
|
315
|
+
operator<< (signed long long v);
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* @brief Appends an unsigned long long value with type suffix `"ull"`.
|
|
319
|
+
*
|
|
320
|
+
* @param v The unsigned long long value.
|
|
321
|
+
* @return Reference to this instance.
|
|
322
|
+
*/
|
|
323
|
+
expression_formatter&
|
|
324
|
+
operator<< (unsigned long long v);
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @brief Appends a float value with type suffix `"f"`.
|
|
328
|
+
*
|
|
329
|
+
* @param v The float value.
|
|
330
|
+
* @return Reference to this instance.
|
|
331
|
+
*/
|
|
332
|
+
expression_formatter&
|
|
333
|
+
operator<< (float v);
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @brief Appends a double value (no suffix).
|
|
337
|
+
*
|
|
338
|
+
* @param v The double value.
|
|
339
|
+
* @return Reference to this instance.
|
|
340
|
+
*/
|
|
341
|
+
expression_formatter&
|
|
342
|
+
operator<< (double v);
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @brief Appends a long double value with type suffix `"l"`.
|
|
346
|
+
*
|
|
347
|
+
* @param v The long double value.
|
|
348
|
+
* @return Reference to this instance.
|
|
349
|
+
*/
|
|
350
|
+
expression_formatter&
|
|
351
|
+
operator<< (long double v);
|
|
352
|
+
|
|
353
|
+
// ----------------------------------------------------------------------
|
|
354
|
+
// Template operator<< overloads.
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* @brief Appends the hexadecimal address of a pointer.
|
|
358
|
+
*
|
|
359
|
+
* @details
|
|
360
|
+
* Null pointers are rendered as `"0x0"`. Non-null pointers are
|
|
361
|
+
* formatted with `snprintf` using the `%p` specifier.
|
|
362
|
+
*
|
|
363
|
+
* @tparam T The type pointed to.
|
|
364
|
+
* @param v The pointer value.
|
|
365
|
+
* @return Reference to this instance.
|
|
366
|
+
*/
|
|
367
|
+
template <typename T>
|
|
368
|
+
expression_formatter&
|
|
369
|
+
operator<< (T* v);
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @brief Appends the value of an op expression via `detail::get`.
|
|
373
|
+
*
|
|
374
|
+
* @tparam T An expression type satisfying `type_traits::is_op<T>`.
|
|
375
|
+
* @param t The expression object.
|
|
376
|
+
* @return Reference to this instance.
|
|
377
|
+
*/
|
|
378
|
+
template <class T>
|
|
379
|
+
requires type_traits::is_op<T>
|
|
380
|
+
expression_formatter&
|
|
381
|
+
operator<< (const T& t);
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* @brief Appends a genuine integral value without a type suffix.
|
|
385
|
+
*
|
|
386
|
+
* @tparam T The underlying integral type.
|
|
387
|
+
* @param v The strongly-typed integral value.
|
|
388
|
+
* @return Reference to this instance.
|
|
389
|
+
*/
|
|
390
|
+
template <class T>
|
|
391
|
+
expression_formatter&
|
|
392
|
+
operator<< (const type_traits::genuine_integral_value<T>& v);
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @brief Appends a container's elements enclosed in braces.
|
|
396
|
+
*
|
|
397
|
+
* @details
|
|
398
|
+
* Elements are formatted as `{ e1, e2, … }` by iterating the
|
|
399
|
+
* container and recursing through `operator<<` for each element.
|
|
400
|
+
*
|
|
401
|
+
* @tparam T A container type satisfying `type_traits::container_like`
|
|
402
|
+
* that does not have `npos`.
|
|
403
|
+
* @param t The container.
|
|
404
|
+
* @return Reference to this instance.
|
|
405
|
+
*/
|
|
406
|
+
template <class T>
|
|
407
|
+
requires (type_traits::container_like<T>
|
|
408
|
+
and not type_traits::has_npos<T>)
|
|
409
|
+
expression_formatter&
|
|
410
|
+
operator<< (const T& t);
|
|
411
|
+
|
|
412
|
+
// ----------------------------------------------------------------------
|
|
413
|
+
// Compound expression operator<< overloads (without colour).
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @brief Formats an equality comparison as `lhs == rhs`.
|
|
417
|
+
*
|
|
418
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
419
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
420
|
+
* @param op The equality expression.
|
|
421
|
+
* @return Reference to this instance.
|
|
422
|
+
*/
|
|
423
|
+
template <class Lhs_T, class Rhs_T>
|
|
424
|
+
expression_formatter&
|
|
425
|
+
operator<< (const detail::eq_<Lhs_T, Rhs_T>& op);
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @brief Formats an inequality comparison as `lhs != rhs`.
|
|
429
|
+
*
|
|
430
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
431
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
432
|
+
* @param op The inequality expression.
|
|
433
|
+
* @return Reference to this instance.
|
|
434
|
+
*/
|
|
435
|
+
template <class Lhs_T, class Rhs_T>
|
|
436
|
+
expression_formatter&
|
|
437
|
+
operator<< (const detail::ne_<Lhs_T, Rhs_T>& op);
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* @brief Formats a greater-than comparison as `lhs > rhs`.
|
|
441
|
+
*
|
|
442
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
443
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
444
|
+
* @param op The greater-than expression.
|
|
445
|
+
* @return Reference to this instance.
|
|
446
|
+
*/
|
|
447
|
+
template <class Lhs_T, class Rhs_T>
|
|
448
|
+
expression_formatter&
|
|
449
|
+
operator<< (const detail::gt_<Lhs_T, Rhs_T>& op);
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @brief Formats a greater-than-or-equal comparison as `lhs >= rhs`.
|
|
453
|
+
*
|
|
454
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
455
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
456
|
+
* @param op The greater-than-or-equal expression.
|
|
457
|
+
* @return Reference to this instance.
|
|
458
|
+
*/
|
|
459
|
+
template <class Lhs_T, class Rhs_T>
|
|
460
|
+
expression_formatter&
|
|
461
|
+
operator<< (const detail::ge_<Lhs_T, Rhs_T>& op);
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* @brief Formats a less-than comparison as `lhs < rhs`.
|
|
465
|
+
*
|
|
466
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
467
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
468
|
+
* @param op The less-than expression.
|
|
469
|
+
* @return Reference to this instance.
|
|
470
|
+
*/
|
|
471
|
+
template <class Lhs_T, class Rhs_T>
|
|
472
|
+
expression_formatter&
|
|
473
|
+
operator<< (const detail::lt_<Rhs_T, Lhs_T>& op);
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @brief Formats a less-than-or-equal comparison as `lhs <= rhs`.
|
|
477
|
+
*
|
|
478
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
479
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
480
|
+
* @param op The less-than-or-equal expression.
|
|
481
|
+
* @return Reference to this instance.
|
|
482
|
+
*/
|
|
483
|
+
template <class Lhs_T, class Rhs_T>
|
|
484
|
+
expression_formatter&
|
|
485
|
+
operator<< (const detail::le_<Rhs_T, Lhs_T>& op);
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* @brief Formats a logical AND as `(lhs and rhs)`.
|
|
489
|
+
*
|
|
490
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
491
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
492
|
+
* @param op The logical AND expression.
|
|
493
|
+
* @return Reference to this instance.
|
|
494
|
+
*/
|
|
495
|
+
template <class Lhs_T, class Rhs_T>
|
|
496
|
+
expression_formatter&
|
|
497
|
+
operator<< (const detail::and_<Lhs_T, Rhs_T>& op);
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* @brief Formats a logical OR as `(lhs or rhs)`.
|
|
501
|
+
*
|
|
502
|
+
* @tparam Lhs_T Left-hand operand type.
|
|
503
|
+
* @tparam Rhs_T Right-hand operand type.
|
|
504
|
+
* @param op The logical OR expression.
|
|
505
|
+
* @return Reference to this instance.
|
|
506
|
+
*/
|
|
507
|
+
template <class Lhs_T, class Rhs_T>
|
|
508
|
+
expression_formatter&
|
|
509
|
+
operator<< (const detail::or_<Lhs_T, Rhs_T>& op);
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* @brief Formats a logical NOT as `not operand`.
|
|
513
|
+
*
|
|
514
|
+
* @tparam T The operand type.
|
|
515
|
+
* @param op The logical NOT expression.
|
|
516
|
+
* @return Reference to this instance.
|
|
517
|
+
*/
|
|
518
|
+
template <class T>
|
|
519
|
+
expression_formatter&
|
|
520
|
+
operator<< (const detail::not_<T>& op);
|
|
521
|
+
|
|
522
|
+
#if defined(__cpp_exceptions)
|
|
523
|
+
/**
|
|
524
|
+
* @brief Formats a typed throws expression as
|
|
525
|
+
* `throws<TypeName>`.
|
|
526
|
+
*
|
|
527
|
+
* @tparam Callable_T The callable type.
|
|
528
|
+
* @tparam Exception_T The expected exception type.
|
|
529
|
+
* @param op The throws expression.
|
|
530
|
+
* @return Reference to this instance.
|
|
531
|
+
*/
|
|
532
|
+
template <class Callable_T, class Exception_T>
|
|
533
|
+
expression_formatter&
|
|
534
|
+
operator<< (const detail::throws_<Callable_T, Exception_T>& op);
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @brief Formats an untyped throws expression as `throws`.
|
|
538
|
+
*
|
|
539
|
+
* @tparam Callable_T The callable type.
|
|
540
|
+
* @param op The throws expression.
|
|
541
|
+
* @return Reference to this instance.
|
|
542
|
+
*/
|
|
543
|
+
template <class Callable_T>
|
|
544
|
+
expression_formatter&
|
|
545
|
+
operator<< (const detail::throws_<Callable_T, void>& op);
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* @brief Formats a nothrow expression as `nothrow`.
|
|
549
|
+
*
|
|
550
|
+
* @tparam Callable_T The callable type.
|
|
551
|
+
* @param op The nothrow expression.
|
|
552
|
+
* @return Reference to this instance.
|
|
553
|
+
*/
|
|
554
|
+
template <class Callable_T>
|
|
555
|
+
expression_formatter&
|
|
556
|
+
operator<< (const detail::nothrow_<Callable_T>& op);
|
|
557
|
+
#endif
|
|
558
|
+
|
|
559
|
+
// ----------------------------------------------------------------------
|
|
560
|
+
// Buffer accessors.
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @brief Returns a const reference to the internal buffer.
|
|
564
|
+
*
|
|
565
|
+
* @par Parameters
|
|
566
|
+
* None.
|
|
567
|
+
* @return Const reference to the accumulated string.
|
|
568
|
+
*/
|
|
569
|
+
[[nodiscard]] const std::string&
|
|
570
|
+
str () const noexcept;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @brief Returns a pointer to the null-terminated buffer contents.
|
|
574
|
+
*
|
|
575
|
+
* @par Parameters
|
|
576
|
+
* None.
|
|
577
|
+
* @return Pointer to the null-terminated character array.
|
|
578
|
+
*/
|
|
579
|
+
[[nodiscard]] const char*
|
|
580
|
+
c_str () const noexcept;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* @brief Clears the internal buffer.
|
|
584
|
+
*
|
|
585
|
+
* @par Parameters
|
|
586
|
+
* None.
|
|
587
|
+
* @par Returns
|
|
588
|
+
* Nothing.
|
|
589
|
+
*/
|
|
590
|
+
void
|
|
591
|
+
clear () noexcept;
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* @brief Returns whether the internal buffer is empty.
|
|
595
|
+
*
|
|
596
|
+
* @par Parameters
|
|
597
|
+
* None.
|
|
598
|
+
* @retval true The buffer contains no characters.
|
|
599
|
+
* @retval false The buffer contains at least one character.
|
|
600
|
+
*/
|
|
601
|
+
[[nodiscard]] bool
|
|
602
|
+
empty () const noexcept;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* @brief Appends a sequence of identical characters to the buffer.
|
|
606
|
+
*
|
|
607
|
+
* @param count The number of characters to append.
|
|
608
|
+
* @param ch The character to repeat.
|
|
609
|
+
* @par Returns
|
|
610
|
+
* Nothing.
|
|
611
|
+
*/
|
|
612
|
+
void
|
|
613
|
+
append (size_t count, char ch);
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* @brief Reserves storage in the internal buffer.
|
|
617
|
+
*
|
|
618
|
+
* @param capacity The minimum capacity to reserve.
|
|
619
|
+
* @par Returns
|
|
620
|
+
* Nothing.
|
|
621
|
+
*/
|
|
622
|
+
void
|
|
623
|
+
reserve (size_t capacity);
|
|
624
|
+
|
|
625
|
+
protected:
|
|
626
|
+
/**
|
|
627
|
+
* @brief Selects the appropriate colour code based on a condition.
|
|
628
|
+
*
|
|
629
|
+
* @param cond Boolean value indicating pass (true) or fail (false).
|
|
630
|
+
* @return The corresponding ANSI colour code as a string.
|
|
631
|
+
*/
|
|
632
|
+
[[nodiscard]] inline auto
|
|
633
|
+
colour_ (const bool cond) const;
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* @brief ANSI colour codes for output formatting.
|
|
637
|
+
*/
|
|
638
|
+
colours& colours_;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* @brief The internal output buffer.
|
|
642
|
+
*/
|
|
643
|
+
std::string buffer_{};
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// ------------------------------------------------------------------------
|
|
647
|
+
} // namespace detail
|
|
648
|
+
|
|
649
|
+
// --------------------------------------------------------------------------
|
|
650
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
651
|
+
|
|
652
|
+
#if defined(__GNUC__)
|
|
653
|
+
#pragma GCC diagnostic pop
|
|
654
|
+
#endif
|
|
655
|
+
|
|
656
|
+
// ----------------------------------------------------------------------------
|
|
657
|
+
|
|
658
|
+
#endif // __cplusplus
|
|
659
|
+
|
|
660
|
+
// ============================================================================
|
|
661
|
+
// Templates & constexpr implementations.
|
|
662
|
+
|
|
663
|
+
#include "inlines/expression-formatter-inlines.h"
|
|
664
|
+
|
|
665
|
+
// ----------------------------------------------------------------------------
|
|
666
|
+
|
|
667
|
+
#endif // MICRO_TEST_PLUS_EXPRESSION_FORMATTER_H_
|
|
668
|
+
|
|
669
|
+
// ----------------------------------------------------------------------------
|
|
@@ -329,6 +329,11 @@ namespace micro_os_plus::micro_test_plus
|
|
|
329
329
|
|
|
330
330
|
#endif // __cplusplus
|
|
331
331
|
|
|
332
|
+
// ============================================================================
|
|
333
|
+
// Templates & constexpr implementations.
|
|
334
|
+
|
|
335
|
+
#include "inlines/function-comparators-inlines.h"
|
|
336
|
+
|
|
332
337
|
// ----------------------------------------------------------------------------
|
|
333
338
|
|
|
334
339
|
#endif // MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
|