@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.
Files changed (65) hide show
  1. package/CHANGELOG.md +412 -2
  2. package/CMakeLists.txt +134 -28
  3. package/README.md +3 -2
  4. package/config/xcdl-build.json +11 -4
  5. package/include/micro-os-plus/micro-test-plus/README.md +6 -0
  6. package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +267 -0
  7. package/include/micro-os-plus/micro-test-plus/detail.h +272 -1425
  8. package/include/micro-os-plus/micro-test-plus/exceptions.h +125 -0
  9. package/include/micro-os-plus/micro-test-plus/expression-formatter.h +669 -0
  10. package/include/micro-os-plus/micro-test-plus/function-comparators.h +15 -7
  11. package/include/micro-os-plus/micro-test-plus/inlines/{details-inlines.h → deferred-reporter-inlines.h} +66 -44
  12. package/include/micro-os-plus/micro-test-plus/inlines/detail-inlines.h +711 -0
  13. package/include/micro-os-plus/micro-test-plus/inlines/exceptions-inline.h +137 -0
  14. package/include/micro-os-plus/micro-test-plus/inlines/{test-reporter-inlines.h → expression-formatter-inlines.h} +232 -198
  15. package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +24 -20
  16. package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +50 -31
  17. package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +25 -19
  18. package/include/micro-os-plus/micro-test-plus/inlines/operators-inlines.h +275 -0
  19. package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +39 -21
  20. package/include/micro-os-plus/micro-test-plus/inlines/reporter-inlines.h +205 -0
  21. package/include/micro-os-plus/micro-test-plus/inlines/runner-inlines.h +151 -0
  22. package/include/micro-os-plus/micro-test-plus/inlines/runner-totals-inlines.h +152 -0
  23. package/include/micro-os-plus/micro-test-plus/inlines/test-inlines.h +555 -0
  24. package/include/micro-os-plus/micro-test-plus/inlines/timings-inlines.h +120 -0
  25. package/include/micro-os-plus/micro-test-plus/inlines/type-traits-inlines.h +231 -0
  26. package/include/micro-os-plus/micro-test-plus/inlines/utility-inlines.h +126 -0
  27. package/include/micro-os-plus/micro-test-plus/literals.h +12 -17
  28. package/include/micro-os-plus/micro-test-plus/math.h +14 -6
  29. package/include/micro-os-plus/micro-test-plus/operators.h +53 -209
  30. package/include/micro-os-plus/micro-test-plus/reflection.h +8 -4
  31. package/include/micro-os-plus/micro-test-plus/{test-reporter-basic.h → reporter-human.h} +80 -74
  32. package/include/micro-os-plus/micro-test-plus/{test-reporter-tap.h → reporter-tap.h} +77 -71
  33. package/include/micro-os-plus/micro-test-plus/reporter.h +619 -0
  34. package/include/micro-os-plus/micro-test-plus/runner-totals.h +250 -0
  35. package/include/micro-os-plus/micro-test-plus/runner.h +472 -0
  36. package/include/micro-os-plus/micro-test-plus/test.h +1013 -0
  37. package/include/micro-os-plus/micro-test-plus/timings.h +363 -0
  38. package/include/micro-os-plus/micro-test-plus/type-traits.h +223 -577
  39. package/include/micro-os-plus/micro-test-plus/utility.h +136 -0
  40. package/include/micro-os-plus/micro-test-plus.h +42 -236
  41. package/meson.build +11 -6
  42. package/package.json +11 -3
  43. package/src/deferred-reporter.cpp +137 -0
  44. package/src/expression-formatter.cpp +289 -0
  45. package/src/reflection.cpp +97 -0
  46. package/src/reporter-human.cpp +816 -0
  47. package/src/reporter-tap.cpp +772 -0
  48. package/src/reporter.cpp +481 -0
  49. package/src/runner-totals.cpp +98 -0
  50. package/src/runner.cpp +669 -0
  51. package/src/test.cpp +503 -0
  52. package/src/timings.cpp +210 -0
  53. package/src/utility.cpp +163 -0
  54. package/.cmake-format.yaml +0 -11
  55. package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +0 -313
  56. package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +0 -115
  57. package/include/micro-os-plus/micro-test-plus/test-reporter.h +0 -846
  58. package/include/micro-os-plus/micro-test-plus/test-runner.h +0 -281
  59. package/include/micro-os-plus/micro-test-plus/test-suite.h +0 -492
  60. package/src/micro-test-plus.cpp +0 -316
  61. package/src/test-reporter-basic.cpp +0 -466
  62. package/src/test-reporter-tap.cpp +0 -530
  63. package/src/test-reporter.cpp +0 -399
  64. package/src/test-runner.cpp +0 -311
  65. package/src/test-suite.cpp +0 -304
@@ -48,9 +48,12 @@
48
48
 
49
49
  // ----------------------------------------------------------------------------
50
50
 
51
- #include <stdio.h>
51
+ #include <cstdio>
52
52
  #include <string>
53
53
 
54
+ #include "type-traits.h"
55
+ #include "reflection.h"
56
+
54
57
  // ----------------------------------------------------------------------------
55
58
 
56
59
  #if defined(__GNUC__)
@@ -62,8 +65,12 @@
62
65
  #endif
63
66
  #endif
64
67
 
68
+ // ============================================================================
69
+
65
70
  namespace micro_os_plus::micro_test_plus
66
71
  {
72
+ class test_node;
73
+
67
74
  // --------------------------------------------------------------------------
68
75
 
69
76
  /**
@@ -91,20 +98,18 @@ namespace micro_os_plus::micro_test_plus
91
98
  */
92
99
  namespace detail
93
100
  {
101
+ // ========================================================================
102
+
94
103
  /**
95
104
  * @brief Assertion struct template for parameter passing to the evaluator.
96
105
  *
97
- * @tparam Expr_T The type of the expression being asserted.
98
- *
99
106
  * @details
100
- * The `assertion` struct template is used to encapsulate assertion
101
- * parameters, including the expression under evaluation and its associated
102
- * source location. This design enables precise reporting and diagnostics
103
- * within the framework.
107
+ * This structure encapsulates both the expression being tested and its
108
+ * associated source location. Used internally by the framework to pass
109
+ * assertion data through the evaluation pipeline, enabling accurate
110
+ * reporting of where assertions occur in test code.
104
111
  *
105
- * The structure is intended exclusively for internal use and is
106
- * implemented in the `include/micro-os-plus/micro-test-plus` folder to
107
- * maintain a structured and modular codebase.
112
+ * @tparam Expr_T The type of the expression being asserted.
108
113
  *
109
114
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
110
115
  */
@@ -122,74 +127,7 @@ namespace micro_os_plus::micro_test_plus
122
127
  reflection::source_location location{};
123
128
  };
124
129
 
125
- // ------------------------------------------------------------------------
126
-
127
- // in C++14/17/20, a function template with a deduced return type
128
- // (auto) cannot be used before its definition is visible.
129
- // Therefore it is not possible to split definitions.
130
-
131
- /**
132
- * @brief Generic getter function template for value retrieval.
133
- *
134
- * @tparam T The type from which the value is to be retrieved.
135
- *
136
- * @param t The object or value to be accessed.
137
- * @return The value obtained via the relevant getter implementation.
138
- *
139
- * @details
140
- * The `get` function template invokes the appropriate getter
141
- * implementation to retrieve the value from the provided object or type.
142
- * This function ensures consistent access to values for both custom and
143
- * standard types within the framework.
144
- *
145
- * The primary implementation attempts to invoke a `get()` method if it
146
- * exists, which is recommended for user-defined types to ensure consistent
147
- * value access. If the type does not provide a `get()` method, the
148
- * fallback variadic implementation simply returns the original argument.
149
- *
150
- * The `get` function template delegates to these implementations, enabling
151
- * seamless support for a wide range of types in test expressions and
152
- * comparators.
153
- *
154
- * All definitions are intended for internal use within the framework and
155
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
156
- * maintain a structured and modular codebase.
157
- */
158
- template <class T>
159
- [[nodiscard]] constexpr auto
160
- get_impl (const T& t, int) -> decltype (t.get ())
161
- {
162
- return t.get ();
163
- }
164
-
165
- /**
166
- * @brief Fallback variadic getter function template.
167
- *
168
- * @tparam T The type from which the value is to be retrieved.
169
- *
170
- * @param t The object or value to be accessed.
171
- * @return The original argument `t`.
172
- *
173
- * @details
174
- * The `get_impl` function template serves as a fallback mechanism for
175
- * value retrieval when the provided type does not implement a `get()`
176
- * member function. It simply returns the first argument, discarding any
177
- * additional parameters.
178
- *
179
- * This approach ensures that both custom types (with a `get()` method) and
180
- * standard types (without a `get()` method) are supported seamlessly
181
- * within the framework's generic getter utilities.
182
- *
183
- * All definitions are intended for internal use within the framework and
184
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
185
- * maintain a structured and modular codebase.
186
- */
187
- template <class T>
188
- [[nodiscard]] constexpr auto
189
- get_impl (const T& t, ...) -> decltype (auto)
190
- {
191
- return t;
192
- }
130
+ // ========================================================================
193
131
 
194
132
  /**
195
133
  * @brief Generic getter function template for value retrieval.
@@ -198,324 +136,111 @@ namespace micro_os_plus::micro_test_plus
198
136
  *
199
137
  * @param t The object or value to be accessed.
200
138
  * @return The value obtained via the relevant getter implementation.
201
- *
202
- * @details
203
- * The `get` function template invokes the appropriate getter
204
- * implementation to retrieve the value from the provided object or type.
205
- * This function ensures consistent access to values for both custom and
206
- * standard types within the framework.
207
- *
208
- * The primary implementation attempts to invoke a `get()` method if it
209
- * exists, which is recommended for user-defined types to ensure consistent
210
- * value access. If the type does not provide a `get()` method, the
211
- * fallback variadic implementation simply returns the original argument.
212
- *
213
- * The `get` function template delegates to these implementations, enabling
214
- * seamless support for a wide range of types in test expressions and
215
- * comparators.
216
- *
217
- * All definitions are intended for internal use within the framework and
218
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
219
- * maintain a structured and modular codebase.
220
139
  */
221
140
  template <class T>
222
141
  [[nodiscard]] constexpr auto
223
- get (const T& t)
224
- {
225
- // Call the variadic function, basically to force it return `t`.
226
- return get_impl<T> (t, 0);
227
- }
142
+ get (const T& t);
228
143
 
229
- // ------------------------------------------------------------------------
144
+ // ========================================================================
230
145
 
231
146
  /**
232
- * @brief Equality comparator struct template.
233
- *
234
- * @tparam Lhs_T The type of the left-hand operand.
235
- * @tparam Rhs_T The type of the right-hand operand.
147
+ * @brief Common base struct template for unary comparators.
236
148
  *
237
149
  * @details
238
- * The `eq_` struct template provides a type-safe mechanism for evaluating
239
- * equality between two operands within the framework.
240
- *
241
- * This comparator supports a variety of operand types, including those
242
- * with static values, types with precision (epsilon), and generic types.
243
- * For types with static values, the comparison is performed directly. For
244
- * types supporting precision, the comparison accounts for the smallest
245
- * epsilon to ensure accuracy, particularly for floating-point types. For
246
- * all other types, the generic getter is used to retrieve and compare the
247
- * values.
150
+ * This base struct stores a single operand and the pre-computed boolean
151
+ * result of a unary operation. Derived structs such as `not_` inherit
152
+ * from this to provide logical negation. The result is computed at
153
+ * construction time, enabling consistent handling and reporting of
154
+ * operations throughout the assertion framework.
248
155
  *
249
- * The implementation is optimised for use in embedded environments and
250
- * supports both compile-time and run-time evaluation.
251
- *
252
- * All definitions are intended for internal use within the framework and
253
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
254
- * maintain a structured and modular codebase.
156
+ * @tparam T The type of the operand.
255
157
  *
256
158
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
257
159
  */
258
- template <class Lhs_T, class Rhs_T>
259
- struct eq_ : type_traits::op
160
+ template <class T>
161
+ struct unary_op_ : type_traits::op
260
162
  {
261
163
  /**
262
- * @brief Constructs an equality comparator for the given operands.
263
- *
264
- * @param lhs The left-hand operand.
265
- * @param rhs The right-hand operand.
164
+ * @brief Constructs a unary comparator with the given operand and
165
+ * pre-computed result.
266
166
  *
267
- * @details
268
- * Evaluates the equality of the provided operands at construction,
269
- * supporting static values, types with precision, and generic types. The
270
- * result is stored in the `value_` member for efficient access.
167
+ * @param t The operand.
168
+ * @param value The pre-computed boolean result of the operation.
271
169
  */
272
- constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
273
- : lhs_{ lhs }, rhs_{ rhs }, value_{
274
- [&]
275
- {
276
- // This lambda is called in the constructor to
277
- // evaluate the comparison.
278
- using std::operator==;
279
- using std::operator<;
280
-
281
- #if defined(__GNUC__)
282
- #pragma GCC diagnostic push
283
- #pragma GCC diagnostic ignored "-Wfloat-equal"
284
- #pragma GCC diagnostic ignored "-Wconversion"
285
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
286
- #pragma GCC diagnostic ignored "-Wsign-compare"
287
- #if defined(__clang__)
288
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
289
- #pragma clang diagnostic ignored "-Wpedantic"
290
- #endif
291
- #endif
292
- if constexpr (type_traits::has_value_v<Lhs_T>
293
- and type_traits::has_value_v<Rhs_T>)
294
- {
295
- // If both types have values (like numeric constants),
296
- // compare them directly.
297
- return Lhs_T::value == Rhs_T::value;
298
- }
299
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>
300
- and type_traits::has_epsilon_v<Rhs_T>)
301
- {
302
- // If both values have precision, compare them using
303
- // the smalles precision.
304
- return math::abs (get (lhs) - get (rhs))
305
- < math::min_value (Lhs_T::epsilon,
306
- Rhs_T::epsilon);
307
- }
308
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
309
- {
310
- // If only the left operand has precision, use it.
311
- return math::abs (get (lhs) - get (rhs))
312
- < Lhs_T::epsilon;
313
- }
314
- else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
315
- {
316
- // If only the right operand has precision, use it.
317
- return math::abs (get (lhs) - get (rhs))
318
- < Rhs_T::epsilon;
319
- }
320
- else
321
- {
322
- // Call the generic getters, which might
323
- // either call the type get() or return the value.
324
- return get (lhs) == get (rhs);
325
- }
326
- #if defined(__GNUC__)
327
- #pragma GCC diagnostic pop
328
- #endif
329
- }()
330
- }
331
- {
332
- }
170
+ constexpr unary_op_ (const T& t, bool value);
333
171
 
334
172
  /**
335
173
  * @brief Conversion operator to boolean.
336
174
  *
337
175
  * @par Parameters
338
176
  * None.
339
- * @retval true The operands are considered equal.
340
- * @retval false The operands are not equal.
341
- *
342
- * @details
343
- * Returns the result of the equality comparison.
177
+ * @return The result of the operation.
344
178
  */
345
179
  [[nodiscard]] constexpr
346
- operator bool () const
347
- {
348
- return value_;
349
- }
350
-
351
- /**
352
- * @brief Retrieves the left-hand operand.
353
- *
354
- * @par Parameters
355
- * None.
356
- * @return The extracted left-hand operand.
357
- *
358
- * @details
359
- * Returns the value of the left-hand operand, applying the generic
360
- * getter to ensure correct extraction for both custom and standard
361
- * types.
362
- */
363
- [[nodiscard]] constexpr auto
364
- lhs (void) const
365
- {
366
- return get (lhs_);
367
- }
180
+ operator bool () const;
368
181
 
369
182
  /**
370
- * @brief Retrieves the right-hand operand.
183
+ * @brief Retrieves the wrapped operand expression.
371
184
  *
372
185
  * @par Parameters
373
186
  * None.
374
- * @return The extracted right-hand operand.
375
- *
376
- * @details
377
- * Returns the value of the right-hand operand, applying the generic
378
- * getter to ensure correct extraction for both custom and standard
379
- * types.
187
+ * @return The extracted operand value.
380
188
  */
381
189
  [[nodiscard]] constexpr auto
382
- rhs (void) const
383
- {
384
- return get (rhs_);
385
- }
386
-
387
- /**
388
- * @brief Stores the left-hand operand.
389
- */
390
- const Lhs_T lhs_{};
190
+ operand () const;
391
191
 
192
+ private:
392
193
  /**
393
- * @brief Stores the right-hand operand.
194
+ * @brief Stores the operand.
394
195
  */
395
- const Rhs_T rhs_{};
196
+ const T t_{};
396
197
 
397
198
  /**
398
- * @brief Stores the result of the equality comparison.
199
+ * @brief Stores the result of the operation.
399
200
  */
400
201
  const bool value_{};
401
202
  };
402
203
 
403
- // Deduction guide.
404
- template <typename Lhs_T, typename Rhs_T>
405
- eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
406
-
407
- // ------------------------------------------------------------------------
204
+ // ========================================================================
408
205
 
409
206
  /**
410
- * @brief Non-equality comparator struct template.
411
- *
412
- * @tparam Lhs_T The type of the left-hand operand.
413
- * @tparam Rhs_T The type of the right-hand operand.
207
+ * @brief Common base struct template for binary comparators.
414
208
  *
415
209
  * @details
416
- * The `ne_` struct template provides a type-safe mechanism for evaluating
417
- * non-equality between two operands within the framework.
418
- *
419
- * This comparator supports a variety of operand types, including those
420
- * with static values, types with precision (epsilon), and generic types.
421
- * For types with static values, the comparison is performed directly. For
422
- * types supporting precision, the comparison accounts for the smallest
423
- * epsilon to ensure accuracy, particularly for floating-point types. For
424
- * all other types, the generic getter is used to retrieve and compare the
425
- * values.
210
+ * This base struct stores two operands (left-hand and right-hand) along
211
+ * with the pre-computed boolean result of a binary comparison. Derived
212
+ * structs such as `eq_`, `lt_`, and others inherit from this to provide
213
+ * relational and logical operations. The comparison result is computed at
214
+ * construction time and cached, enabling efficient reporting and
215
+ * composition of complex assertions without repeated computation.
426
216
  *
427
- * The implementation is optimised for use in embedded environments and
428
- * supports both compile-time and run-time evaluation.
429
- *
430
- * All definitions are intended for internal use within the framework and
431
- * are implemented in the `include/micro-os-plus` folder to maintain a
432
- * structured and modular codebase.
217
+ * @tparam Lhs_T The type of the left-hand operand.
218
+ * @tparam Rhs_T The type of the right-hand operand.
433
219
  *
434
220
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
435
221
  */
436
222
  template <class Lhs_T, class Rhs_T>
437
- struct ne_ : type_traits::op
223
+ struct binary_op_ : type_traits::op
438
224
  {
439
225
  /**
440
- * @brief Constructs a non-equality comparator for the given operands.
226
+ * @brief Constructs a binary comparator with the given operands and
227
+ * pre-computed result.
441
228
  *
442
229
  * @param lhs The left-hand operand.
443
230
  * @param rhs The right-hand operand.
444
- *
445
- * @details
446
- * Evaluates the non-equality of the provided operands at construction,
447
- * supporting static values, types with precision, and generic types. The
448
- * result is stored in the `value_` member for efficient access.
231
+ * @param value The pre-computed boolean result of the comparison.
449
232
  */
450
- constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
451
- : lhs_{ lhs }, rhs_{ rhs }, value_{
452
- [&]
453
- {
454
- using std::operator==;
455
- using std::operator!=;
456
- using std::operator>;
457
-
458
- #if defined(__GNUC__)
459
- #pragma GCC diagnostic push
460
- #pragma GCC diagnostic ignored "-Wfloat-equal"
461
- #pragma GCC diagnostic ignored "-Wconversion"
462
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
463
- #pragma GCC diagnostic ignored "-Wsign-compare"
464
- #if defined(__clang__)
465
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
466
- #pragma clang diagnostic ignored "-Wpedantic"
467
- #endif
468
- #endif
469
- if constexpr (type_traits::has_value_v<Lhs_T>
470
- and type_traits::has_value_v<Rhs_T>)
471
- {
472
- return Lhs_T::value != Rhs_T::value;
473
- }
474
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>
475
- and type_traits::has_epsilon_v<Rhs_T>)
476
- {
477
- return math::abs (get (lhs_) - get (rhs_))
478
- > math::min_value (Lhs_T::epsilon,
479
- Rhs_T::epsilon);
480
- }
481
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
482
- {
483
- return math::abs (get (lhs_) - get (rhs_))
484
- > Lhs_T::epsilon;
485
- }
486
- else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
487
- {
488
- return math::abs (get (lhs_) - get (rhs_))
489
- > Rhs_T::epsilon;
490
- }
491
- else
492
- {
493
- return get (lhs_) != get (rhs_);
494
- }
495
- #if defined(__GNUC__)
496
- #pragma GCC diagnostic pop
497
- #endif
498
- }()
499
- }
500
- {
501
- }
233
+ constexpr binary_op_ (const Lhs_T& lhs, const Rhs_T& rhs, bool value);
502
234
 
503
235
  /**
504
236
  * @brief Conversion operator to boolean.
505
237
  *
506
238
  * @par Parameters
507
239
  * None.
508
- * @retval true The operands are considered not equal.
509
- * @retval false The operands are considered equal.
510
- *
511
- * @details
512
- * Returns the result of the non-equality comparison.
240
+ * @return The result of the comparison.
513
241
  */
514
242
  [[nodiscard]] constexpr
515
- operator bool () const
516
- {
517
- return value_;
518
- }
243
+ operator bool () const;
519
244
 
520
245
  /**
521
246
  * @brief Retrieves the left-hand operand.
@@ -523,17 +248,9 @@ namespace micro_os_plus::micro_test_plus
523
248
  * @par Parameters
524
249
  * None.
525
250
  * @return The extracted left-hand operand.
526
- *
527
- * @details
528
- * Returns the value of the left-hand operand, applying the generic
529
- * getter to ensure correct extraction for both custom and standard
530
- * types.
531
251
  */
532
252
  [[nodiscard]] constexpr auto
533
- lhs (void) const
534
- {
535
- return get (lhs_);
536
- }
253
+ lhs (void) const;
537
254
 
538
255
  /**
539
256
  * @brief Retrieves the right-hand operand.
@@ -541,214 +258,148 @@ namespace micro_os_plus::micro_test_plus
541
258
  * @par Parameters
542
259
  * None.
543
260
  * @return The extracted right-hand operand.
544
- *
545
- * @details
546
- * Returns the value of the right-hand operand, applying the generic
547
- * getter to ensure correct extraction for both custom and standard
548
- * types.
549
261
  */
550
262
  [[nodiscard]] constexpr auto
551
- rhs (void) const
552
- {
553
- return get (rhs_);
554
- }
263
+ rhs (void) const;
555
264
 
265
+ private:
556
266
  /**
557
267
  * @brief Stores the left-hand operand.
268
+ *
269
+ * @note Operands are stored by value; passing a large container
270
+ * will copy it into this member.
558
271
  */
559
272
  const Lhs_T lhs_{};
560
273
 
561
274
  /**
562
275
  * @brief Stores the right-hand operand.
276
+ *
277
+ * @note Operands are stored by value; passing a large container
278
+ * will copy it into this member.
563
279
  */
564
280
  const Rhs_T rhs_{};
565
281
 
566
282
  /**
567
- * @brief Stores the result of the non-equality comparison.
283
+ * @brief Stores the result of the comparison.
568
284
  */
569
285
  const bool value_{};
570
286
  };
571
287
 
572
- // Deduction guide.
573
- template <typename Lhs_T, typename Rhs_T>
574
- ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
575
-
576
- // ------------------------------------------------------------------------
288
+ // ========================================================================
577
289
 
578
290
  /**
579
- * @brief Greater than comparator struct template.
580
- *
581
- * @tparam Lhs_T The type of the left-hand operand.
582
- * @tparam Rhs_T The type of the right-hand operand.
291
+ * @brief Equality comparator struct template.
583
292
  *
584
293
  * @details
585
- * The `gt_` struct template provides a type-safe mechanism for evaluating
586
- * whether the left-hand operand is greater than the right-hand operand
587
- * within the framework.
588
- *
589
- * This comparator supports a variety of operand types, including those
590
- * with static values and generic types. For types with static values, the
591
- * comparison is performed directly. For all other types, the generic
592
- * getter is used to retrieve and compare the values.
593
- *
594
- * The implementation is optimised for use in embedded environments and
595
- * supports both compile-time and run-time evaluation.
294
+ * Derived from `binary_op_`, this struct checks whether the left-hand
295
+ * operand is equal to the right-hand operand. It is used within test
296
+ * expressions to provide human-readable equality assertions with
297
+ * enhanced reporting of the actual and expected values upon failure.
596
298
  *
597
- * All definitions are intended for internal use within the framework and
598
- * are implemented in the `include/micro-os-plus` folder to maintain a
599
- * structured and modular codebase.
299
+ * @tparam Lhs_T The type of the left-hand operand.
300
+ * @tparam Rhs_T The type of the right-hand operand.
600
301
  *
601
302
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
602
303
  */
603
304
  template <class Lhs_T, class Rhs_T>
604
- struct gt_ : type_traits::op
305
+ struct eq_ : binary_op_<Lhs_T, Rhs_T>
605
306
  {
606
307
  /**
607
- * @brief Constructs a greater than comparator for the given operands.
308
+ * @brief Constructs an equality comparator for the given operands.
608
309
  *
609
310
  * @param lhs The left-hand operand.
610
311
  * @param rhs The right-hand operand.
611
- *
612
- * @details
613
- * Evaluates whether the left-hand operand is greater than the right-hand
614
- * operand at construction, supporting static values and generic types.
615
- * The result is stored in the `value_` member for efficient access.
616
312
  */
617
- constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
618
- : lhs_{ lhs }, rhs_{ rhs },
619
- value_{ [&]
620
- {
621
- using std::operator>;
622
-
623
- #if defined(__GNUC__)
624
- #pragma GCC diagnostic push
625
- #pragma GCC diagnostic ignored "-Wconversion"
626
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
627
- #pragma GCC diagnostic ignored "-Wsign-compare"
628
- #if defined(__clang__)
629
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
630
- #pragma clang diagnostic ignored "-Wpedantic"
631
- #endif
632
- #endif
633
- if constexpr (type_traits::has_value_v<Lhs_T>
634
- and type_traits::has_value_v<Rhs_T>)
635
- {
636
- return Lhs_T::value > Rhs_T::value;
637
- }
638
- else
639
- {
640
- return get (lhs_) > get (rhs_);
641
- }
642
- #if defined(__GNUC__)
643
- #pragma GCC diagnostic pop
644
- #endif
645
- }() }
646
- {
647
- }
313
+ constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
314
+ };
648
315
 
649
- /**
650
- * @brief Conversion operator to boolean.
651
- *
652
- * @par Parameters
653
- * None.
654
- * @retval true The left-hand operand is greater than the right-hand
655
- * operand.
656
- * @retval false Otherwise.
657
- *
658
- * @details
659
- * Returns the result of the greater than comparison.
660
- */
661
- [[nodiscard]] constexpr
662
- operator bool () const
663
- {
664
- return value_;
665
- }
316
+ // Deduction guide.
317
+ template <typename Lhs_T, typename Rhs_T>
318
+ eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
666
319
 
667
- /**
668
- * @brief Retrieves the left-hand operand.
669
- *
670
- * @par Parameters
671
- * None.
672
- * @return The extracted left-hand operand.
673
- *
674
- * @details
675
- * Returns the value of the left-hand operand, applying the generic
676
- * getter to ensure correct extraction for both custom and standard
677
- * types.
678
- */
679
- [[nodiscard]] constexpr auto
680
- lhs (void) const
681
- {
682
- return get (lhs_);
683
- }
684
- [[nodiscard]] constexpr auto
320
+ // ========================================================================
685
321
 
322
+ /**
323
+ * @brief Non-equality comparator struct template.
324
+ *
325
+ * @details
326
+ * Derived from `binary_op_`, this struct checks whether the left-hand
327
+ * operand is not equal to the right-hand operand. It is used within test
328
+ * expressions to provide human-readable inequality assertions with
329
+ * enhanced reporting of the actual and expected values upon failure.
330
+ *
331
+ * @tparam Lhs_T The type of the left-hand operand.
332
+ * @tparam Rhs_T The type of the right-hand operand.
333
+ *
334
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
335
+ */
336
+ template <class Lhs_T, class Rhs_T>
337
+ struct ne_ : binary_op_<Lhs_T, Rhs_T>
338
+ {
686
339
  /**
687
- * @brief Retrieves the right-hand operand.
688
- *
689
- * @par Parameters
690
- * None.
691
- * @return The extracted right-hand operand.
340
+ * @brief Constructs a non-equality comparator for the given operands.
692
341
  *
693
- * @details
694
- * Returns the value of the right-hand operand, applying the generic
695
- * getter to ensure correct extraction for both custom and standard
696
- * types.
342
+ * @param lhs The left-hand operand.
343
+ * @param rhs The right-hand operand.
697
344
  */
698
- rhs (void) const
699
- {
700
- return get (rhs_);
701
- }
345
+ constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
346
+ };
702
347
 
703
- /**
704
- * @brief Stores the left-hand operand.
705
- */
706
- const Lhs_T lhs_{};
348
+ // Deduction guide.
349
+ template <typename Lhs_T, typename Rhs_T>
350
+ ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
707
351
 
708
- /**
709
- * @brief Stores the right-hand operand.
710
- */
711
- const Rhs_T rhs_{};
352
+ // ========================================================================
712
353
 
354
+ /**
355
+ * @brief Greater than comparator struct template.
356
+ *
357
+ * @details
358
+ * Derived from `binary_op_`, this struct checks whether the left-hand
359
+ * operand is greater than the right-hand operand. It is used within test
360
+ * expressions to provide human-readable relational assertions with
361
+ * enhanced reporting of the actual and expected values upon failure.
362
+ *
363
+ * @tparam Lhs_T The type of the left-hand operand.
364
+ * @tparam Rhs_T The type of the right-hand operand.
365
+ *
366
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
367
+ */
368
+ template <class Lhs_T, class Rhs_T>
369
+ struct gt_ : binary_op_<Lhs_T, Rhs_T>
370
+ {
713
371
  /**
714
- * @brief Stores the result of the greater than comparison.
372
+ * @brief Constructs a greater than comparator for the given operands.
373
+ *
374
+ * @param lhs The left-hand operand.
375
+ * @param rhs The right-hand operand.
715
376
  */
716
- const bool value_{};
377
+ constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
717
378
  };
718
379
 
719
380
  // Deduction guide.
720
381
  template <typename Lhs_T, typename Rhs_T>
721
382
  gt_ (const Lhs_T&, const Rhs_T&) -> gt_<Lhs_T, Rhs_T>;
722
383
 
723
- // ------------------------------------------------------------------------
384
+ // ========================================================================
724
385
 
725
386
  /**
726
387
  * @brief Greater than or equal comparator struct template.
727
388
  *
728
- * @tparam Lhs_T The type of the left-hand operand.
729
- * @tparam Rhs_T The type of the right-hand operand.
730
- *
731
389
  * @details
732
- * The `ge_` struct template provides a type-safe mechanism for evaluating
733
- * whether the left-hand operand is greater than or equal to the right-hand
734
- * operand within the framework.
735
- *
736
- * This comparator supports a variety of operand types, including those
737
- * with static values and generic types. For types with static values, the
738
- * comparison is performed directly. For all other types, the generic
739
- * getter is used to retrieve and compare the values.
390
+ * Derived from `binary_op_`, this struct checks whether the left-hand
391
+ * operand is greater than or equal to the right-hand operand. It is used
392
+ * within test expressions to provide human-readable relational
393
+ * assertions with enhanced reporting of the actual and expected values
394
+ * upon failure.
740
395
  *
741
- * The implementation is optimised for use in embedded environments and
742
- * supports both compile-time and run-time evaluation.
743
- *
744
- * All definitions are intended for internal use within the framework and
745
- * are implemented in the `include/micro-os-plus` folder to maintain a
746
- * structured and modular codebase.
396
+ * @tparam Lhs_T The type of the left-hand operand.
397
+ * @tparam Rhs_T The type of the right-hand operand.
747
398
  *
748
399
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
749
400
  */
750
401
  template <class Lhs_T, class Rhs_T>
751
- struct ge_ : type_traits::op
402
+ struct ge_ : binary_op_<Lhs_T, Rhs_T>
752
403
  {
753
404
  /**
754
405
  * @brief Constructs a greater than or equal comparator for the given
@@ -756,296 +407,65 @@ namespace micro_os_plus::micro_test_plus
756
407
  *
757
408
  * @param lhs The left-hand operand.
758
409
  * @param rhs The right-hand operand.
759
- *
760
- * @details
761
- * Evaluates whether the left-hand operand is greater than or equal to
762
- * the right-hand operand at construction, supporting static values and
763
- * generic types. The result is stored in the `value_` member for
764
- * efficient access.
765
410
  */
766
- constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
767
- : lhs_{ lhs }, rhs_{ rhs },
768
- value_{ [&]
769
- {
770
- using std::operator>=;
411
+ constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
412
+ };
771
413
 
772
- #if defined(__GNUC__)
773
- #pragma GCC diagnostic push
774
- #pragma GCC diagnostic ignored "-Wconversion"
775
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
776
- #pragma GCC diagnostic ignored "-Wsign-compare"
777
- #if defined(__clang__)
778
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
779
- #pragma clang diagnostic ignored "-Wpedantic"
780
- #endif
781
- #endif
782
- if constexpr (type_traits::has_value_v<Lhs_T>
783
- and type_traits::has_value_v<Rhs_T>)
784
- {
785
- return Lhs_T::value >= Rhs_T::value;
786
- }
787
- else
788
- {
789
- return get (lhs_) >= get (rhs_);
790
- }
791
- #if defined(__GNUC__)
792
- #pragma GCC diagnostic pop
793
- #endif
794
- }() }
795
- {
796
- }
414
+ // Deduction guide.
415
+ template <typename Lhs_T, typename Rhs_T>
416
+ ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
797
417
 
798
- /**
799
- * @brief Conversion operator to boolean.
800
- *
801
- * @par Parameters
802
- * None.
803
- * @retval true The left-hand operand is greater than or equal to the
804
- * right-hand operand.
805
- * @retval false Otherwise.
806
- *
807
- * @details
808
- * Returns the result of the greater than or equal comparison.
809
- */
810
- [[nodiscard]] constexpr
811
- operator bool () const
812
- {
813
- return value_;
814
- }
815
-
816
- /**
817
- * @brief Retrieves the left-hand operand.
818
- *
819
- * @par Parameters
820
- * None.
821
- * @return The extracted left-hand operand.
822
- *
823
- * @details
824
- * Returns the value of the left-hand operand, applying the generic
825
- * getter to ensure correct extraction for both custom and standard
826
- * types.
827
- */
828
- [[nodiscard]] constexpr auto
829
- lhs (void) const
830
- {
831
- return get (lhs_);
832
- }
833
-
834
- /**
835
- * @brief Retrieves the right-hand operand.
836
- *
837
- * @par Parameters
838
- * None.
839
- * @return The extracted right-hand operand.
840
- *
841
- * @details
842
- * Returns the value of the right-hand operand, applying the generic
843
- * getter to ensure correct extraction for both custom and standard
844
- * types.
845
- */
846
- [[nodiscard]] constexpr auto
847
- rhs (void) const
848
- {
849
- return get (rhs_);
850
- }
851
-
852
- /**
853
- * @brief Stores the left-hand operand.
854
- */
855
- const Lhs_T lhs_{};
856
-
857
- /**
858
- * @brief Stores the right-hand operand.
859
- */
860
- const Rhs_T rhs_{};
861
-
862
- /**
863
- * @brief Stores the result of the greater than or equal comparison.
864
- */
865
- const bool value_{};
866
- };
867
-
868
- // Deduction guide.
869
- template <typename Lhs_T, typename Rhs_T>
870
- ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
871
-
872
- // ------------------------------------------------------------------------
418
+ // ========================================================================
873
419
 
874
420
  /**
875
421
  * @brief Less than comparator struct template.
876
422
  *
877
- * @tparam Lhs_T The type of the left-hand operand.
878
- * @tparam Rhs_T The type of the right-hand operand.
879
- *
880
423
  * @details
881
- * The `lt_` struct template provides a type-safe mechanism for evaluating
882
- * whether the left-hand operand is less than the right-hand operand within
883
- * the framework.
424
+ * Derived from `binary_op_`, this struct checks whether the left-hand
425
+ * operand is less than the right-hand operand. It is used within test
426
+ * expressions to provide human-readable relational assertions with
427
+ * enhanced reporting of the actual and expected values upon failure.
884
428
  *
885
- * This comparator supports a variety of operand types, including those
886
- * with static values and generic types. For types with static values, the
887
- * comparison is performed directly. For all other types, the generic
888
- * getter is used to retrieve and compare the values.
889
- *
890
- * The implementation is optimised for use in embedded environments and
891
- * supports both compile-time and run-time evaluation.
892
- *
893
- * All definitions are intended for internal use within the framework and
894
- * are implemented in the `include/micro-os-plus` folder to maintain a
895
- * structured and modular codebase.
429
+ * @tparam Lhs_T The type of the left-hand operand.
430
+ * @tparam Rhs_T The type of the right-hand operand.
896
431
  *
897
432
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
898
433
  */
899
434
  template <class Lhs_T, class Rhs_T>
900
- struct lt_ : type_traits::op
435
+ struct lt_ : binary_op_<Lhs_T, Rhs_T>
901
436
  {
902
437
  /**
903
438
  * @brief Constructs a less than comparator for the given operands.
904
439
  *
905
440
  * @param lhs The left-hand operand.
906
441
  * @param rhs The right-hand operand.
907
- *
908
- * @details
909
- * Evaluates whether the left-hand operand is less than the right-hand
910
- * operand at construction, supporting static values and generic types.
911
- * The result is stored in the `value_` member for efficient access.
912
- */
913
- constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
914
- : lhs_{ lhs }, rhs_{ rhs },
915
- value_{ [&]
916
- {
917
- using std::operator<;
918
-
919
- #if defined(__GNUC__)
920
- #pragma GCC diagnostic push
921
- #pragma GCC diagnostic ignored "-Wconversion"
922
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
923
- #pragma GCC diagnostic ignored "-Wsign-compare"
924
- #if defined(__clang__)
925
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
926
- #pragma clang diagnostic ignored "-Wpedantic"
927
- #endif
928
- #endif
929
- if constexpr (type_traits::has_value_v<Lhs_T>
930
- and type_traits::has_value_v<Rhs_T>)
931
- {
932
- return Lhs_T::value < Rhs_T::value;
933
- }
934
- else
935
- {
936
- return get (lhs_) < get (rhs_);
937
- }
938
- #if defined(__GNUC__)
939
- #pragma GCC diagnostic pop
940
- #endif
941
- }() }
942
- {
943
- }
944
-
945
- /**
946
- * @brief Conversion operator to boolean.
947
- *
948
- * @par Parameters
949
- * None.
950
- * @retval true The left-hand operand is less than the right-hand
951
- * operand.
952
- * @retval false Otherwise.
953
- *
954
- * @details
955
- * Returns the result of the less than comparison.
956
- */
957
- [[nodiscard]] constexpr
958
- operator bool () const
959
- {
960
- return value_;
961
- }
962
-
963
- /**
964
- * @brief Retrieves the left-hand operand.
965
- *
966
- * @par Parameters
967
- * None.
968
- * @return The extracted left-hand operand.
969
- *
970
- * @details
971
- * Returns the value of the left-hand operand, applying the generic
972
- * getter to ensure correct extraction for both custom and standard
973
- * types.
974
- */
975
- [[nodiscard]] constexpr auto
976
- lhs (void) const
977
- {
978
- return get (lhs_);
979
- }
980
-
981
- /**
982
- * @brief Retrieves the right-hand operand.
983
- *
984
- * @par Parameters
985
- * None.
986
- * @return The extracted right-hand operand.
987
- *
988
- * @details
989
- * Returns the value of the right-hand operand, applying the generic
990
- * getter to ensure correct extraction for both custom and standard
991
- * types.
992
- */
993
- [[nodiscard]] constexpr auto
994
- rhs (void) const
995
- {
996
- return get (rhs_);
997
- }
998
-
999
- private:
1000
- /**
1001
- * @brief Stores the left-hand operand.
1002
- */
1003
- const Lhs_T lhs_{};
1004
-
1005
- /**
1006
- * @brief Stores the right-hand operand.
1007
- */
1008
- const Rhs_T rhs_{};
1009
-
1010
- /**
1011
- * @brief Stores the result of the less than comparison.
1012
442
  */
1013
- const bool value_{};
443
+ constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
1014
444
  };
1015
445
 
1016
446
  // Deduction guide.
1017
447
  template <typename Lhs_T, typename Rhs_T>
1018
448
  lt_ (const Lhs_T&, const Rhs_T&) -> lt_<Lhs_T, Rhs_T>;
1019
449
 
1020
- // ------------------------------------------------------------------------
450
+ // ========================================================================
1021
451
 
1022
452
  /**
1023
453
  * @brief Less than or equal comparator struct template.
1024
454
  *
1025
- * @tparam Lhs_T The type of the left-hand operand.
1026
- * @tparam Rhs_T The type of the right-hand operand.
1027
- *
1028
455
  * @details
1029
- * The `le_` struct template provides a type-safe mechanism for evaluating
1030
- * whether the left-hand operand is less than or equal to the right-hand
1031
- * operand within the framework.
1032
- *
1033
- * This comparator supports a variety of operand types, including those
1034
- * with static values and generic types. For types with static values, the
1035
- * comparison is performed directly. For all other types, the generic
1036
- * getter is used to retrieve and compare the values.
1037
- *
1038
- * The implementation is optimised for use in embedded environments and
1039
- * supports both compile-time and run-time evaluation.
456
+ * Derived from `binary_op_`, this struct checks whether the left-hand
457
+ * operand is less than or equal to the right-hand operand. It is used
458
+ * within test expressions to provide human-readable relational
459
+ * assertions with enhanced reporting of the actual and expected values
460
+ * upon failure.
1040
461
  *
1041
- * All definitions are intended for internal use within the framework and
1042
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1043
- * maintain a structured and modular codebase.
462
+ * @tparam Lhs_T The type of the left-hand operand.
463
+ * @tparam Rhs_T The type of the right-hand operand.
1044
464
  *
1045
465
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1046
466
  */
1047
467
  template <class Lhs_T, class Rhs_T>
1048
- struct le_ : type_traits::op
468
+ struct le_ : binary_op_<Lhs_T, Rhs_T>
1049
469
  {
1050
470
  /**
1051
471
  * @brief Constructs a less than or equal comparator for the given
@@ -1053,839 +473,261 @@ namespace micro_os_plus::micro_test_plus
1053
473
  *
1054
474
  * @param lhs The left-hand operand.
1055
475
  * @param rhs The right-hand operand.
1056
- *
1057
- * @details
1058
- * Evaluates whether the left-hand operand is less than or equal to the
1059
- * right-hand operand at construction, supporting static values and
1060
- * generic types. The result is stored in the `value_` member for
1061
- * efficient access.
1062
476
  */
1063
- constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
1064
- : lhs_{ lhs }, rhs_{ rhs },
1065
- value_{ [&]
1066
- {
1067
- using std::operator<=;
1068
-
1069
- #if defined(__GNUC__)
1070
- #pragma GCC diagnostic push
1071
- #pragma GCC diagnostic ignored "-Wconversion"
1072
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
1073
- #pragma GCC diagnostic ignored "-Wsign-compare"
1074
- #if defined(__clang__)
1075
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
1076
- #pragma clang diagnostic ignored "-Wpedantic"
1077
- #endif
1078
- #endif
1079
- if constexpr (type_traits::has_value_v<Lhs_T>
1080
- and type_traits::has_value_v<Rhs_T>)
1081
- {
1082
- return Lhs_T::value <= Rhs_T::value;
1083
- }
1084
- else
1085
- {
1086
- return get (lhs_) <= get (rhs_);
1087
- }
1088
- #if defined(__GNUC__)
1089
- #pragma GCC diagnostic pop
1090
- #endif
1091
- }() }
1092
- {
1093
- }
1094
-
1095
- /**
1096
- * @brief Conversion operator to boolean.
1097
- *
1098
- * @par Parameters
1099
- * None.
1100
- * @retval true The left-hand operand is less than or equal to the
1101
- * right-hand operand.
1102
- * @retval false Otherwise.
1103
- *
1104
- * @details
1105
- * Returns the result of the less than or equal comparison.
1106
- */
1107
- [[nodiscard]] constexpr
1108
- operator bool () const
1109
- {
1110
- return value_;
1111
- }
1112
-
1113
- /**
1114
- * @brief Retrieves the left-hand operand.
1115
- *
1116
- * @par Parameters
1117
- * None.
1118
- * @return The extracted left-hand operand.
1119
- *
1120
- * @details
1121
- * Returns the value of the left-hand operand, applying the generic
1122
- * getter to ensure correct extraction for both custom and standard
1123
- * types.
1124
- */
1125
-
1126
- [[nodiscard]] constexpr auto
1127
- lhs (void) const
1128
- {
1129
- return get (lhs_);
1130
- }
1131
-
1132
- /**
1133
- * @brief Retrieves the right-hand operand.
1134
- *
1135
- * @par Parameters
1136
- * None.
1137
- * @return The extracted right-hand operand.
1138
- *
1139
- * @details
1140
- * Returns the value of the right-hand operand, applying the generic
1141
- * getter to ensure correct extraction for both custom and standard
1142
- * types.
1143
- */
1144
- [[nodiscard]] constexpr auto
1145
- rhs (void) const
1146
- {
1147
- return get (rhs_);
1148
- }
1149
-
1150
- /**
1151
- * @brief Stores the left-hand operand.
1152
- */
1153
- const Lhs_T lhs_{};
1154
-
1155
- /**
1156
- * @brief Stores the right-hand operand.
1157
- */
1158
- const Rhs_T rhs_{};
1159
-
1160
- /**
1161
- * @brief Stores the result of the less than or equal comparison.
1162
- */
1163
- const bool value_{};
477
+ constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
1164
478
  };
1165
479
 
1166
480
  // Deduction guide.
1167
481
  template <typename Lhs_T, typename Rhs_T>
1168
482
  le_ (const Lhs_T&, const Rhs_T&) -> le_<Lhs_T, Rhs_T>;
1169
483
 
1170
- // ------------------------------------------------------------------------
484
+ // ========================================================================
1171
485
 
1172
486
  /**
1173
487
  * @brief Logical AND comparator struct template.
1174
488
  *
1175
- * @tparam Lhs_T The type of the left-hand operand.
1176
- * @tparam Rhs_T The type of the right-hand operand.
1177
- *
1178
489
  * @details
1179
- * The `and_` struct template provides a type-safe mechanism for evaluating
1180
- * the logical conjunction (AND) of two operands within the framework.
490
+ * Derived from `binary_op_`, this struct combines two sub-expressions
491
+ * with a logical AND operation. It enables composition of complex
492
+ * assertions by combining multiple conditions into a single logical
493
+ * whole, with reporting that shows the combined result and individual
494
+ * operand outcomes.
1181
495
  *
1182
- * This comparator supports a wide range of operand types, applying the
1183
- * generic getter to ensure correct value extraction for both custom and
1184
- * standard types. The result of the logical AND operation is stored in the
1185
- * `value_` member for efficient access.
1186
- *
1187
- * The implementation is optimised for use in embedded environments and
1188
- * supports both compile-time and run-time evaluation.
1189
- *
1190
- * All definitions are intended for internal use within the framework and
1191
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1192
- * maintain a structured and modular codebase.
496
+ * @tparam Lhs_T The type of the left-hand operand.
497
+ * @tparam Rhs_T The type of the right-hand operand.
1193
498
  *
1194
499
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1195
500
  */
1196
501
  template <class Lhs_T, class Rhs_T>
1197
- struct and_ : type_traits::op
502
+ struct and_ : binary_op_<Lhs_T, Rhs_T>
1198
503
  {
1199
504
  /**
1200
505
  * @brief Constructs a logical AND comparator for the given operands.
1201
506
  *
1202
507
  * @param lhs The left-hand operand.
1203
508
  * @param rhs The right-hand operand.
1204
- *
1205
- * @details
1206
- * Evaluates the logical conjunction of the provided operands at
1207
- * construction, supporting both custom and standard types. The result is
1208
- * stored in the `value_` member for efficient access.
1209
- */
1210
- constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
1211
- : lhs_{ lhs }, rhs_{ rhs },
1212
- value_{ static_cast<bool> (lhs) and static_cast<bool> (rhs) }
1213
- {
1214
- }
1215
-
1216
- /**
1217
- * @brief Conversion operator to boolean.
1218
- *
1219
- * @par Parameters
1220
- * None.
1221
- * @retval true Both operands evaluate to true.
1222
- * @retval false At least one operand evaluates to false.
1223
- *
1224
- * @details
1225
- * Returns the result of the logical AND operation.
1226
509
  */
1227
- [[nodiscard]] constexpr
1228
- operator bool () const
1229
- {
1230
- return value_;
1231
- }
1232
-
1233
- /**
1234
- * @brief Retrieves the left-hand operand.
1235
- *
1236
- * @par Parameters
1237
- * None.
1238
- * @return The extracted left-hand operand.
1239
- *
1240
- * @details
1241
- * Returns the value of the left-hand operand, applying the generic
1242
- * getter to ensure correct extraction for both custom and standard
1243
- * types.
1244
- */
1245
- [[nodiscard]] constexpr auto
1246
- lhs (void) const
1247
- {
1248
- return get (lhs_);
1249
- }
1250
-
1251
- /**
1252
- * @brief Retrieves the right-hand operand.
1253
- *
1254
- * @par Parameters
1255
- * None.
1256
- * @return The extracted right-hand operand.
1257
- *
1258
- * @details
1259
- * Returns the value of the right-hand operand, applying the generic
1260
- * getter to ensure correct extraction for both custom and standard
1261
- * types.
1262
- */
1263
- [[nodiscard]] constexpr auto
1264
- rhs (void) const
1265
- {
1266
- return get (rhs_);
1267
- }
1268
-
1269
- /**
1270
- * @brief Stores the left-hand operand.
1271
- */
1272
- const Lhs_T lhs_{};
1273
-
1274
- /**
1275
- * @brief Stores the right-hand operand.
1276
- */
1277
- const Rhs_T rhs_{};
1278
-
1279
- /**
1280
- * @brief Stores the result of the logical AND operation.
1281
- */
1282
- const bool value_{};
510
+ constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
1283
511
  };
1284
512
 
1285
513
  // Deduction guide.
1286
514
  template <typename Lhs_T, typename Rhs_T>
1287
515
  and_ (const Lhs_T&, const Rhs_T&) -> and_<Lhs_T, Rhs_T>;
1288
516
 
1289
- // ------------------------------------------------------------------------
517
+ // ========================================================================
1290
518
 
1291
519
  /**
1292
520
  * @brief Logical OR comparator struct template.
1293
521
  *
1294
- * @tparam Lhs_T The type of the left-hand operand.
1295
- * @tparam Rhs_T The type of the right-hand operand.
1296
- *
1297
522
  * @details
1298
- * The `or_` struct template provides a type-safe mechanism for evaluating
1299
- * the logical disjunction (OR) of two operands within the framework.
1300
- *
1301
- * This comparator supports a wide range of operand types, applying the
1302
- * generic getter to ensure correct value extraction for both custom and
1303
- * standard types. The result of the logical OR operation is stored in the
1304
- * `value_` member for efficient access.
523
+ * Derived from `binary_op_`, this struct combines two sub-expressions
524
+ * with a logical OR operation. It enables composition of complex
525
+ * assertions by combining multiple conditions into a single logical
526
+ * whole, with reporting that shows the combined result and individual
527
+ * operand outcomes.
1305
528
  *
1306
- * The implementation is optimised for use in embedded environments and
1307
- * supports both compile-time and run-time evaluation.
1308
- *
1309
- * All definitions are intended for internal use within the framework and
1310
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1311
- * maintain a structured and modular codebase.
529
+ * @tparam Lhs_T The type of the left-hand operand.
530
+ * @tparam Rhs_T The type of the right-hand operand.
1312
531
  *
1313
532
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1314
533
  */
1315
534
  template <class Lhs_T, class Rhs_T>
1316
- struct or_ : type_traits::op
535
+ struct or_ : binary_op_<Lhs_T, Rhs_T>
1317
536
  {
1318
537
  /**
1319
538
  * @brief Constructs a logical OR comparator for the given operands.
1320
539
  *
1321
- * @details
1322
- * Evaluates the logical disjunction of the provided operands at
1323
- * construction, supporting both custom and standard types. The result is
1324
- * stored in the `value_` member for efficient access.
1325
- *
1326
540
  * @param lhs The left-hand operand.
1327
541
  * @param rhs The right-hand operand.
1328
542
  */
1329
- constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
1330
- : lhs_{ lhs }, rhs_{ rhs },
1331
- value_{ static_cast<bool> (lhs) or static_cast<bool> (rhs) }
1332
- {
1333
- }
1334
-
1335
- /**
1336
- * @brief Conversion operator to boolean.
1337
- *
1338
- * @par Parameters
1339
- * None.
1340
- * @retval true At least one operand evaluates to true.
1341
- * @retval false Both operands evaluate to false.
1342
- *
1343
- * @details
1344
- * Returns the result of the logical OR operation.
1345
- */
1346
- [[nodiscard]] constexpr
1347
- operator bool () const
1348
- {
1349
- return value_;
1350
- }
1351
-
1352
- /**
1353
- * @brief Retrieves the left-hand operand.
1354
- *
1355
- * @par Parameters
1356
- * None.
1357
- * @return The extracted left-hand operand.
1358
- *
1359
- * @details
1360
- * Returns the value of the left-hand operand, applying the generic
1361
- * getter to ensure correct extraction for both custom and standard
1362
- * types.
1363
- */
1364
- [[nodiscard]] constexpr auto
1365
- lhs (void) const
1366
- {
1367
- return get (lhs_);
1368
- }
1369
-
1370
- /**
1371
- * @brief Retrieves the right-hand operand.
1372
- *
1373
- * @par Parameters
1374
- * None.
1375
- * @return The extracted right-hand operand.
1376
- *
1377
- * @details
1378
- * Returns the value of the right-hand operand, applying the generic
1379
- * getter to ensure correct extraction for both custom and standard
1380
- * types.
1381
- */
1382
- [[nodiscard]] constexpr auto
1383
- rhs (void) const
1384
- {
1385
- return get (rhs_);
1386
- }
1387
-
1388
- /**
1389
- * @brief Stores the left-hand operand.
1390
- */
1391
- const Lhs_T lhs_{};
1392
-
1393
- /**
1394
- * @brief Stores the right-hand operand.
1395
- */
1396
- const Rhs_T rhs_{};
1397
-
1398
- /**
1399
- * @brief Stores the result of the logical OR operation.
1400
- */
1401
- const bool value_{};
543
+ constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
1402
544
  };
1403
545
 
1404
546
  // Deduction guide.
1405
547
  template <typename Lhs_T, typename Rhs_T>
1406
548
  or_ (const Lhs_T&, const Rhs_T&) -> or_<Lhs_T, Rhs_T>;
1407
549
 
1408
- // ------------------------------------------------------------------------
550
+ // ========================================================================
1409
551
 
1410
552
  /**
1411
553
  * @brief Logical NOT comparator struct template.
1412
554
  *
1413
- * @tparam T The type of the operand.
1414
- *
1415
555
  * @details
1416
- * The `not_` struct template provides a type-safe mechanism for evaluating
1417
- * the logical negation (NOT) of an operand within the framework.
1418
- *
1419
- * This comparator supports a wide range of operand types, applying the
1420
- * generic getter to ensure correct value extraction for both custom and
1421
- * standard types. The result of the logical NOT operation is stored in the
1422
- * `value_` member for efficient access.
556
+ * Derived from `unary_op_`, this struct negates a single sub-expression,
557
+ * enabling test writers to assert that a condition does not hold. The
558
+ * negation result is computed at construction time, ensuring consistent
559
+ * reporting throughout the assertion framework.
1423
560
  *
1424
- * The implementation is optimised for use in embedded environments and
1425
- * supports both compile-time and run-time evaluation.
1426
- *
1427
- * All definitions are intended for internal use within the framework and
1428
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1429
- * maintain a structured and modular codebase.
561
+ * @tparam T The type of the operand.
1430
562
  *
1431
563
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1432
564
  */
1433
565
  template <class T>
1434
- struct not_ : type_traits::op
566
+ struct not_ : unary_op_<T>
1435
567
  {
1436
568
  /**
1437
569
  * @brief Constructs a logical NOT comparator for the given operand.
1438
570
  *
1439
571
  * @param t The operand to be negated.
1440
- *
1441
- * @details
1442
- * Evaluates the logical negation of the provided operand at
1443
- * construction, supporting both custom and standard types. The result is
1444
- * stored in the `value_` member for efficient access.
1445
572
  */
1446
- explicit constexpr not_ (const T& t = {})
1447
- : t_{ t }, value_{ not static_cast<bool> (t) }
1448
- {
1449
- }
1450
-
1451
- /**
1452
- * @brief Conversion operator to boolean.
1453
- *
1454
- * @par Parameters
1455
- * None.
1456
- * @retval true The operand evaluates to false.
1457
- * @retval false The operand evaluates to true.
1458
- *
1459
- * @details
1460
- * Returns the result of the logical NOT operation.
1461
- */
1462
- [[nodiscard]] constexpr
1463
- operator bool () const
1464
- {
1465
- return value_;
1466
- }
1467
-
1468
- /**
1469
- * @brief Retrieves the value of the operand.
1470
- *
1471
- * @par Parameters
1472
- * None.
1473
- * @return The extracted operand value.
1474
- *
1475
- * @details
1476
- * Returns the value of the operand, applying the generic getter to
1477
- * ensure correct extraction for both custom and standard types.
1478
- */
1479
- [[nodiscard]] constexpr auto
1480
- value () const
1481
- {
1482
- return get (t_);
1483
- }
1484
-
1485
- /**
1486
- * @brief Stores the operand.
1487
- */
1488
- const T t_{};
1489
-
1490
- /**
1491
- * @brief Stores the result of the logical NOT operation.
1492
- */
1493
- const bool value_{};
573
+ explicit constexpr not_ (const T& t = {});
1494
574
  };
1495
575
 
1496
576
  // Deduction guide.
1497
577
  template <typename T>
1498
578
  not_ (const T&) -> not_<T>;
1499
579
 
1500
- // ------------------------------------------------------------------------
580
+ // ========================================================================
1501
581
 
1502
582
  #if defined(__cpp_exceptions)
1503
583
 
1504
584
  /**
1505
- * @brief Operator struct template to check if an expression throws a
1506
- * specific exception.
1507
- *
1508
- * @tparam Callable_T The type of the callable object to be invoked.
1509
- * @tparam Exception_T The type of the exception to check for (defaults to
1510
- * `void` for any exception).
585
+ * @brief Common base struct for callable-wrapping operators.
1511
586
  *
1512
587
  * @details
1513
- * The `throws_` struct template provides a type-safe mechanism for
1514
- * verifying whether a callable expression throws a specified exception
1515
- * type during its execution within the framework.
1516
- *
1517
- * This comparator is designed to support both custom and standard callable
1518
- * types. The result of the exception check is stored in the `value_`
1519
- * member for efficient access.
1520
- *
1521
- * The implementation is optimised for use in embedded environments and
1522
- * supports both compile-time and run-time evaluation.
1523
- *
1524
- * All definitions are intended for internal use within the framework and
1525
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1526
- * maintain a structured and modular codebase.
588
+ * This base struct provides common functionality for operators that wrap
589
+ * callable invocations, particularly for exception-checking operations.
590
+ * Derived structs (such as `throws_` and `nothrow_`) use this base to
591
+ * store and manage the pre-computed boolean result of a callable
592
+ * invocation, enabling consistent reporting and composition of
593
+ * exception-checking assertions.
1527
594
  *
1528
595
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1529
596
  */
1530
- template <class Callable_T, class Exception_T = void>
1531
- struct throws_ : type_traits::op
597
+ struct callable_op_ : type_traits::op
1532
598
  {
1533
599
  /**
1534
- * @brief Constructs an exception checking operator for the given
1535
- * callable.
600
+ * @brief Constructs a callable operator with the pre-computed
601
+ * boolean result.
1536
602
  *
1537
- * @param func The callable object to be invoked.
1538
- *
1539
- * @details
1540
- * Invokes the provided callable and determines whether it throws an
1541
- * exception of the specified type. The result is stored in the `value_`
1542
- * member for efficient access.
603
+ * @param value The pre-computed boolean result of the invocation.
1543
604
  */
1544
- constexpr explicit throws_ (const Callable_T& func)
1545
- : value_{ [&func]
1546
- {
1547
- try
1548
- {
1549
- func ();
1550
- }
1551
- catch (const Exception_T&)
1552
- {
1553
- return true;
1554
- }
1555
- catch (...)
1556
- {
1557
- return false;
1558
- }
1559
- return false;
1560
- }() }
1561
- {
1562
- }
605
+ constexpr explicit callable_op_ (bool value);
1563
606
 
1564
607
  /**
1565
608
  * @brief Conversion operator to boolean.
1566
609
  *
1567
610
  * @par Parameters
1568
611
  * None.
1569
- * @retval true The callable throws the specified exception type.
1570
- * @retval false The callable does not throw the specified exception
1571
- * type.
1572
- *
1573
- * @details
1574
- * Returns the result of the exception check.
612
+ * @return The result of the callable invocation.
1575
613
  */
1576
614
  [[nodiscard]] constexpr
1577
- operator bool () const
1578
- {
1579
- return value_;
1580
- }
615
+ operator bool () const;
1581
616
 
617
+ private:
1582
618
  /**
1583
- * @brief Stores the result of the exception check.
619
+ * @brief Stores the result of the callable invocation.
1584
620
  */
1585
621
  const bool value_{};
1586
622
  };
1587
623
 
1588
- // ------------------------------------------------------------------------
624
+ // ========================================================================
1589
625
 
1590
626
  /**
1591
- * @brief Operator struct template to check if an expression throws any
1592
- * exception.
1593
- *
1594
- * @tparam Callable_T The type of the callable object to be invoked.
627
+ * @brief Operator struct template to check if an expression throws a
628
+ * specific exception.
1595
629
  *
1596
630
  * @details
1597
- * The `throws_` struct template provides a type-safe mechanism for
1598
- * verifying whether a callable expression throws any exception during its
1599
- * execution within the framework.
1600
- *
1601
- * This comparator is designed to support both custom and standard callable
1602
- * types. The result of the exception check is stored in the `value_`
1603
- * member for efficient access.
1604
- *
1605
- * The implementation is optimised for use in embedded environments and
1606
- * supports both compile-time and run-time evaluation.
631
+ * This specialisation checks whether invoking the given callable throws
632
+ * an exception of the specified type. The check is performed at
633
+ * construction time, with the result cached for reporting and
634
+ * composition. Use this when a test must verify that an operation raises
635
+ * an expected exception of a particular type.
1607
636
  *
1608
- * All definitions are intended for internal use within the framework and
1609
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1610
- * maintain a structured and modular codebase.
637
+ * @tparam Callable_T The type of the callable object to be invoked.
638
+ * @tparam Exception_T The type of the exception to check for (defaults to
639
+ * `void` for any exception).
1611
640
  *
1612
641
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1613
642
  */
1614
- template <class Callable_T>
1615
- struct throws_<Callable_T, void> : type_traits::op
643
+ template <class Callable_T, class Exception_T = void>
644
+ struct throws_ : callable_op_
1616
645
  {
1617
646
  /**
1618
647
  * @brief Constructs an exception checking operator for the given
1619
648
  * callable.
1620
649
  *
1621
- * @details
1622
- * Invokes the provided callable and determines whether it throws any
1623
- * exception. The result is stored in the `value_` member for efficient
1624
- * access.
1625
- *
1626
650
  * @param func The callable object to be invoked.
1627
651
  */
1628
- constexpr explicit throws_ (const Callable_T& func)
1629
- : value_{ [&func]
1630
- {
1631
- try
1632
- {
1633
- func ();
1634
- }
1635
- catch (...)
1636
- {
1637
- return true;
1638
- }
1639
- return false;
1640
- }() }
1641
- {
1642
- }
1643
-
1644
- /**
1645
- * @brief Conversion operator to boolean.
1646
- *
1647
- * @par Parameters
1648
- * None.
1649
- * @retval true The callable throws an exception.
1650
- *
1651
- * @details
1652
- * Returns the result of the exception check.
1653
- * @retval false The callable does not throw any exception.
1654
- */
1655
- [[nodiscard]] constexpr
1656
- operator bool () const
1657
- {
1658
- return value_;
1659
- }
1660
-
1661
- /**
1662
- * @brief Stores the result of the exception check.
1663
- */
1664
- const bool value_{};
652
+ constexpr explicit throws_ (const Callable_T& func);
1665
653
  };
1666
654
 
1667
- // ------------------------------------------------------------------------
655
+ // ========================================================================
1668
656
 
1669
657
  /**
1670
- * @brief Operator struct template to check if an expression does not throw
1671
- * any exception.
1672
- *
1673
- * @tparam Callable_T The type of the callable object to be invoked.
658
+ * @brief Operator struct template to check if an expression throws any
659
+ * exception.
1674
660
  *
1675
661
  * @details
1676
- * The `nothrow_` struct template provides a type-safe mechanism for
1677
- * verifying whether a callable expression completes without throwing any
1678
- * exception during its execution within the framework.
1679
- *
1680
- * This comparator is designed to support both custom and standard callable
1681
- * types. The result of the exception check is stored in the `value_`
1682
- * member for efficient access.
662
+ * This partial specialisation checks whether invoking the given callable
663
+ * throws any exception, regardless of type. The check is performed at
664
+ * construction time, with the result cached for reporting and
665
+ * composition. Use this when a test must verify that an operation raises
666
+ * an exception without caring about the specific exception type.
1683
667
  *
1684
- * The implementation is optimised for use in embedded environments and
1685
- * supports both compile-time and run-time evaluation.
1686
- *
1687
- * All definitions are intended for internal use within the framework and
1688
- * are implemented in the `include/micro-os-plus/micro-test-plus` folder to
1689
- * maintain a structured and modular codebase.
668
+ * @tparam Callable_T The type of the callable object to be invoked.
1690
669
  *
1691
670
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1692
671
  */
1693
672
  template <class Callable_T>
1694
- struct nothrow_ : type_traits::op
673
+ struct throws_<Callable_T, void> : callable_op_
1695
674
  {
1696
675
  /**
1697
- * @brief Constructs a nothrow checking operator for the given callable.
676
+ * @brief Constructs an exception checking operator for the given
677
+ * callable.
1698
678
  *
1699
679
  * @param func The callable object to be invoked.
1700
- *
1701
- * @details
1702
- * Invokes the provided callable and determines whether it completes
1703
- * without throwing any exception. The result is stored in the `value_`
1704
- * member for efficient access.
1705
- */
1706
- constexpr explicit nothrow_ (const Callable_T& func)
1707
- : value_{ [&func]
1708
- {
1709
- try
1710
- {
1711
- func ();
1712
- }
1713
- catch (...)
1714
- {
1715
- return false;
1716
- }
1717
- return true;
1718
- }() }
1719
- {
1720
- }
1721
-
1722
- /**
1723
- * @brief Conversion operator to boolean.
1724
- *
1725
- * @par Parameters
1726
- * None.
1727
- * @retval true The callable does not throw any exception.
1728
- * @retval false The callable throws an exception.
1729
- *
1730
- * @details
1731
- * Returns the result of the nothrow check.
1732
680
  */
1733
- [[nodiscard]] constexpr
1734
- operator bool () const
1735
- {
1736
- return value_;
1737
- }
1738
-
1739
- /**
1740
- * @brief Stores the result of the nothrow check.
1741
- */
1742
- const bool value_{};
681
+ constexpr explicit throws_ (const Callable_T& func);
1743
682
  };
1744
683
 
1745
- #endif
1746
-
1747
- // ------------------------------------------------------------------------
684
+ // ========================================================================
1748
685
 
1749
686
  /**
1750
- * @brief Base class for a deferred reporter that collects messages into a
1751
- * string.
687
+ * @brief Operator struct template to check if an expression does not throw
688
+ * any exception.
1752
689
  *
1753
690
  * @details
1754
- * The `deferred_reporter_base` class serves as the foundational component
1755
- * for deferred reporting within the framework. It is responsible for
1756
- * collecting expectation messages, typically passed via the
1757
- * `operator<<()`, into a string for later reporting.
691
+ * This struct checks whether invoking the given callable completes
692
+ * without throwing an exception. The check is performed at construction
693
+ * time, with the result cached for reporting and composition. Use this
694
+ * when a test must verify that an operation is exception-safe.
1758
695
  *
1759
- * This class maintains the result value, abort status, and the source
1760
- * location associated with the report. It is intended exclusively for
1761
- * internal use and is implemented in the
1762
- * `include/micro-os-plus/micro-test-plus` folder to ensure a structured
1763
- * and modular codebase.
696
+ * @tparam Callable_T The type of the callable object to be invoked.
1764
697
  *
1765
698
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
1766
699
  */
1767
- class deferred_reporter_base
700
+ template <class Callable_T>
701
+ struct nothrow_ : callable_op_
1768
702
  {
1769
- public:
1770
703
  /**
1771
- * @brief Constructs a deferred reporter base.
1772
- *
1773
- * @param value The result value associated with the report.
1774
- * @param location The source location relevant to the report.
1775
- */
1776
- deferred_reporter_base (bool value,
1777
- const reflection::source_location location);
1778
-
1779
- /**
1780
- * @brief Destructor for the deferred reporter base.
1781
- */
1782
- ~deferred_reporter_base ();
1783
-
1784
- /**
1785
- * @brief Appends a message to the reporter.
1786
- *
1787
- * @tparam T The type of the message to append.
1788
- *
1789
- * @param msg The message to append.
1790
- * @return Reference to the current reporter instance.
1791
- */
1792
- template <class T>
1793
- auto&
1794
- operator<< (const T& msg);
1795
-
1796
- /**
1797
- * @brief Retrieves the result value.
1798
- *
1799
- *
1800
- * @par Parameters
1801
- * None.
1802
- * @retval true The reported condition was met.
1803
- * @retval false The reported condition was not met.
704
+ * @brief Constructs a nothrow checking operator for the given
705
+ * callable.
1804
706
  *
1805
- * @details
1806
- * Returns the result value associated with the report.
1807
- */
1808
- [[nodiscard]] constexpr bool
1809
- value () const
1810
- {
1811
- return value_;
1812
- }
1813
-
1814
- protected:
1815
- /**
1816
- * @brief Stores the result value of the report.
1817
- */
1818
- bool value_{};
1819
-
1820
- /**
1821
- * @brief Indicates whether the reporting should abort further
1822
- * processing.
1823
- */
1824
- bool abort_ = false;
1825
-
1826
- /**
1827
- * @brief Stores the source location associated with the report.
1828
- */
1829
- const reflection::source_location location_{};
1830
-
1831
- /**
1832
- * @brief String to collect the expectation message passed via
1833
- * `operator<<()`.
707
+ * @param func The callable object to be invoked.
1834
708
  */
1835
- std::string message_{};
709
+ constexpr explicit nothrow_ (const Callable_T& func);
1836
710
  };
1837
711
 
1838
- // ------------------------------------------------------------------------
712
+ #endif
713
+
714
+ // ========================================================================
1839
715
 
1840
716
  /**
1841
- * @brief Deferred reporter class template for a specific expression.
1842
- *
1843
- * @tparam Expr_T The type of the expression being reported.
1844
- *
1845
- * @details
1846
- * The `deferred_reporter` class template extends `deferred_reporter_base`
1847
- * to provide deferred reporting functionality for a specific test
1848
- * expression within the framework.
1849
- *
1850
- * This class template is responsible for capturing the expression under
1851
- * evaluation, the abort status, and the source location. It is intended
1852
- * exclusively for internal use and is implemented in the
1853
- * `include/micro-os-plus/micro-test-plus` folder to ensure a structured
1854
- * and modular codebase.
1855
- *
1856
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
717
+ * @brief Appends the string representation of a numeric value to a
718
+ * buffer, using `std::to_chars` for allocation-free,
719
+ * locale-independent formatting.
720
+ *
721
+ * @tparam T The numeric type to format.
722
+ * @param buffer The string to append to.
723
+ * @param v The value to format.
724
+ * @par Returns
725
+ * Nothing.
1857
726
  */
1858
- template <class Expr_T>
1859
- class deferred_reporter : public deferred_reporter_base
1860
- {
1861
- public:
1862
- /**
1863
- * @brief Constructs a deferred reporter for a specific expression.
1864
- *
1865
- * @param expr The expression under evaluation.
1866
- * @param abort Indicates whether reporting should abort further
1867
- * processing.
1868
- * @param location The source location relevant to the report.
1869
- *
1870
- * @details
1871
- * Initialises the reporter with the given expression, abort status, and
1872
- * source location.
1873
- */
1874
- constexpr explicit deferred_reporter (
1875
- const Expr_T& expr, bool abort,
1876
- const reflection::source_location& location);
1877
-
1878
- /**
1879
- * @brief Destructor for the deferred reporter.
1880
- */
1881
- ~deferred_reporter ();
1882
-
1883
- protected:
1884
- /**
1885
- * @brief Stores the expression under evaluation.
1886
- */
1887
- const Expr_T expr_{};
1888
- };
727
+ template <class T>
728
+ requires std::is_arithmetic_v<T>
729
+ void
730
+ append_number_ (std::string& buffer, T v);
1889
731
 
1890
732
  // ------------------------------------------------------------------------
1891
733
  } // namespace detail
@@ -1901,6 +743,11 @@ namespace micro_os_plus::micro_test_plus
1901
743
 
1902
744
  #endif // __cplusplus
1903
745
 
746
+ // ============================================================================
747
+ // Templates & constexpr implementations.
748
+
749
+ #include "inlines/detail-inlines.h"
750
+
1904
751
  // ----------------------------------------------------------------------------
1905
752
 
1906
753
  #endif // MICRO_TEST_PLUS_DETAIL_H_