@micro-os-plus/micro-test-plus 3.2.2 → 3.2.3
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 +352 -2
- package/CMakeLists.txt +32 -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 +1885 -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 +471 -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.h +801 -0
- package/include/micro-os-plus/micro-test-plus/test-runner.h +241 -0
- package/include/micro-os-plus/micro-test-plus/test-suite.h +456 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
- package/include/micro-os-plus/micro-test-plus.h +169 -551
- package/meson.build +5 -5
- package/package.json +29 -34
- package/src/micro-test-plus.cpp +131 -35
- package/src/test-reporter.cpp +348 -6
- package/src/test-runner.cpp +69 -5
- package/src/test-suite.cpp +124 -5
- 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,333 @@
|
|
|
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++ function
|
|
21
|
+
* comparators.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the declarations for the function comparator templates
|
|
25
|
+
* and logical operators used within the µTest++ framework. It defines the
|
|
26
|
+
* interfaces for generic and pointer-based comparison functions, including
|
|
27
|
+
* equality, non-equality, greater than, less than, and their respective
|
|
28
|
+
* logical variants. Additionally, it declares logical combinators such as
|
|
29
|
+
* conjunction (`_and`), disjunction (`_or`), and negation (`_not`), as well as
|
|
30
|
+
* a utility for safely removing constness from objects.
|
|
31
|
+
*
|
|
32
|
+
* These comparators and logical operators enable expressive and type-safe test
|
|
33
|
+
* expectations and assertions, supporting both value and pointer semantics.
|
|
34
|
+
* The underscore-prefixed logical operators are intentionally named to avoid
|
|
35
|
+
* conflicts with standard operators and provide clear, readable test
|
|
36
|
+
* expressions.
|
|
37
|
+
*
|
|
38
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
39
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
40
|
+
* of naming conflicts.
|
|
41
|
+
*
|
|
42
|
+
* The header files are organised within the
|
|
43
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
44
|
+
* modular codebase.
|
|
45
|
+
*
|
|
46
|
+
* This file is intended solely for internal use within the framework and
|
|
47
|
+
* should not be included directly by user code.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
#ifndef MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
|
|
51
|
+
#define MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
|
|
52
|
+
|
|
53
|
+
// ----------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
#ifdef __cplusplus
|
|
56
|
+
|
|
57
|
+
// ----------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
#if defined(__GNUC__)
|
|
60
|
+
#pragma GCC diagnostic push
|
|
61
|
+
#pragma GCC diagnostic ignored "-Wpadded"
|
|
62
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
63
|
+
#if defined(__clang__)
|
|
64
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
65
|
+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
66
|
+
#endif
|
|
67
|
+
#endif
|
|
68
|
+
|
|
69
|
+
namespace micro_os_plus::micro_test_plus
|
|
70
|
+
{
|
|
71
|
+
// --------------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @ingroup micro-test-plus-function-comparators
|
|
75
|
+
* @brief Generic equality comparator for non-pointer types.
|
|
76
|
+
*
|
|
77
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
78
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
79
|
+
* @param [in] lhs Left hand side operand.
|
|
80
|
+
* @param [in] rhs Right hand side operand.
|
|
81
|
+
* @return A comparator object that evaluates to true if the operands are
|
|
82
|
+
* equal.
|
|
83
|
+
*/
|
|
84
|
+
template <class Lhs_T, class Rhs_T>
|
|
85
|
+
[[nodiscard]] constexpr auto
|
|
86
|
+
eq (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @ingroup micro-test-plus-function-comparators
|
|
90
|
+
* @brief Pointer equality comparator for any pointer types.
|
|
91
|
+
*
|
|
92
|
+
* @tparam Lhs_T Type of the left hand side pointer operand.
|
|
93
|
+
* @tparam Rhs_T Type of the right hand side pointer operand.
|
|
94
|
+
* @param [in] lhs Left hand side pointer operand.
|
|
95
|
+
* @param [in] rhs Right hand side pointer operand.
|
|
96
|
+
* @return A comparator object that evaluates to true if the pointers are
|
|
97
|
+
* equal.
|
|
98
|
+
*/
|
|
99
|
+
template <class Lhs_T, class Rhs_T>
|
|
100
|
+
[[nodiscard]] constexpr auto
|
|
101
|
+
eq (Lhs_T* lhs, Rhs_T* rhs);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @ingroup micro-test-plus-function-comparators
|
|
105
|
+
* @brief Generic non-equality comparator.
|
|
106
|
+
*
|
|
107
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
108
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
109
|
+
* @param [in] lhs Left hand side operand.
|
|
110
|
+
* @param [in] rhs Right hand side operand.
|
|
111
|
+
* @return A comparator object that evaluates to true if the operands are not
|
|
112
|
+
* equal.
|
|
113
|
+
*/
|
|
114
|
+
template <class Lhs_T, class Rhs_T>
|
|
115
|
+
[[nodiscard]] constexpr auto
|
|
116
|
+
ne (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @ingroup micro-test-plus-function-comparators
|
|
120
|
+
* @brief Pointer non-equality comparator.
|
|
121
|
+
*
|
|
122
|
+
* @tparam Lhs_T Type of the left hand side pointer operand.
|
|
123
|
+
* @tparam Rhs_T Type of the right hand side pointer operand.
|
|
124
|
+
* @param [in] lhs Left hand side pointer operand.
|
|
125
|
+
* @param [in] rhs Right hand side pointer operand.
|
|
126
|
+
* @return A comparator object that evaluates to true if the pointers are not
|
|
127
|
+
* equal.
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
template <class Lhs_T, class Rhs_T>
|
|
131
|
+
[[nodiscard]] constexpr auto
|
|
132
|
+
ne (Lhs_T* lhs, Rhs_T* rhs);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @ingroup micro-test-plus-function-comparators
|
|
136
|
+
* @brief Generic greater than comparator.
|
|
137
|
+
*
|
|
138
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
139
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
140
|
+
* @param [in] lhs Left hand side operand.
|
|
141
|
+
* @param [in] rhs Right hand side operand.
|
|
142
|
+
* @return A comparator object that evaluates to true if `lhs` is greater
|
|
143
|
+
* than `rhs`.
|
|
144
|
+
*/
|
|
145
|
+
template <class Lhs_T, class Rhs_T>
|
|
146
|
+
[[nodiscard]] constexpr auto
|
|
147
|
+
gt (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @ingroup micro-test-plus-function-comparators
|
|
151
|
+
* @brief Pointer greater than comparator.
|
|
152
|
+
*
|
|
153
|
+
* @tparam Lhs_T Type of the left hand side pointer operand.
|
|
154
|
+
* @tparam Rhs_T Type of the right hand side pointer operand.
|
|
155
|
+
* @param [in] lhs Left hand side pointer operand.
|
|
156
|
+
* @param [in] rhs Right hand side pointer operand.
|
|
157
|
+
* @return A comparator object that evaluates to true if the left hand side
|
|
158
|
+
* pointer is greater than the right hand side pointer.
|
|
159
|
+
*/
|
|
160
|
+
template <class Lhs_T, class Rhs_T>
|
|
161
|
+
[[nodiscard]] constexpr auto
|
|
162
|
+
gt (Lhs_T* lhs, Rhs_T* rhs);
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @ingroup micro-test-plus-function-comparators
|
|
166
|
+
* @brief Generic greater than or equal comparator.
|
|
167
|
+
*
|
|
168
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
169
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
170
|
+
*
|
|
171
|
+
* @param [in] lhs Left hand side operand.
|
|
172
|
+
* @param [in] rhs Right hand side operand.
|
|
173
|
+
* @return A comparator object that evaluates to true if `lhs` is greater
|
|
174
|
+
* than or equal to `rhs`.
|
|
175
|
+
*/
|
|
176
|
+
template <class Lhs_T, class Rhs_T>
|
|
177
|
+
[[nodiscard]] constexpr auto
|
|
178
|
+
ge (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @ingroup micro-test-plus-function-comparators
|
|
182
|
+
* @brief Pointer greater than or equal comparator.
|
|
183
|
+
*
|
|
184
|
+
* @tparam Lhs_T Type of the left hand side pointer operand.
|
|
185
|
+
* @tparam Rhs_T Type of the right hand side pointer operand.
|
|
186
|
+
*
|
|
187
|
+
* @param [in] lhs Left hand side pointer operand.
|
|
188
|
+
* @param [in] rhs Right hand side pointer operand.
|
|
189
|
+
* @return A comparator object that evaluates to true if the left hand side
|
|
190
|
+
* pointer is greater than or equal to the right hand side pointer.
|
|
191
|
+
*/
|
|
192
|
+
template <class Lhs_T, class Rhs_T>
|
|
193
|
+
[[nodiscard]] constexpr auto
|
|
194
|
+
ge (Lhs_T* lhs, Rhs_T* rhs);
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @ingroup micro-test-plus-function-comparators
|
|
198
|
+
* @brief Generic less than comparator.
|
|
199
|
+
*
|
|
200
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
201
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
202
|
+
*
|
|
203
|
+
* @param [in] lhs Left hand side operand.
|
|
204
|
+
* @param [in] rhs Right hand side operand.
|
|
205
|
+
* @return A comparator object that evaluates to true if `lhs` is less than
|
|
206
|
+
* `rhs`.
|
|
207
|
+
*/
|
|
208
|
+
template <class Lhs_T, class Rhs_T>
|
|
209
|
+
[[nodiscard]] constexpr auto
|
|
210
|
+
lt (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @ingroup micro-test-plus-function-comparators
|
|
214
|
+
* @brief Pointer less than comparator.
|
|
215
|
+
*
|
|
216
|
+
* @tparam Lhs_T Type of the left hand side pointer operand.
|
|
217
|
+
* @tparam Rhs_T Type of the right hand side pointer operand.
|
|
218
|
+
*
|
|
219
|
+
* @param [in] lhs Left hand side pointer operand.
|
|
220
|
+
* @param [in] rhs Right hand side pointer operand.
|
|
221
|
+
* @return A comparator object that evaluates to true if the left hand side
|
|
222
|
+
* pointer is less than the right hand side pointer.
|
|
223
|
+
*/
|
|
224
|
+
template <class Lhs_T, class Rhs_T>
|
|
225
|
+
[[nodiscard]] constexpr auto
|
|
226
|
+
lt (Lhs_T* lhs, Rhs_T* rhs);
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @ingroup micro-test-plus-function-comparators
|
|
230
|
+
* @brief Generic less than or equal comparator.
|
|
231
|
+
*
|
|
232
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
233
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
234
|
+
*
|
|
235
|
+
* @param [in] lhs Left hand side operand.
|
|
236
|
+
* @param [in] rhs Right hand side operand.
|
|
237
|
+
* @return A comparator object that evaluates to true if `lhs` is less than
|
|
238
|
+
* or equal to `rhs`.
|
|
239
|
+
*/
|
|
240
|
+
template <class Lhs_T, class Rhs_T>
|
|
241
|
+
[[nodiscard]] constexpr auto
|
|
242
|
+
le (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @ingroup micro-test-plus-function-comparators
|
|
246
|
+
* @brief Pointer less than or equal comparator.
|
|
247
|
+
*
|
|
248
|
+
* @tparam Lhs_T Type of the left hand side pointer operand.
|
|
249
|
+
* @tparam Rhs_T Type of the right hand side pointer operand.
|
|
250
|
+
*
|
|
251
|
+
* @param [in] lhs Left hand side pointer operand.
|
|
252
|
+
* @param [in] rhs Right hand side pointer operand.
|
|
253
|
+
* @return A comparator object that evaluates to true if the left hand side
|
|
254
|
+
* pointer is less than or equal to the right hand side pointer.
|
|
255
|
+
*/
|
|
256
|
+
template <class Lhs_T, class Rhs_T>
|
|
257
|
+
[[nodiscard]] constexpr auto
|
|
258
|
+
le (Lhs_T* lhs, Rhs_T* rhs);
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @ingroup micro-test-plus-logical-functions
|
|
262
|
+
* @brief Generic logical **not** operation.
|
|
263
|
+
*
|
|
264
|
+
* @tparam Expr_T Type of the operand.
|
|
265
|
+
*
|
|
266
|
+
* @param [in] expr Logical expression to be negated.
|
|
267
|
+
* @return An object that evaluates to true if the operand is false.
|
|
268
|
+
*/
|
|
269
|
+
template <class Expr_T>
|
|
270
|
+
[[nodiscard]] constexpr auto
|
|
271
|
+
_not (const Expr_T& expr);
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @ingroup micro-test-plus-logical-functions
|
|
275
|
+
* @brief Generic logical **and** operation.
|
|
276
|
+
*
|
|
277
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
278
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
279
|
+
*
|
|
280
|
+
* @param [in] lhs Left hand side operand.
|
|
281
|
+
* @param [in] rhs Right hand side operand.
|
|
282
|
+
* @return An object that evaluates to true if both operand expressions are
|
|
283
|
+
* true.
|
|
284
|
+
*/
|
|
285
|
+
template <class Lhs_T, class Rhs_T>
|
|
286
|
+
[[nodiscard]] constexpr auto
|
|
287
|
+
_and (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @ingroup micro-test-plus-logical-functions
|
|
291
|
+
* @brief Generic logical **or** operation.
|
|
292
|
+
*
|
|
293
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
294
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
295
|
+
*
|
|
296
|
+
* @param [in] lhs Left hand side operand.
|
|
297
|
+
* @param [in] rhs Right hand side operand.
|
|
298
|
+
* @return An object that evaluates to true if at least one of the operand
|
|
299
|
+
* expressions is true.
|
|
300
|
+
*/
|
|
301
|
+
template <class Lhs_T, class Rhs_T>
|
|
302
|
+
[[nodiscard]] constexpr auto
|
|
303
|
+
_or (const Lhs_T& lhs, const Rhs_T& rhs);
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @ingroup micro-test-plus-utility-functions
|
|
307
|
+
* @brief Generic mutator to remove const qualification from any type.
|
|
308
|
+
*
|
|
309
|
+
* @tparam T The type of the input object.
|
|
310
|
+
*
|
|
311
|
+
* @param [in] t The object from which to remove const qualification.
|
|
312
|
+
* @return A non-const reference to the input object.
|
|
313
|
+
*/
|
|
314
|
+
template <class T>
|
|
315
|
+
[[nodiscard]] constexpr auto
|
|
316
|
+
mut (const T& t) noexcept -> T&;
|
|
317
|
+
|
|
318
|
+
#if defined(__GNUC__)
|
|
319
|
+
#pragma GCC diagnostic pop
|
|
320
|
+
#endif
|
|
321
|
+
|
|
322
|
+
// --------------------------------------------------------------------------
|
|
323
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
324
|
+
|
|
325
|
+
// ----------------------------------------------------------------------------
|
|
326
|
+
|
|
327
|
+
#endif // __cplusplus
|
|
328
|
+
|
|
329
|
+
// ----------------------------------------------------------------------------
|
|
330
|
+
|
|
331
|
+
#endif // MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
|
|
332
|
+
|
|
333
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,172 @@
|
|
|
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 inline implementations for the µTest++
|
|
21
|
+
* internals.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the inline implementations for internal components of
|
|
25
|
+
* the µTest++ framework, including operator overloads and constructors for
|
|
26
|
+
* deferred reporting mechanisms.
|
|
27
|
+
*
|
|
28
|
+
* It defines the logic for accumulating expectation messages, handling both
|
|
29
|
+
* arithmetic and string-like types, as well as the construction and
|
|
30
|
+
* destruction behaviour of deferred reporters, ensuring that test outcomes are
|
|
31
|
+
* accurately captured and reported.
|
|
32
|
+
*
|
|
33
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus::detail`
|
|
34
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
35
|
+
* of naming conflicts.
|
|
36
|
+
*
|
|
37
|
+
* The header files are organised within the
|
|
38
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
39
|
+
* modular codebase.
|
|
40
|
+
*
|
|
41
|
+
* This file is intended solely for internal use within the framework and
|
|
42
|
+
* should not be included directly by user code.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
#ifndef MICRO_TEST_PLUS_DETAILS_INLINES_H_
|
|
46
|
+
#define MICRO_TEST_PLUS_DETAILS_INLINES_H_
|
|
47
|
+
|
|
48
|
+
// ----------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
#ifdef __cplusplus
|
|
51
|
+
|
|
52
|
+
// ----------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
#include <stdio.h>
|
|
55
|
+
#include <cstring>
|
|
56
|
+
// #include "test-reporter.h"
|
|
57
|
+
|
|
58
|
+
// ----------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
#if defined(__GNUC__)
|
|
61
|
+
#pragma GCC diagnostic push
|
|
62
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
63
|
+
#if defined(__clang__)
|
|
64
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
65
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
66
|
+
#endif
|
|
67
|
+
#endif
|
|
68
|
+
|
|
69
|
+
namespace micro_os_plus::micro_test_plus
|
|
70
|
+
{
|
|
71
|
+
// --------------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
namespace detail
|
|
74
|
+
{
|
|
75
|
+
// ------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @details
|
|
79
|
+
* This operator overload enables the deferred reporter to accumulate
|
|
80
|
+
* expectation messages by appending the provided value to the internal
|
|
81
|
+
* message string.
|
|
82
|
+
*
|
|
83
|
+
* If the argument is of an arithmetic type, it is first converted to a
|
|
84
|
+
* string using `std::to_string` before being appended. For all other
|
|
85
|
+
* types, the value is appended directly. This ensures that both numeric
|
|
86
|
+
* and string-like messages are handled appropriately and consistently.
|
|
87
|
+
*/
|
|
88
|
+
template <class T>
|
|
89
|
+
auto&
|
|
90
|
+
deferred_reporter_base::operator<< (const T& msg)
|
|
91
|
+
{
|
|
92
|
+
if constexpr (std::is_arithmetic_v<T>)
|
|
93
|
+
{
|
|
94
|
+
message_.append (std::to_string (msg));
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
{
|
|
98
|
+
message_.append (msg);
|
|
99
|
+
}
|
|
100
|
+
return *this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @details
|
|
107
|
+
* This constructor initialises a deferred reporter for a specific
|
|
108
|
+
* expression, capturing the evaluation result, abort status, and source
|
|
109
|
+
* location.
|
|
110
|
+
*
|
|
111
|
+
* The expression is evaluated and its boolean result is passed to the base
|
|
112
|
+
* class. The abort flag determines whether further test execution should
|
|
113
|
+
* be halted if the expectation fails. The source location provides
|
|
114
|
+
* contextual information for reporting purposes.
|
|
115
|
+
*/
|
|
116
|
+
template <class Expr_T>
|
|
117
|
+
constexpr deferred_reporter<Expr_T>::deferred_reporter (
|
|
118
|
+
const Expr_T& expr, bool abort,
|
|
119
|
+
const reflection::source_location& location)
|
|
120
|
+
: deferred_reporter_base{ static_cast<bool> (expr), location },
|
|
121
|
+
expr_{ expr }
|
|
122
|
+
{
|
|
123
|
+
#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
124
|
+
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
125
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
126
|
+
abort_ = abort;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @details
|
|
131
|
+
* The destructor finalises the deferred reporting process for a test
|
|
132
|
+
* expression. If the evaluated expression is true, the reporter records a
|
|
133
|
+
* successful outcome along with any accumulated message. If the expression
|
|
134
|
+
* is false, the reporter records a failure, including the abort status,
|
|
135
|
+
* message, and source location for comprehensive reporting.
|
|
136
|
+
*
|
|
137
|
+
* This mechanism ensures that all relevant information about the test
|
|
138
|
+
* outcome is captured and reported accurately when the deferred reporter
|
|
139
|
+
* goes out of scope.
|
|
140
|
+
*/
|
|
141
|
+
template <class Expr_T>
|
|
142
|
+
deferred_reporter<Expr_T>::~deferred_reporter ()
|
|
143
|
+
{
|
|
144
|
+
if (value_)
|
|
145
|
+
{
|
|
146
|
+
reporter.pass (expr_, message_);
|
|
147
|
+
}
|
|
148
|
+
else
|
|
149
|
+
{
|
|
150
|
+
reporter.fail (expr_, abort_, message_, location_);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ------------------------------------------------------------------------
|
|
155
|
+
} // namespace detail
|
|
156
|
+
|
|
157
|
+
// --------------------------------------------------------------------------
|
|
158
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
159
|
+
|
|
160
|
+
#if defined(__GNUC__)
|
|
161
|
+
#pragma GCC diagnostic pop
|
|
162
|
+
#endif
|
|
163
|
+
|
|
164
|
+
// ----------------------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
#endif // __cplusplus
|
|
167
|
+
|
|
168
|
+
// ----------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
#endif // MICRO_TEST_PLUS_DETAILS_INLINES_H_
|
|
171
|
+
|
|
172
|
+
// ----------------------------------------------------------------------------
|