@micro-os-plus/micro-test-plus 3.2.0 → 3.2.3

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