@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
@@ -24,10 +24,10 @@
24
24
  * This header provides the declarations for the function comparator templates
25
25
  * and logical operators used within the µTest++ framework. It defines the
26
26
  * interfaces for generic and pointer-based comparison functions, including
27
- * equality, non-equality, greater than, less than, and their respective
28
- * logical variants. Additionally, it declares logical combinators such as
29
- * conjunction (`_and`), disjunction (`_or`), and negation (`_not`), as well as
30
- * a utility for safely removing constness from objects.
27
+ * equality, non-equality, greater than, less than, greater than or equal,
28
+ * and less than or equal. Additionally, it declares logical combinators such
29
+ * as conjunction (`_and`), disjunction (`_or`), and negation (`_not`), as
30
+ * well as a utility for safely removing constness from objects.
31
31
  *
32
32
  * These comparators and logical operators enable expressive and type-safe test
33
33
  * expectations and assertions, supporting both value and pointer semantics.
@@ -62,10 +62,13 @@
62
62
  #pragma GCC diagnostic ignored "-Waggregate-return"
63
63
  #if defined(__clang__)
64
64
  #pragma clang diagnostic ignored "-Wc++98-compat"
65
+ #pragma clang diagnostic ignored "-Wpre-c++17-compat"
65
66
  #pragma clang diagnostic ignored "-Wunknown-warning-option"
66
67
  #endif
67
68
  #endif
68
69
 
70
+ // ===========================================================================
71
+
69
72
  namespace micro_os_plus::micro_test_plus
70
73
  {
71
74
  // --------------------------------------------------------------------------
@@ -315,17 +318,22 @@ namespace micro_os_plus::micro_test_plus
315
318
  [[nodiscard]] constexpr auto
316
319
  mut (const T& t) noexcept -> T&;
317
320
 
321
+ // --------------------------------------------------------------------------
322
+ } // namespace micro_os_plus::micro_test_plus
323
+
318
324
  #if defined(__GNUC__)
319
325
  #pragma GCC diagnostic pop
320
326
  #endif
321
327
 
322
- // --------------------------------------------------------------------------
323
- } // namespace micro_os_plus::micro_test_plus
324
-
325
328
  // ----------------------------------------------------------------------------
326
329
 
327
330
  #endif // __cplusplus
328
331
 
332
+ // ============================================================================
333
+ // Templates & constexpr implementations.
334
+
335
+ #include "inlines/function-comparators-inlines.h"
336
+
329
337
  // ----------------------------------------------------------------------------
330
338
 
331
339
  #endif // MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
@@ -42,8 +42,8 @@
42
42
  * should not be included directly by user code.
43
43
  */
44
44
 
45
- #ifndef MICRO_TEST_PLUS_DETAILS_INLINES_H_
46
- #define MICRO_TEST_PLUS_DETAILS_INLINES_H_
45
+ #ifndef MICRO_TEST_PLUS_DEFERRED_REPORTER_INLINES_H_
46
+ #define MICRO_TEST_PLUS_DEFERRED_REPORTER_INLINES_H_
47
47
 
48
48
  // ----------------------------------------------------------------------------
49
49
 
@@ -51,9 +51,12 @@
51
51
 
52
52
  // ----------------------------------------------------------------------------
53
53
 
54
- #include <stdio.h>
55
- #include <cstring>
56
- // #include "test-reporter.h"
54
+ #include <charconv>
55
+ #include <cstdio>
56
+
57
+ #if defined(MICRO_OS_PLUS_TRACE)
58
+ #include <micro-os-plus/diag/trace.h>
59
+ #endif // MICRO_OS_PLUS_TRACE
57
60
 
58
61
  // ----------------------------------------------------------------------------
59
62
 
@@ -66,12 +69,26 @@
66
69
  #endif
67
70
  #endif
68
71
 
72
+ // ============================================================================
73
+
69
74
  namespace micro_os_plus::micro_test_plus
70
75
  {
71
76
  // --------------------------------------------------------------------------
72
77
 
73
78
  namespace detail
74
79
  {
80
+ // ========================================================================
81
+
82
+ /**
83
+ * @details
84
+ * Returns the result value stored in `value_`.
85
+ */
86
+ inline bool
87
+ deferred_reporter_base::value () const
88
+ {
89
+ return value_;
90
+ }
91
+
75
92
  // ------------------------------------------------------------------------
76
93
 
77
94
  /**
@@ -80,22 +97,45 @@ namespace micro_os_plus::micro_test_plus
80
97
  * expectation messages by appending the provided value to the internal
81
98
  * message string.
82
99
  *
83
- * If the argument is of an arithmetic type, it is first converted to a
84
- * string using `std::to_string` before being appended. For all other
85
- * types, the value is appended directly. This ensures that both numeric
86
- * and string-like messages are handled appropriately and consistently.
100
+ * If the argument is a `char`, it is appended directly as a character.
101
+ * If the argument is of another arithmetic type, it is converted to a
102
+ * string using a fixed-size buffer and `std::to_chars` to avoid dynamic
103
+ * memory allocation. For all other types, the value is appended directly.
87
104
  */
88
105
  template <class T>
106
+ requires type_traits::printable<T>
89
107
  auto&
90
108
  deferred_reporter_base::operator<< (const T& msg)
91
109
  {
92
- if constexpr (std::is_arithmetic_v<T>)
110
+ if constexpr (std::is_same_v<T, char>)
93
111
  {
94
- message_.append (std::to_string (msg));
112
+ deferred_output_.push_back (msg);
113
+ }
114
+ else if constexpr (std::is_arithmetic_v<T>)
115
+ {
116
+ // Optimise to avoid dynamic memory allocation in std::to_string by
117
+ // using a fixed-size buffer and std::to_chars.
118
+ #if defined(__GNUC__)
119
+ #pragma GCC diagnostic push
120
+ #if defined(__clang__)
121
+ #pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
122
+ #endif
123
+ #endif
124
+ char buf[64];
125
+ // 64 bytes is sufficient for the longest decimal representation
126
+ // of any standard arithmetic type (long double ~45 chars).
127
+ static_assert (sizeof (buf) >= 50,
128
+ "buf must be large enough for any arithmetic type");
129
+ auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), msg);
130
+ if (ec == std::errc{})
131
+ deferred_output_.append (buf, ptr);
132
+ #if defined(__GNUC__)
133
+ #pragma GCC diagnostic pop
134
+ #endif
95
135
  }
96
136
  else
97
137
  {
98
- message_.append (msg);
138
+ deferred_output_.append (msg);
99
139
  }
100
140
  return *this;
101
141
  }
@@ -114,41 +154,23 @@ namespace micro_os_plus::micro_test_plus
114
154
  * contextual information for reporting purposes.
115
155
  */
116
156
  template <class Expr_T>
117
- constexpr deferred_reporter<Expr_T>::deferred_reporter (
157
+ deferred_reporter::deferred_reporter (
118
158
  const Expr_T& expr, bool abort,
119
- const reflection::source_location& location)
120
- : deferred_reporter_base{ static_cast<bool> (expr), location },
121
- expr_{ expr }
159
+ const reflection::source_location& location, subtest& subtest,
160
+ expression_formatter& expression)
161
+ : deferred_reporter_base{ static_cast<bool> (expr), location, subtest }
162
+
122
163
  {
123
- #if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
124
- printf ("%s\n", __PRETTY_FUNCTION__);
125
- #endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
164
+ #if defined(MICRO_OS_PLUS_TRACE) \
165
+ && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
166
+ trace::printf ("%s\n", __PRETTY_FUNCTION__);
167
+ #endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
126
168
  abort_ = abort;
127
- }
169
+ has_expression_ = type_traits::is_op<Expr_T>;
128
170
 
129
- /**
130
- * @details
131
- * The destructor finalises the deferred reporting process for a test
132
- * expression. If the evaluated expression is true, the reporter records a
133
- * successful outcome along with any accumulated message. If the expression
134
- * is false, the reporter records a failure, including the abort status,
135
- * message, and source location for comprehensive reporting.
136
- *
137
- * This mechanism ensures that all relevant information about the test
138
- * outcome is captured and reported accurately when the deferred reporter
139
- * goes out of scope.
140
- */
141
- template <class Expr_T>
142
- deferred_reporter<Expr_T>::~deferred_reporter ()
143
- {
144
- if (value_)
145
- {
146
- reporter->pass (expr_, message_);
147
- }
148
- else
149
- {
150
- reporter->fail (expr_, abort_, message_, location_);
151
- }
171
+ expression.clear ();
172
+
173
+ expression << expr;
152
174
  }
153
175
 
154
176
  // ------------------------------------------------------------------------
@@ -167,6 +189,6 @@ namespace micro_os_plus::micro_test_plus
167
189
 
168
190
  // ----------------------------------------------------------------------------
169
191
 
170
- #endif // MICRO_TEST_PLUS_DETAILS_INLINES_H_
192
+ #endif // MICRO_TEST_PLUS_DEFERRED_REPORTER_INLINES_H_
171
193
 
172
194
  // ----------------------------------------------------------------------------