@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
|
@@ -17,37 +17,32 @@
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @file
|
|
20
|
-
* @brief C++ header file with inline implementations for the µTest++
|
|
21
|
-
*
|
|
20
|
+
* @brief C++ header file with inline implementations for the µTest++
|
|
21
|
+
* expression formatter.
|
|
22
22
|
*
|
|
23
23
|
* @details
|
|
24
|
-
* This header provides the inline
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
24
|
+
* This header provides the inline and template method implementations for
|
|
25
|
+
* `expression_formatter`. The buffer accessors (`str()`, `c_str()`,
|
|
26
|
+
* `clear()`, `empty()`, `append()`, `reserve()`) are defined as inline
|
|
27
|
+
* functions for zero-overhead access. The template operators —
|
|
28
|
+
* `operator<<(T*)`, `operator<<(is_op<T>)`,
|
|
29
|
+
* `operator<<(genuine_integral_value<T>)`, and `operator<<(container)` —
|
|
30
|
+
* are instantiated per concrete type at each call site.
|
|
29
31
|
*
|
|
30
|
-
* The
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* and extensibility, enabling professional and readable test reports suitable
|
|
35
|
-
* for embedded and general C++ development.
|
|
32
|
+
* The `append_number_()` helper is also a template, selecting between a
|
|
33
|
+
* `std::to_chars` path for standard numeric types and an `snprintf` fallback
|
|
34
|
+
* for `long double` on platforms where `std::to_chars` lacks support for
|
|
35
|
+
* 80-bit extended precision.
|
|
36
36
|
*
|
|
37
|
-
* All definitions reside within the `micro_os_plus::micro_test_plus
|
|
38
|
-
* namespace
|
|
39
|
-
* of naming conflicts.
|
|
40
|
-
*
|
|
41
|
-
* The header files are organised within the
|
|
42
|
-
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
43
|
-
* modular codebase.
|
|
37
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
38
|
+
* namespace.
|
|
44
39
|
*
|
|
45
40
|
* This file is intended solely for internal use within the framework and
|
|
46
41
|
* should not be included directly by user code.
|
|
47
42
|
*/
|
|
48
43
|
|
|
49
|
-
#ifndef
|
|
50
|
-
#define
|
|
44
|
+
#ifndef MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
|
|
45
|
+
#define MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
|
|
51
46
|
|
|
52
47
|
// ----------------------------------------------------------------------------
|
|
53
48
|
|
|
@@ -55,8 +50,9 @@
|
|
|
55
50
|
|
|
56
51
|
// ----------------------------------------------------------------------------
|
|
57
52
|
|
|
58
|
-
#include <
|
|
59
|
-
|
|
53
|
+
#include <cstdio>
|
|
54
|
+
|
|
55
|
+
#include "micro-os-plus/micro-test-plus/reflection.h"
|
|
60
56
|
|
|
61
57
|
// ----------------------------------------------------------------------------
|
|
62
58
|
|
|
@@ -69,94 +65,184 @@
|
|
|
69
65
|
#endif
|
|
70
66
|
#endif
|
|
71
67
|
|
|
72
|
-
|
|
68
|
+
// ============================================================================
|
|
69
|
+
|
|
70
|
+
namespace micro_os_plus::micro_test_plus::detail
|
|
73
71
|
{
|
|
74
72
|
// --------------------------------------------------------------------------
|
|
75
73
|
|
|
76
74
|
/**
|
|
77
75
|
* @details
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
* Initializes the `colours_` reference with the provided `colours` instance.
|
|
77
|
+
* The internal buffer is default-initialized to an empty string.
|
|
78
|
+
*/
|
|
79
|
+
inline expression_formatter::expression_formatter (colours& colours) noexcept
|
|
80
|
+
: colours_ (colours)
|
|
81
|
+
{
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @details
|
|
88
|
+
* Returns the ANSI colour code for pass or fail, depending on the boolean
|
|
89
|
+
* condition provided.
|
|
90
|
+
*/
|
|
91
|
+
inline auto
|
|
92
|
+
expression_formatter::colour_ (const bool cond) const
|
|
93
|
+
{
|
|
94
|
+
return cond ? colours_.pass : colours_.fail;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// --------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @details
|
|
101
|
+
* Returns a const reference to the internal `buffer_` string.
|
|
102
|
+
*/
|
|
103
|
+
inline const std::string&
|
|
104
|
+
expression_formatter::str () const noexcept
|
|
105
|
+
{
|
|
106
|
+
return buffer_;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @details
|
|
111
|
+
* Returns `buffer_.c_str()`, providing a pointer to the
|
|
112
|
+
* null-terminated contents of the internal buffer.
|
|
113
|
+
*/
|
|
114
|
+
inline const char*
|
|
115
|
+
expression_formatter::c_str () const noexcept
|
|
116
|
+
{
|
|
117
|
+
return buffer_.c_str ();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @details
|
|
122
|
+
* Calls `buffer_.clear()`, resetting the buffer length to zero
|
|
123
|
+
* without releasing the allocated storage.
|
|
124
|
+
*/
|
|
125
|
+
inline void
|
|
126
|
+
expression_formatter::clear () noexcept
|
|
127
|
+
{
|
|
128
|
+
buffer_.clear ();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @details
|
|
133
|
+
* Returns `buffer_.empty()`, indicating whether the accumulated
|
|
134
|
+
* string has zero length.
|
|
135
|
+
*/
|
|
136
|
+
inline bool
|
|
137
|
+
expression_formatter::empty () const noexcept
|
|
138
|
+
{
|
|
139
|
+
return buffer_.empty ();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @details
|
|
144
|
+
* Appends @p count repetitions of @p ch to the internal buffer by
|
|
145
|
+
* delegating to `buffer_.append(count, ch)`.
|
|
146
|
+
*/
|
|
147
|
+
inline void
|
|
148
|
+
expression_formatter::append (size_t count, char ch)
|
|
149
|
+
{
|
|
150
|
+
buffer_.append (count, ch);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @details
|
|
155
|
+
* Calls `buffer_.reserve(capacity)` to pre-allocate storage,
|
|
156
|
+
* reducing subsequent dynamic allocations.
|
|
157
|
+
*/
|
|
158
|
+
inline void
|
|
159
|
+
expression_formatter::reserve (size_t capacity)
|
|
160
|
+
{
|
|
161
|
+
buffer_.reserve (capacity);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// --------------------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
#if defined(__GNUC__)
|
|
167
|
+
#pragma GCC diagnostic push
|
|
168
|
+
#if defined(__clang__)
|
|
169
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
170
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
171
|
+
#endif
|
|
172
|
+
#endif
|
|
173
|
+
|
|
174
|
+
// --------------------------------------------------------------------------
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @details
|
|
178
|
+
* Null pointers are rendered as `"0x0"` to avoid platform-specific
|
|
179
|
+
* representations such as `"(nil)"` on Linux/glibc. Non-null pointers
|
|
180
|
+
* are formatted as a hexadecimal address using `snprintf` with the
|
|
181
|
+
* `%p` specifier.
|
|
89
182
|
*/
|
|
90
183
|
template <typename T>
|
|
91
|
-
|
|
92
|
-
|
|
184
|
+
expression_formatter&
|
|
185
|
+
expression_formatter::operator<< (T* v)
|
|
93
186
|
{
|
|
187
|
+
if (v == nullptr)
|
|
188
|
+
{
|
|
189
|
+
buffer_.append ("0x0");
|
|
190
|
+
return *this;
|
|
191
|
+
}
|
|
192
|
+
#if defined(__GNUC__)
|
|
193
|
+
#pragma GCC diagnostic push
|
|
194
|
+
#if defined(__clang__)
|
|
195
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
196
|
+
#endif
|
|
197
|
+
#endif
|
|
94
198
|
char buff[20];
|
|
95
199
|
snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
|
|
96
|
-
|
|
97
|
-
|
|
200
|
+
buffer_.append (buff);
|
|
201
|
+
#if defined(__GNUC__)
|
|
202
|
+
#pragma GCC diagnostic pop
|
|
203
|
+
#endif
|
|
98
204
|
return *this;
|
|
99
205
|
}
|
|
100
206
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
test_reporter&
|
|
112
|
-
test_reporter::operator<< (const T& t)
|
|
207
|
+
/**
|
|
208
|
+
* @details
|
|
209
|
+
* Delegates to `detail::get(t)` to obtain the displayable value
|
|
210
|
+
* of an op expression, then streams it through `operator<<` to
|
|
211
|
+
* format it into the buffer.
|
|
212
|
+
*/
|
|
213
|
+
template <class T>
|
|
214
|
+
requires type_traits::is_op<T>
|
|
215
|
+
expression_formatter&
|
|
216
|
+
expression_formatter::operator<< (const T& t)
|
|
113
217
|
{
|
|
114
218
|
*this << detail::get (t);
|
|
115
219
|
return *this;
|
|
116
220
|
}
|
|
117
|
-
#endif
|
|
118
221
|
|
|
119
222
|
/**
|
|
120
223
|
* @details
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* The value is converted to a string using `std::to_string` after being cast
|
|
125
|
-
* to `long long`, ensuring accurate formatting and compatibility across
|
|
126
|
-
* platforms. The resulting string is appended to the internal output buffer,
|
|
127
|
-
* allowing integral values to be included in test reports and diagnostics.
|
|
128
|
-
*
|
|
129
|
-
* This approach ensures precise and unambiguous representation of integral
|
|
130
|
-
* values, which is particularly advantageous for verifying test results and
|
|
131
|
-
* facilitating debugging.
|
|
224
|
+
* Casts the underlying integral value to `long long` and formats
|
|
225
|
+
* it without a type suffix, appending the result to the buffer.
|
|
132
226
|
*/
|
|
133
227
|
template <class T>
|
|
134
|
-
|
|
135
|
-
|
|
228
|
+
expression_formatter&
|
|
229
|
+
expression_formatter::operator<< (
|
|
230
|
+
const type_traits::genuine_integral_value<T>& v)
|
|
136
231
|
{
|
|
137
|
-
|
|
232
|
+
detail::append_number_ (buffer_, static_cast<long long> (v.get ()));
|
|
138
233
|
return *this;
|
|
139
234
|
}
|
|
140
235
|
|
|
141
236
|
/**
|
|
142
237
|
* @details
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* The contents of the container are enclosed in curly braces and each
|
|
147
|
-
* element is separated by a comma and a space. The operator iterates over
|
|
148
|
-
* the container, formatting each element in sequence, which ensures clarity
|
|
149
|
-
* and consistency in test reports and diagnostics.
|
|
150
|
-
*
|
|
151
|
-
* This approach provides a clear visual representation of container
|
|
152
|
-
* contents, making it easier to interpret test results and debug issues
|
|
153
|
-
* involving collections of values.
|
|
238
|
+
* Iterates the container and formats each element separated by
|
|
239
|
+
* `", "`, surrounded by `{` and `}`. Each element is streamed
|
|
240
|
+
* through `operator<<`, which recurses as needed for nested types.
|
|
154
241
|
*/
|
|
155
|
-
template <class T
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
test_reporter::operator<< (T&& t)
|
|
242
|
+
template <class T>
|
|
243
|
+
requires (type_traits::container_like<T> and not type_traits::has_npos<T>)
|
|
244
|
+
expression_formatter&
|
|
245
|
+
expression_formatter::operator<< (const T& t)
|
|
160
246
|
{
|
|
161
247
|
*this << '{';
|
|
162
248
|
auto first = true;
|
|
@@ -169,9 +255,12 @@ namespace micro_os_plus::micro_test_plus
|
|
|
169
255
|
return *this;
|
|
170
256
|
}
|
|
171
257
|
|
|
258
|
+
// --------------------------------------------------------------------------
|
|
259
|
+
// Compound expression operators (without colour codes).
|
|
260
|
+
|
|
172
261
|
/**
|
|
173
262
|
* @details
|
|
174
|
-
* This operator overload enables the `
|
|
263
|
+
* This operator overload enables the `reporter` to output equality
|
|
175
264
|
* comparison expressions in a clear and expressive format.
|
|
176
265
|
*
|
|
177
266
|
* The left-hand side and right-hand side values are formatted and separated
|
|
@@ -181,16 +270,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
181
270
|
* equality assertions and facilitates efficient debugging of test failures.
|
|
182
271
|
*/
|
|
183
272
|
template <class Lhs_T, class Rhs_T>
|
|
184
|
-
|
|
185
|
-
|
|
273
|
+
expression_formatter&
|
|
274
|
+
expression_formatter::operator<< (const detail::eq_<Lhs_T, Rhs_T>& op)
|
|
186
275
|
{
|
|
187
|
-
return (*this <<
|
|
188
|
-
<<
|
|
276
|
+
return (*this << colour_ (op) << op.lhs () << " == " << op.rhs ()
|
|
277
|
+
<< colours_.none);
|
|
189
278
|
}
|
|
190
279
|
|
|
191
280
|
/**
|
|
192
281
|
* @details
|
|
193
|
-
* This operator overload enables the `
|
|
282
|
+
* This operator overload enables the `reporter` to output inequality
|
|
194
283
|
* comparison expressions in a clear and expressive format.
|
|
195
284
|
*
|
|
196
285
|
* The left-hand side and right-hand side values are formatted and separated
|
|
@@ -201,16 +290,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
201
290
|
* failures.
|
|
202
291
|
*/
|
|
203
292
|
template <class Lhs_T, class Rhs_T>
|
|
204
|
-
|
|
205
|
-
|
|
293
|
+
expression_formatter&
|
|
294
|
+
expression_formatter::operator<< (const detail::ne_<Lhs_T, Rhs_T>& op)
|
|
206
295
|
{
|
|
207
|
-
return (*this <<
|
|
208
|
-
<<
|
|
296
|
+
return (*this << colour_ (op) << op.lhs () << " != " << op.rhs ()
|
|
297
|
+
<< colours_.none);
|
|
209
298
|
}
|
|
210
299
|
|
|
211
300
|
/**
|
|
212
301
|
* @details
|
|
213
|
-
* This operator overload enables the `
|
|
302
|
+
* This operator overload enables the `reporter` to output greater-than
|
|
214
303
|
* comparison expressions in a clear and expressive format.
|
|
215
304
|
*
|
|
216
305
|
* The left-hand side and right-hand side values are formatted and separated
|
|
@@ -221,16 +310,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
221
310
|
* failures.
|
|
222
311
|
*/
|
|
223
312
|
template <class Lhs_T, class Rhs_T>
|
|
224
|
-
|
|
225
|
-
|
|
313
|
+
expression_formatter&
|
|
314
|
+
expression_formatter::operator<< (const detail::gt_<Lhs_T, Rhs_T>& op)
|
|
226
315
|
{
|
|
227
|
-
return (*this <<
|
|
228
|
-
<<
|
|
316
|
+
return (*this << colour_ (op) << op.lhs () << " > " << op.rhs ()
|
|
317
|
+
<< colours_.none);
|
|
229
318
|
}
|
|
230
319
|
|
|
231
320
|
/**
|
|
232
321
|
* @details
|
|
233
|
-
* This operator overload enables the `
|
|
322
|
+
* This operator overload enables the `reporter` to output
|
|
234
323
|
* greater-than-or-equal-to comparison expressions in a clear and expressive
|
|
235
324
|
* format.
|
|
236
325
|
*
|
|
@@ -242,16 +331,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
242
331
|
* efficient debugging of test failures.
|
|
243
332
|
*/
|
|
244
333
|
template <class Lhs_T, class Rhs_T>
|
|
245
|
-
|
|
246
|
-
|
|
334
|
+
expression_formatter&
|
|
335
|
+
expression_formatter::operator<< (const detail::ge_<Lhs_T, Rhs_T>& op)
|
|
247
336
|
{
|
|
248
|
-
return (*this <<
|
|
249
|
-
<<
|
|
337
|
+
return (*this << colour_ (op) << op.lhs () << " >= " << op.rhs ()
|
|
338
|
+
<< colours_.none);
|
|
250
339
|
}
|
|
251
340
|
|
|
252
341
|
/**
|
|
253
342
|
* @details
|
|
254
|
-
* This operator overload enables the `
|
|
343
|
+
* This operator overload enables the `reporter` to output less-than
|
|
255
344
|
* comparison expressions in a clear and expressive format.
|
|
256
345
|
*
|
|
257
346
|
* The left-hand side and right-hand side values are formatted and separated
|
|
@@ -261,16 +350,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
261
350
|
* less-than assertions and facilitates efficient debugging of test failures.
|
|
262
351
|
*/
|
|
263
352
|
template <class Lhs_T, class Rhs_T>
|
|
264
|
-
|
|
265
|
-
|
|
353
|
+
expression_formatter&
|
|
354
|
+
expression_formatter::operator<< (const detail::lt_<Rhs_T, Lhs_T>& op)
|
|
266
355
|
{
|
|
267
|
-
return (*this <<
|
|
268
|
-
<<
|
|
356
|
+
return (*this << colour_ (op) << op.lhs () << " < " << op.rhs ()
|
|
357
|
+
<< colours_.none);
|
|
269
358
|
}
|
|
270
359
|
|
|
271
360
|
/**
|
|
272
361
|
* @details
|
|
273
|
-
* This operator overload enables the `
|
|
362
|
+
* This operator overload enables the `reporter` to output
|
|
274
363
|
* less-than-or-equal-to comparison expressions in a clear and expressive
|
|
275
364
|
* format.
|
|
276
365
|
*
|
|
@@ -282,16 +371,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
282
371
|
* efficient debugging of test failures.
|
|
283
372
|
*/
|
|
284
373
|
template <class Lhs_T, class Rhs_T>
|
|
285
|
-
|
|
286
|
-
|
|
374
|
+
expression_formatter&
|
|
375
|
+
expression_formatter::operator<< (const detail::le_<Rhs_T, Lhs_T>& op)
|
|
287
376
|
{
|
|
288
|
-
return (*this <<
|
|
289
|
-
<<
|
|
377
|
+
return (*this << colour_ (op) << op.lhs () << " <= " << op.rhs ()
|
|
378
|
+
<< colours_.none);
|
|
290
379
|
}
|
|
291
380
|
|
|
292
381
|
/**
|
|
293
382
|
* @details
|
|
294
|
-
* This operator overload enables the `
|
|
383
|
+
* This operator overload enables the `reporter` to output logical
|
|
295
384
|
* conjunction (AND) expressions in a clear and structured format.
|
|
296
385
|
*
|
|
297
386
|
* The left-hand side and right-hand side expressions are enclosed in
|
|
@@ -302,16 +391,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
302
391
|
* test failures involving compound conditions.
|
|
303
392
|
*/
|
|
304
393
|
template <class Lhs_T, class Rhs_T>
|
|
305
|
-
|
|
306
|
-
|
|
394
|
+
expression_formatter&
|
|
395
|
+
expression_formatter::operator<< (const detail::and_<Lhs_T, Rhs_T>& op)
|
|
307
396
|
{
|
|
308
|
-
return (*this << '(' << op.lhs () <<
|
|
309
|
-
<< op.rhs () << ')');
|
|
397
|
+
return (*this << '(' << op.lhs () << colour_ (op) << " and "
|
|
398
|
+
<< colours_.none << op.rhs () << ')');
|
|
310
399
|
}
|
|
311
400
|
|
|
312
401
|
/**
|
|
313
402
|
* @details
|
|
314
|
-
* This operator overload enables the `
|
|
403
|
+
* This operator overload enables the `reporter` to output logical
|
|
315
404
|
* disjunction (OR) expressions in a clear and structured format.
|
|
316
405
|
*
|
|
317
406
|
* The left-hand side and right-hand side expressions are enclosed in
|
|
@@ -322,11 +411,11 @@ namespace micro_os_plus::micro_test_plus
|
|
|
322
411
|
* test failures involving compound conditions.
|
|
323
412
|
*/
|
|
324
413
|
template <class Lhs_T, class Rhs_T>
|
|
325
|
-
|
|
326
|
-
|
|
414
|
+
expression_formatter&
|
|
415
|
+
expression_formatter::operator<< (const detail::or_<Lhs_T, Rhs_T>& op)
|
|
327
416
|
{
|
|
328
|
-
return (*this << '(' << op.lhs () <<
|
|
329
|
-
<< op.rhs () << ')');
|
|
417
|
+
return (*this << '(' << op.lhs () << colour_ (op) << " or "
|
|
418
|
+
<< colours_.none << op.rhs () << ')');
|
|
330
419
|
}
|
|
331
420
|
|
|
332
421
|
/**
|
|
@@ -338,10 +427,10 @@ namespace micro_os_plus::micro_test_plus
|
|
|
338
427
|
* diagnostics.
|
|
339
428
|
*/
|
|
340
429
|
template <class T>
|
|
341
|
-
|
|
342
|
-
|
|
430
|
+
expression_formatter&
|
|
431
|
+
expression_formatter::operator<< (const detail::not_<T>& op)
|
|
343
432
|
{
|
|
344
|
-
return (*this <<
|
|
433
|
+
return (*this << colour_ (op) << "not " << op.operand () << colours_.none);
|
|
345
434
|
}
|
|
346
435
|
|
|
347
436
|
#if defined(__cpp_exceptions)
|
|
@@ -357,13 +446,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
357
446
|
* reports, and assists in the precise identification and debugging of
|
|
358
447
|
* exception-related test cases.
|
|
359
448
|
*/
|
|
360
|
-
template <class
|
|
361
|
-
|
|
362
|
-
|
|
449
|
+
template <class Callable_T, class Exception_T>
|
|
450
|
+
expression_formatter&
|
|
451
|
+
expression_formatter::operator<< (
|
|
452
|
+
const detail::throws_<Callable_T, Exception_T>& op)
|
|
363
453
|
{
|
|
364
|
-
return (*this <<
|
|
454
|
+
return (*this << colour_ (op) << "throws<"
|
|
365
455
|
<< reflection::type_name<Exception_T> () << ">"
|
|
366
|
-
<<
|
|
456
|
+
<< colours_.none);
|
|
367
457
|
}
|
|
368
458
|
|
|
369
459
|
/**
|
|
@@ -376,11 +466,12 @@ namespace micro_os_plus::micro_test_plus
|
|
|
376
466
|
* immediately apparent when an expression is expected to throw, thereby
|
|
377
467
|
* improving the readability and professionalism of the test output.
|
|
378
468
|
*/
|
|
379
|
-
template <class
|
|
380
|
-
|
|
381
|
-
|
|
469
|
+
template <class Callable_T>
|
|
470
|
+
expression_formatter&
|
|
471
|
+
expression_formatter::operator<< (
|
|
472
|
+
const detail::throws_<Callable_T, void>& op)
|
|
382
473
|
{
|
|
383
|
-
return (*this <<
|
|
474
|
+
return (*this << colour_ (op) << "throws" << colours_.none);
|
|
384
475
|
}
|
|
385
476
|
|
|
386
477
|
/**
|
|
@@ -393,73 +484,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
393
484
|
* apparent when an expression is guaranteed not to throw, thereby improving
|
|
394
485
|
* the readability and professionalism of the test output.
|
|
395
486
|
*/
|
|
396
|
-
template <class
|
|
397
|
-
|
|
398
|
-
|
|
487
|
+
template <class Callable_T>
|
|
488
|
+
expression_formatter&
|
|
489
|
+
expression_formatter::operator<< (const detail::nothrow_<Callable_T>& op)
|
|
399
490
|
{
|
|
400
|
-
return (*this <<
|
|
491
|
+
return (*this << colour_ (op) << "nothrow" << colours_.none);
|
|
401
492
|
}
|
|
402
493
|
#endif
|
|
403
494
|
|
|
404
|
-
/**
|
|
405
|
-
* @details
|
|
406
|
-
* This operator overload formats output for expressions that do not throw
|
|
407
|
-
* exceptions. It applies colour styling for clarity and ensures a structured
|
|
408
|
-
* representation of exception safety.
|
|
409
|
-
*
|
|
410
|
-
* When invoked, the function outputs a pass prefix, followed by either the
|
|
411
|
-
* provided message or, if the message is empty, the evaluated expression
|
|
412
|
-
* itself. It then appends a pass suffix to complete the output. This
|
|
413
|
-
* approach guarantees that successful test outcomes are presented in a clear
|
|
414
|
-
* and consistent manner, enhancing the readability and professionalism of
|
|
415
|
-
* test reports.
|
|
416
|
-
*/
|
|
417
|
-
template <class Expr_T>
|
|
418
|
-
void
|
|
419
|
-
test_reporter::pass (Expr_T& expr, std::string& message)
|
|
420
|
-
{
|
|
421
|
-
current_test_suite->current_test_case.index++;
|
|
422
|
-
|
|
423
|
-
output_pass_prefix_ (message);
|
|
424
|
-
|
|
425
|
-
if (message.empty ())
|
|
426
|
-
{
|
|
427
|
-
// If there is no message, display the evaluated expression.
|
|
428
|
-
*this << expr;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
output_pass_suffix_ ();
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* @details
|
|
436
|
-
* This function reports a test failure and formats the output in a clear and
|
|
437
|
-
* consistent manner. It provides contextual information, including the
|
|
438
|
-
* precise source location, and appends the evaluated expression when
|
|
439
|
-
* applicable. The failure handling process ensures uniformity in the
|
|
440
|
-
* presentation of unsuccessful test cases, aiding in the rapid
|
|
441
|
-
* identification and diagnosis of issues within test reports.
|
|
442
|
-
*/
|
|
443
|
-
template <class Expr_T>
|
|
444
|
-
void
|
|
445
|
-
test_reporter::fail (Expr_T& expr, bool abort, std::string& message,
|
|
446
|
-
const reflection::source_location& location)
|
|
447
|
-
{
|
|
448
|
-
current_test_suite->current_test_case.index++;
|
|
449
|
-
|
|
450
|
-
const bool hasExpression = type_traits::is_op_v<Expr_T>;
|
|
451
|
-
output_fail_prefix_ (message, hasExpression, location);
|
|
452
|
-
|
|
453
|
-
if constexpr (type_traits::is_op_v<Expr_T>)
|
|
454
|
-
{
|
|
455
|
-
*this << expr;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
output_fail_suffix_ (location, abort);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
495
|
// --------------------------------------------------------------------------
|
|
462
|
-
} // namespace micro_os_plus::micro_test_plus
|
|
496
|
+
} // namespace micro_os_plus::micro_test_plus::detail
|
|
463
497
|
|
|
464
498
|
#if defined(__GNUC__)
|
|
465
499
|
#pragma GCC diagnostic pop
|
|
@@ -471,6 +505,6 @@ namespace micro_os_plus::micro_test_plus
|
|
|
471
505
|
|
|
472
506
|
// ----------------------------------------------------------------------------
|
|
473
507
|
|
|
474
|
-
#endif //
|
|
508
|
+
#endif // MICRO_TEST_PLUS_EXPRESSION_FORMATTER_INLINES_H_
|
|
475
509
|
|
|
476
510
|
// ----------------------------------------------------------------------------
|