@micro-os-plus/micro-test-plus 3.1.1 → 3.1.2
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 +303 -1
- package/CMakeLists.txt +9 -11
- package/README.md +12 -1226
- package/include/micro-os-plus/detail.h +54 -36
- package/include/micro-os-plus/inlines.h +46 -7
- package/include/micro-os-plus/literals.h +154 -25
- package/include/micro-os-plus/micro-test-plus.h +253 -67
- package/include/micro-os-plus/reflection.h +9 -5
- package/include/micro-os-plus/test-reporter-inlines.h +2 -2
- package/include/micro-os-plus/test-reporter.h +11 -4
- package/include/micro-os-plus/test-runner.h +2 -2
- package/include/micro-os-plus/test-suite.h +70 -6
- package/include/micro-os-plus/type-traits.h +22 -10
- package/meson.build +23 -17
- package/package.json +25 -535
- package/src/micro-test-plus.cpp +43 -0
- package/src/test-reporter.cpp +11 -1
- package/src/test-runner.cpp +11 -4
|
@@ -62,41 +62,79 @@ namespace micro_os_plus::micro_test_plus
|
|
|
62
62
|
// Public API.
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
+
* @ingroup micro-test-plus-inits
|
|
65
66
|
* @brief Initialize the test framework.
|
|
67
|
+
* @param [in] argc The number of arguments.
|
|
68
|
+
* @param [in] argv Array of pointers to null terminated arguments.
|
|
69
|
+
* @param [in] name The name of the default test suite.
|
|
70
|
+
* @par Returns
|
|
71
|
+
* Nothing.
|
|
66
72
|
*/
|
|
67
73
|
void
|
|
68
74
|
initialize (int argc, char* argv[], const char* name = "Main");
|
|
69
75
|
|
|
70
76
|
/**
|
|
71
|
-
* @
|
|
77
|
+
* @ingroup micro-test-plus-inits
|
|
78
|
+
* @brief Complete the test and return the exit code.
|
|
79
|
+
* @par Parameters
|
|
80
|
+
* None.
|
|
81
|
+
* @return 0 for success, 1 for failure.
|
|
72
82
|
*/
|
|
73
|
-
|
|
74
|
-
void
|
|
75
|
-
test_case (const char* name, Callable_T&& func, Args_T&&... arguments);
|
|
83
|
+
[[nodiscard]] int
|
|
84
|
+
exit_code (void);
|
|
76
85
|
|
|
77
86
|
/**
|
|
78
|
-
* @
|
|
79
|
-
* and
|
|
87
|
+
* @ingroup micro-test-plus-test-case
|
|
88
|
+
* @brief Define and execute a test case.
|
|
89
|
+
* @tparam Callable_T The type of an object that can be called.
|
|
90
|
+
* @tparam Args_T The type of the callable arguments.
|
|
91
|
+
* @param [in] name The test case name or description.
|
|
92
|
+
* A short string used in the report.
|
|
93
|
+
* @param [in] callable A generic callable object,
|
|
94
|
+
* invoked to perform the test. Usually a lambda.
|
|
95
|
+
* @param [in] arguments A possibly empty list of arguments to be
|
|
96
|
+
* passed to the callable.
|
|
97
|
+
* @par Returns
|
|
98
|
+
* Nothing.
|
|
80
99
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
template <typename Callable_T, typename... Args_T>
|
|
101
|
+
void
|
|
102
|
+
test_case (const char* name, Callable_T&& callable, Args_T&&... arguments);
|
|
83
103
|
|
|
84
104
|
/**
|
|
85
|
-
* @
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
105
|
+
* @ingroup micro-test-plus-expectations
|
|
106
|
+
* @brief Evaluate a generic condition and report the results.
|
|
107
|
+
* @tparam Expr_T The type of the custom expression.
|
|
108
|
+
* @param [in] expr Logical expression to evaluate.
|
|
109
|
+
* @param [in] sl Optional source location, by default the current line.
|
|
110
|
+
* @return An output stream to write optional messages.
|
|
90
111
|
*
|
|
91
|
-
*
|
|
112
|
+
* @details
|
|
113
|
+
* The expression can be any logical expression, but, in order to
|
|
114
|
+
* allow the framework to help identify the reason why the check failed
|
|
115
|
+
* (by displaying the actual vs. the expected values), the expression
|
|
116
|
+
* should use the provided `eq()`, `ne()`, `lt()`, `le()`, `gt()`, `ge()`
|
|
117
|
+
* comparators, or, if the custom operators namespace is included,
|
|
118
|
+
* to use the custom type operands.
|
|
119
|
+
*
|
|
120
|
+
* The function template can be used only for expressions that evaluate to
|
|
92
121
|
* a boolean or use custom comparators/operators derived from the
|
|
93
|
-
* local `op` type.
|
|
122
|
+
* local `detail::op` type.
|
|
123
|
+
*
|
|
124
|
+
* For generic checks performed with standard C/C++
|
|
125
|
+
*`if` statements outside the `expect()` logical expression
|
|
126
|
+
* (like complex `try`/`catch` statements),
|
|
127
|
+
* the results can be reported with `expect(true)` or `expect(false)`.
|
|
128
|
+
*
|
|
129
|
+
* @par Example
|
|
130
|
+
* ```cpp
|
|
131
|
+
* expect (compute_answer () == 42) << "answer is 42";
|
|
132
|
+
* ```
|
|
94
133
|
*/
|
|
95
|
-
template <
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Expr_T> or type_traits::is_convertible_v<Expr_T, bool>> = 0>
|
|
134
|
+
template <class Expr_T, type_traits::requires_t<
|
|
135
|
+
type_traits::is_op_v<Expr_T>
|
|
136
|
+
or type_traits::is_convertible_v<Expr_T, bool>>
|
|
137
|
+
= 0>
|
|
100
138
|
constexpr auto
|
|
101
139
|
expect (const Expr_T& expr, const reflection::source_location& sl
|
|
102
140
|
= reflection::source_location::current ())
|
|
@@ -105,17 +143,26 @@ namespace micro_os_plus::micro_test_plus
|
|
|
105
143
|
}
|
|
106
144
|
|
|
107
145
|
/**
|
|
146
|
+
* @ingroup micro-test-plus-assumptions
|
|
108
147
|
* @brief Check a condition and, if false, abort.
|
|
148
|
+
* @tparam Expr_T The type of the custom expression.
|
|
149
|
+
* @param [in] expr Logical expression to evaluate.
|
|
150
|
+
* @param [in] sl Optional source location, by default the current line.
|
|
151
|
+
* @return An output stream to write optional messages.
|
|
109
152
|
*
|
|
110
153
|
* The template is usable only for expressions that evaluate to
|
|
111
154
|
* a boolean or use custom comparators/operators derived from the
|
|
112
|
-
* local `op` type.
|
|
155
|
+
* local `detail::op` type.
|
|
156
|
+
*
|
|
157
|
+
* @par Example
|
|
158
|
+
* ```cpp
|
|
159
|
+
* assert (compute_answer () == 42) << "answer is 42";
|
|
160
|
+
* ```
|
|
113
161
|
*/
|
|
114
|
-
template <
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
Expr_T> or type_traits::is_convertible_v<Expr_T, bool>> = 0>
|
|
162
|
+
template <class Expr_T, type_traits::requires_t<
|
|
163
|
+
type_traits::is_op_v<Expr_T>
|
|
164
|
+
or type_traits::is_convertible_v<Expr_T, bool>>
|
|
165
|
+
= 0>
|
|
119
166
|
constexpr auto
|
|
120
167
|
assume (const Expr_T& expr, const reflection::source_location& sl
|
|
121
168
|
= reflection::source_location::current ())
|
|
@@ -127,7 +174,12 @@ namespace micro_os_plus::micro_test_plus
|
|
|
127
174
|
|
|
128
175
|
#if defined(__cpp_exceptions)
|
|
129
176
|
/**
|
|
177
|
+
* @ingroup micro-test-plus-exceptions
|
|
130
178
|
* @brief Check if a callable throws a specific exception.
|
|
179
|
+
* @tparam Exception_T Type of the exception.
|
|
180
|
+
* @tparam Callable_T The type of an object that can be called.
|
|
181
|
+
* @param [in] func Function to check.
|
|
182
|
+
* @return An output stream to write optional messages.
|
|
131
183
|
*/
|
|
132
184
|
template <class Exception_T, class Callable_T>
|
|
133
185
|
[[nodiscard]] constexpr auto
|
|
@@ -137,7 +189,11 @@ namespace micro_os_plus::micro_test_plus
|
|
|
137
189
|
}
|
|
138
190
|
|
|
139
191
|
/**
|
|
192
|
+
* @ingroup micro-test-plus-exceptions
|
|
140
193
|
* @brief Check if a callable throws an exception (any exception).
|
|
194
|
+
* @tparam Callable_T The type of an object that can be called.
|
|
195
|
+
* @param [in] func Function to check.
|
|
196
|
+
* @return An output stream to write optional messages.
|
|
141
197
|
*/
|
|
142
198
|
template <class Callable_T>
|
|
143
199
|
[[nodiscard]] constexpr auto
|
|
@@ -147,7 +203,11 @@ namespace micro_os_plus::micro_test_plus
|
|
|
147
203
|
}
|
|
148
204
|
|
|
149
205
|
/**
|
|
206
|
+
* @ingroup micro-test-plus-exceptions
|
|
150
207
|
* @brief Check if a callable doesn't throw an exception.
|
|
208
|
+
* @tparam Callable_T The type of an object that can be called.
|
|
209
|
+
* @param [in] func Function to check.
|
|
210
|
+
* @return An output stream to write optional messages.
|
|
151
211
|
*/
|
|
152
212
|
template <class Callable_T>
|
|
153
213
|
[[nodiscard]] constexpr auto
|
|
@@ -160,8 +220,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
160
220
|
// --------------------------------------------------------------------------
|
|
161
221
|
|
|
162
222
|
/**
|
|
223
|
+
* @ingroup micro-test-plus-function-comparators
|
|
163
224
|
* @brief Generic equality comparator. Matches any
|
|
164
225
|
* non-pointer type.
|
|
226
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
227
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
228
|
+
* @param [in] lhs Left hand side operand.
|
|
229
|
+
* @param [in] rhs Right hand side operand.
|
|
230
|
+
* @return True if the operands are equal.
|
|
165
231
|
*/
|
|
166
232
|
template <class Lhs_T, class Rhs_T>
|
|
167
233
|
[[nodiscard]] constexpr auto
|
|
@@ -171,8 +237,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
171
237
|
}
|
|
172
238
|
|
|
173
239
|
/**
|
|
240
|
+
* @ingroup micro-test-plus-function-comparators
|
|
174
241
|
* @brief Pointer equality comparator. Matches pointers
|
|
175
242
|
* to any types.
|
|
243
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
244
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
245
|
+
* @param [in] lhs Left hand side operand.
|
|
246
|
+
* @param [in] rhs Right hand side operand.
|
|
247
|
+
* @return True if the pointers are equal.
|
|
176
248
|
*/
|
|
177
249
|
template <class Lhs_T, class Rhs_T>
|
|
178
250
|
[[nodiscard]] constexpr auto
|
|
@@ -182,7 +254,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
182
254
|
}
|
|
183
255
|
|
|
184
256
|
/**
|
|
257
|
+
* @ingroup micro-test-plus-function-comparators
|
|
185
258
|
* @brief Generic non-equality comparator.
|
|
259
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
260
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
261
|
+
* @param [in] lhs Left hand side operand.
|
|
262
|
+
* @param [in] rhs Right hand side operand.
|
|
263
|
+
* @return True if the operands are not equal.
|
|
186
264
|
*/
|
|
187
265
|
template <class Lhs_T, class Rhs_T>
|
|
188
266
|
[[nodiscard]] constexpr auto
|
|
@@ -192,7 +270,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
192
270
|
}
|
|
193
271
|
|
|
194
272
|
/**
|
|
273
|
+
* @ingroup micro-test-plus-function-comparators
|
|
195
274
|
* @brief Pointer non-equality comparator.
|
|
275
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
276
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
277
|
+
* @param [in] lhs Left hand side operand.
|
|
278
|
+
* @param [in] rhs Right hand side operand.
|
|
279
|
+
* @return True if the pointers are not equal.
|
|
196
280
|
*/
|
|
197
281
|
template <class Lhs_T, class Rhs_T>
|
|
198
282
|
[[nodiscard]] constexpr auto
|
|
@@ -202,7 +286,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
202
286
|
}
|
|
203
287
|
|
|
204
288
|
/**
|
|
289
|
+
* @ingroup micro-test-plus-function-comparators
|
|
205
290
|
* @brief Generic greater than comparator.
|
|
291
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
292
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
293
|
+
* @param [in] lhs Left hand side operand.
|
|
294
|
+
* @param [in] rhs Right hand side operand.
|
|
295
|
+
* @return True if lhs > rhs.
|
|
206
296
|
*/
|
|
207
297
|
template <class Lhs_T, class Rhs_T>
|
|
208
298
|
[[nodiscard]] constexpr auto
|
|
@@ -212,7 +302,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
212
302
|
}
|
|
213
303
|
|
|
214
304
|
/**
|
|
305
|
+
* @ingroup micro-test-plus-function-comparators
|
|
215
306
|
* @brief Pointer greater than comparator.
|
|
307
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
308
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
309
|
+
* @param [in] lhs Left hand side operand.
|
|
310
|
+
* @param [in] rhs Right hand side operand.
|
|
311
|
+
* @return True if the lhs pointer > rhs pointer.
|
|
216
312
|
*/
|
|
217
313
|
template <class Lhs_T, class Rhs_T>
|
|
218
314
|
[[nodiscard]] constexpr auto
|
|
@@ -222,7 +318,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
222
318
|
}
|
|
223
319
|
|
|
224
320
|
/**
|
|
321
|
+
* @ingroup micro-test-plus-function-comparators
|
|
225
322
|
* @brief Generic greater than or equal comparator.
|
|
323
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
324
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
325
|
+
* @param [in] lhs Left hand side operand.
|
|
326
|
+
* @param [in] rhs Right hand side operand.
|
|
327
|
+
* @return True if lhs >= rhs.
|
|
226
328
|
*/
|
|
227
329
|
template <class Lhs_T, class Rhs_T>
|
|
228
330
|
[[nodiscard]] constexpr auto
|
|
@@ -232,7 +334,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
232
334
|
}
|
|
233
335
|
|
|
234
336
|
/**
|
|
337
|
+
* @ingroup micro-test-plus-function-comparators
|
|
235
338
|
* @brief Pointer greater than or equal comparator.
|
|
339
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
340
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
341
|
+
* @param [in] lhs Left hand side operand.
|
|
342
|
+
* @param [in] rhs Right hand side operand.
|
|
343
|
+
* @return True if the lhs pointer >= rhs pointer.
|
|
236
344
|
*/
|
|
237
345
|
template <class Lhs_T, class Rhs_T>
|
|
238
346
|
[[nodiscard]] constexpr auto
|
|
@@ -242,7 +350,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
242
350
|
}
|
|
243
351
|
|
|
244
352
|
/**
|
|
353
|
+
* @ingroup micro-test-plus-function-comparators
|
|
245
354
|
* @brief Generic less than comparator.
|
|
355
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
356
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
357
|
+
* @param [in] lhs Left hand side operand.
|
|
358
|
+
* @param [in] rhs Right hand side operand.
|
|
359
|
+
* @return True if lhs < rhs.
|
|
246
360
|
*/
|
|
247
361
|
template <class Lhs_T, class Rhs_T>
|
|
248
362
|
[[nodiscard]] constexpr auto
|
|
@@ -252,7 +366,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
252
366
|
}
|
|
253
367
|
|
|
254
368
|
/**
|
|
369
|
+
* @ingroup micro-test-plus-function-comparators
|
|
255
370
|
* @brief Generic less than comparator.
|
|
371
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
372
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
373
|
+
* @param [in] lhs Left hand side operand.
|
|
374
|
+
* @param [in] rhs Right hand side operand.
|
|
375
|
+
* @return True if the lhs pointer < rhs pointer.
|
|
256
376
|
*/
|
|
257
377
|
template <class Lhs_T, class Rhs_T>
|
|
258
378
|
[[nodiscard]] constexpr auto
|
|
@@ -262,7 +382,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
262
382
|
}
|
|
263
383
|
|
|
264
384
|
/**
|
|
385
|
+
* @ingroup micro-test-plus-function-comparators
|
|
265
386
|
* @brief Generic less than or equal comparator.
|
|
387
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
388
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
389
|
+
* @param [in] lhs Left hand side operand.
|
|
390
|
+
* @param [in] rhs Right hand side operand.
|
|
391
|
+
* @return True if lhs <= rhs.
|
|
266
392
|
*/
|
|
267
393
|
template <class Lhs_T, class Rhs_T>
|
|
268
394
|
[[nodiscard]] constexpr auto
|
|
@@ -272,7 +398,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
272
398
|
}
|
|
273
399
|
|
|
274
400
|
/**
|
|
401
|
+
* @ingroup micro-test-plus-function-comparators
|
|
275
402
|
* @brief Generic less than or equal comparator.
|
|
403
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
404
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
405
|
+
* @param [in] lhs Left hand side operand.
|
|
406
|
+
* @param [in] rhs Right hand side operand.
|
|
407
|
+
* @return True if the lhs pointer <= rhs pointer.
|
|
276
408
|
*/
|
|
277
409
|
template <class Lhs_T, class Rhs_T>
|
|
278
410
|
[[nodiscard]] constexpr auto
|
|
@@ -282,7 +414,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
282
414
|
}
|
|
283
415
|
|
|
284
416
|
/**
|
|
285
|
-
* @
|
|
417
|
+
* @ingroup micro-test-plus-logical-functions
|
|
418
|
+
* @brief Generic logical **not**.
|
|
419
|
+
* @tparam Expr_T Type of the operand.
|
|
420
|
+
* @param [in] expr Logical expression.
|
|
421
|
+
* @return True if the operand is false.
|
|
422
|
+
*
|
|
423
|
+
* @note
|
|
424
|
+
* The underscore is intentional,
|
|
286
425
|
* to differentiate from the standard operator.
|
|
287
426
|
*/
|
|
288
427
|
template <class Expr_T>
|
|
@@ -293,7 +432,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
293
432
|
}
|
|
294
433
|
|
|
295
434
|
/**
|
|
296
|
-
* @
|
|
435
|
+
* @ingroup micro-test-plus-logical-functions
|
|
436
|
+
* @brief Generic logical **and**.
|
|
437
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
438
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
439
|
+
* @param [in] lhs Left hand side operand.
|
|
440
|
+
* @param [in] rhs Right hand side operand.
|
|
441
|
+
* @return True if both operand expressions are true.
|
|
442
|
+
*
|
|
443
|
+
* @note
|
|
444
|
+
* The underscore is intentional,
|
|
297
445
|
* to differentiate from the standard operator.
|
|
298
446
|
*/
|
|
299
447
|
template <class Lhs_T, class Rhs_T>
|
|
@@ -304,7 +452,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
304
452
|
}
|
|
305
453
|
|
|
306
454
|
/**
|
|
307
|
-
* @
|
|
455
|
+
* @ingroup micro-test-plus-logical-functions
|
|
456
|
+
* @brief Generic logical **or**.
|
|
457
|
+
* @tparam Lhs_T Type of the left hand side operand.
|
|
458
|
+
* @tparam Rhs_T Type of the right hand side operand.
|
|
459
|
+
* @param [in] lhs Left hand side operand.
|
|
460
|
+
* @param [in] rhs Right hand side operand.
|
|
461
|
+
* @return True if at least one of the operand expressions is true.
|
|
462
|
+
*
|
|
463
|
+
* @note
|
|
464
|
+
* The underscore is intentional,
|
|
308
465
|
* to differentiate from the standard operator.
|
|
309
466
|
*/
|
|
310
467
|
template <class Lhs_T, class Rhs_T>
|
|
@@ -340,7 +497,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
340
497
|
namespace operators
|
|
341
498
|
{
|
|
342
499
|
/**
|
|
343
|
-
* @
|
|
500
|
+
* @ingroup micro-test-plus-string-operators
|
|
501
|
+
* @brief Equality operator for `string_view` objects.
|
|
344
502
|
*/
|
|
345
503
|
[[nodiscard]] constexpr auto
|
|
346
504
|
operator== (std::string_view lhs, std::string_view rhs)
|
|
@@ -349,7 +507,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
349
507
|
}
|
|
350
508
|
|
|
351
509
|
/**
|
|
352
|
-
* @
|
|
510
|
+
* @ingroup micro-test-plus-string-operators
|
|
511
|
+
* @brief Non-equality operator for `string_view` objects.
|
|
353
512
|
*/
|
|
354
513
|
[[nodiscard]] constexpr auto
|
|
355
514
|
operator!= (std::string_view lhs, std::string_view rhs)
|
|
@@ -358,6 +517,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
358
517
|
}
|
|
359
518
|
|
|
360
519
|
/**
|
|
520
|
+
* @ingroup micro-test-plus-container-operators
|
|
361
521
|
* @brief Equality operator for containers.
|
|
362
522
|
*/
|
|
363
523
|
template <class T,
|
|
@@ -369,6 +529,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
369
529
|
}
|
|
370
530
|
|
|
371
531
|
/**
|
|
532
|
+
* @ingroup micro-test-plus-container-operators
|
|
372
533
|
* @brief Non-equality operator for containers.
|
|
373
534
|
*/
|
|
374
535
|
template <class T,
|
|
@@ -380,13 +541,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
380
541
|
}
|
|
381
542
|
|
|
382
543
|
/**
|
|
544
|
+
* @ingroup micro-test-plus-operators
|
|
383
545
|
* @brief Equality operator. It matches only if at least one
|
|
384
546
|
* operand is of local type (derived from local `op`).
|
|
385
547
|
*/
|
|
386
|
-
template <
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
548
|
+
template <class Lhs_T, class Rhs_T,
|
|
549
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
550
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
551
|
+
= 0>
|
|
390
552
|
[[nodiscard]] constexpr auto
|
|
391
553
|
operator== (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
392
554
|
{
|
|
@@ -394,13 +556,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
394
556
|
}
|
|
395
557
|
|
|
396
558
|
/**
|
|
559
|
+
* @ingroup micro-test-plus-operators
|
|
397
560
|
* @brief Non-equality operator. It matches only if at least one
|
|
398
561
|
* operand is of local type (derived from local `op`).
|
|
399
562
|
*/
|
|
400
|
-
template <
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
563
|
+
template <class Lhs_T, class Rhs_T,
|
|
564
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
565
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
566
|
+
= 0>
|
|
404
567
|
[[nodiscard]] constexpr auto
|
|
405
568
|
operator!= (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
406
569
|
{
|
|
@@ -408,13 +571,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
408
571
|
}
|
|
409
572
|
|
|
410
573
|
/**
|
|
574
|
+
* @ingroup micro-test-plus-operators
|
|
411
575
|
* @brief Greater than operator. It matches only if at least one
|
|
412
576
|
* operand is of local type (derived from local `op`).
|
|
413
577
|
*/
|
|
414
|
-
template <
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
578
|
+
template <class Lhs_T, class Rhs_T,
|
|
579
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
580
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
581
|
+
= 0>
|
|
418
582
|
[[nodiscard]] constexpr auto
|
|
419
583
|
operator> (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
420
584
|
{
|
|
@@ -422,13 +586,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
422
586
|
}
|
|
423
587
|
|
|
424
588
|
/**
|
|
589
|
+
* @ingroup micro-test-plus-operators
|
|
425
590
|
* @brief Greater than or equal operator. It matches only if at least one
|
|
426
591
|
* operand is of local type (derived from local `op`).
|
|
427
592
|
*/
|
|
428
|
-
template <
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
593
|
+
template <class Lhs_T, class Rhs_T,
|
|
594
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
595
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
596
|
+
= 0>
|
|
432
597
|
[[nodiscard]] constexpr auto
|
|
433
598
|
operator>= (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
434
599
|
{
|
|
@@ -436,13 +601,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
436
601
|
}
|
|
437
602
|
|
|
438
603
|
/**
|
|
604
|
+
* @ingroup micro-test-plus-operators
|
|
439
605
|
* @brief Less than operator. It matches only if at least one
|
|
440
606
|
* operand is of local type (derived from local `op`).
|
|
441
607
|
*/
|
|
442
|
-
template <
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
608
|
+
template <class Lhs_T, class Rhs_T,
|
|
609
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
610
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
611
|
+
= 0>
|
|
446
612
|
[[nodiscard]] constexpr auto
|
|
447
613
|
operator< (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
448
614
|
{
|
|
@@ -450,13 +616,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
450
616
|
}
|
|
451
617
|
|
|
452
618
|
/**
|
|
619
|
+
* @ingroup micro-test-plus-operators
|
|
453
620
|
* @brief Less than or equal operator. It matches only if at least one
|
|
454
621
|
* operand is of local type (derived from local `op`).
|
|
455
622
|
*/
|
|
456
|
-
template <
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
623
|
+
template <class Lhs_T, class Rhs_T,
|
|
624
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
625
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
626
|
+
= 0>
|
|
460
627
|
[[nodiscard]] constexpr auto
|
|
461
628
|
operator<= (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
462
629
|
{
|
|
@@ -464,13 +631,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
464
631
|
}
|
|
465
632
|
|
|
466
633
|
/**
|
|
467
|
-
* @
|
|
634
|
+
* @ingroup micro-test-plus-operators
|
|
635
|
+
* @brief Logical `&&` (and) operator. It matches only if at least one
|
|
468
636
|
* operand is of local type (derived from local `op`).
|
|
469
637
|
*/
|
|
470
|
-
template <
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
638
|
+
template <class Lhs_T, class Rhs_T,
|
|
639
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
640
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
641
|
+
= 0>
|
|
474
642
|
[[nodiscard]] constexpr auto
|
|
475
643
|
operator and (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
476
644
|
{
|
|
@@ -478,13 +646,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
478
646
|
}
|
|
479
647
|
|
|
480
648
|
/**
|
|
481
|
-
* @
|
|
649
|
+
* @ingroup micro-test-plus-operators
|
|
650
|
+
* @brief Logical `||` (or) operator. It matches only if at least one
|
|
482
651
|
* operand is of local type (derived from local `op`).
|
|
483
652
|
*/
|
|
484
|
-
template <
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
653
|
+
template <class Lhs_T, class Rhs_T,
|
|
654
|
+
type_traits::requires_t<type_traits::is_op_v<Lhs_T>
|
|
655
|
+
or type_traits::is_op_v<Rhs_T>>
|
|
656
|
+
= 0>
|
|
488
657
|
[[nodiscard]] constexpr auto
|
|
489
658
|
operator or (const Lhs_T& lhs, const Rhs_T& rhs)
|
|
490
659
|
{
|
|
@@ -492,12 +661,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
492
661
|
}
|
|
493
662
|
|
|
494
663
|
/**
|
|
495
|
-
* @
|
|
664
|
+
* @ingroup micro-test-plus-operators
|
|
665
|
+
* @brief Logical `!` (not) operator. It matches only if the
|
|
496
666
|
* operand is of local type (derived from local `op`).
|
|
497
667
|
*/
|
|
498
668
|
template <class T, type_traits::requires_t<type_traits::is_op_v<T>> = 0>
|
|
499
669
|
[[nodiscard]] constexpr auto
|
|
500
|
-
operator not
|
|
670
|
+
operator not(const T& t)
|
|
501
671
|
{
|
|
502
672
|
return detail::not_{ t };
|
|
503
673
|
}
|
|
@@ -505,9 +675,25 @@ namespace micro_os_plus::micro_test_plus
|
|
|
505
675
|
|
|
506
676
|
namespace utility
|
|
507
677
|
{
|
|
678
|
+
/**
|
|
679
|
+
* @ingroup micro-test-plus-utility-functions
|
|
680
|
+
* @brief Check if a string matches a pattern.
|
|
681
|
+
* @param [in] input String view to check.
|
|
682
|
+
* @param [in] pattern Sting view with the pattern.
|
|
683
|
+
* @return True if the string matches the pattern.
|
|
684
|
+
*/
|
|
508
685
|
[[nodiscard]] bool
|
|
509
686
|
is_match (std::string_view input, std::string_view pattern);
|
|
510
687
|
|
|
688
|
+
/**
|
|
689
|
+
* @ingroup micro-test-plus-utility-functions
|
|
690
|
+
* @brief Split a string into a vector of sub-strings.
|
|
691
|
+
* @tparam T Type of the input string.
|
|
692
|
+
* @tparam Delim_T Type of the delimiter.
|
|
693
|
+
* @param [in] input Input string to split.
|
|
694
|
+
* @param [in] delim Delimiter string.
|
|
695
|
+
* @return An array of strings.
|
|
696
|
+
*/
|
|
511
697
|
template <class T, class Delim_T>
|
|
512
698
|
[[nodiscard]] auto
|
|
513
699
|
split (T input, Delim_T delim) -> std::vector<T>;
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
38
38
|
#if defined(__clang__)
|
|
39
39
|
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
40
|
+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
40
41
|
#endif
|
|
41
42
|
#endif
|
|
42
43
|
|
|
@@ -58,7 +59,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
58
59
|
[[nodiscard]] static constexpr auto
|
|
59
60
|
current (
|
|
60
61
|
#if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
|
|
61
|
-
const char* file = __builtin_FILE(), int line = __builtin_LINE()
|
|
62
|
+
const char* file = __builtin_FILE (), int line = __builtin_LINE ()
|
|
62
63
|
#else
|
|
63
64
|
const char* file = "unknown", int line = {}
|
|
64
65
|
#endif
|
|
@@ -102,12 +103,15 @@ namespace micro_os_plus::micro_test_plus
|
|
|
102
103
|
type_name () -> std::string_view
|
|
103
104
|
{
|
|
104
105
|
#if defined(__clang__)
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
#pragma GCC diagnostic push
|
|
107
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
108
|
+
// printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
|
|
109
|
+
// (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[78]);
|
|
107
110
|
return { &__PRETTY_FUNCTION__[78], sizeof (__PRETTY_FUNCTION__) - 80 };
|
|
111
|
+
#pragma GCC diagnostic pop
|
|
108
112
|
#elif defined(__GNUC__)
|
|
109
|
-
// printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
|
|
110
|
-
// printf("|%s|\n", &__PRETTY_FUNCTION__[93]);
|
|
113
|
+
// printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
|
|
114
|
+
// (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[93]);
|
|
111
115
|
return { &__PRETTY_FUNCTION__[93], sizeof (__PRETTY_FUNCTION__) - 144 };
|
|
112
116
|
#else
|
|
113
117
|
#error "Unsupported compiler"
|
|
@@ -71,8 +71,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
template <class T,
|
|
74
|
-
type_traits::requires_t<type_traits::is_container_v<
|
|
75
|
-
|
|
74
|
+
type_traits::requires_t<type_traits::is_container_v<T>
|
|
75
|
+
and not type_traits::has_npos_v<T>>>
|
|
76
76
|
test_reporter&
|
|
77
77
|
test_reporter::operator<< (T&& t)
|
|
78
78
|
{
|