@micro-os-plus/micro-test-plus 4.0.0 → 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 (51) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/CMakeLists.txt +74 -24
  3. package/README.md +3 -2
  4. package/include/micro-os-plus/micro-test-plus/README.md +6 -0
  5. package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +29 -54
  6. package/include/micro-os-plus/micro-test-plus/detail.h +166 -705
  7. package/include/micro-os-plus/micro-test-plus/exceptions.h +5 -6
  8. package/include/micro-os-plus/micro-test-plus/expression-formatter.h +669 -0
  9. package/include/micro-os-plus/micro-test-plus/function-comparators.h +5 -0
  10. package/include/micro-os-plus/micro-test-plus/inlines/deferred-reporter-inlines.h +25 -30
  11. package/include/micro-os-plus/micro-test-plus/inlines/detail-inlines.h +711 -0
  12. package/include/micro-os-plus/micro-test-plus/inlines/exceptions-inline.h +137 -0
  13. package/include/micro-os-plus/micro-test-plus/inlines/expression-formatter-inlines.h +510 -0
  14. package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +17 -76
  15. package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +47 -25
  16. package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +7 -7
  17. package/include/micro-os-plus/micro-test-plus/inlines/operators-inlines.h +275 -0
  18. package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +4 -4
  19. package/include/micro-os-plus/micro-test-plus/inlines/reporter-inlines.h +53 -394
  20. package/include/micro-os-plus/micro-test-plus/inlines/runner-inlines.h +38 -0
  21. package/include/micro-os-plus/micro-test-plus/inlines/runner-totals-inlines.h +152 -0
  22. package/include/micro-os-plus/micro-test-plus/inlines/test-inlines.h +231 -45
  23. package/include/micro-os-plus/micro-test-plus/inlines/timings-inlines.h +120 -0
  24. package/include/micro-os-plus/micro-test-plus/inlines/type-traits-inlines.h +231 -0
  25. package/include/micro-os-plus/micro-test-plus/literals.h +8 -14
  26. package/include/micro-os-plus/micro-test-plus/math.h +5 -0
  27. package/include/micro-os-plus/micro-test-plus/operators.h +19 -169
  28. package/include/micro-os-plus/micro-test-plus/reflection.h +5 -12
  29. package/include/micro-os-plus/micro-test-plus/reporter-human.h +17 -11
  30. package/include/micro-os-plus/micro-test-plus/reporter-tap.h +14 -8
  31. package/include/micro-os-plus/micro-test-plus/reporter.h +101 -424
  32. package/include/micro-os-plus/micro-test-plus/runner-totals.h +162 -176
  33. package/include/micro-os-plus/micro-test-plus/runner.h +61 -42
  34. package/include/micro-os-plus/micro-test-plus/test.h +450 -506
  35. package/include/micro-os-plus/micro-test-plus/timings.h +259 -262
  36. package/include/micro-os-plus/micro-test-plus/type-traits.h +19 -67
  37. package/include/micro-os-plus/micro-test-plus/utility.h +5 -4
  38. package/include/micro-os-plus/micro-test-plus.h +33 -24
  39. package/meson.build +1 -0
  40. package/package.json +11 -3
  41. package/src/deferred-reporter.cpp +21 -2
  42. package/src/expression-formatter.cpp +289 -0
  43. package/src/reflection.cpp +3 -1
  44. package/src/reporter-human.cpp +31 -37
  45. package/src/reporter-tap.cpp +25 -35
  46. package/src/reporter.cpp +36 -231
  47. package/src/runner-totals.cpp +6 -3
  48. package/src/runner.cpp +131 -25
  49. package/src/test.cpp +120 -113
  50. package/src/timings.cpp +6 -5
  51. package/src/utility.cpp +1 -1
@@ -65,290 +65,282 @@
65
65
  #endif
66
66
  #endif
67
67
 
68
- // ===========================================================================
68
+ // ============================================================================
69
69
 
70
70
  namespace micro_os_plus::micro_test_plus
71
71
  {
72
+ // --------------------------------------------------------------------------
72
73
 
73
- // ==========================================================================
74
-
75
- /**
76
- * @brief A single point-in-time measurement, wrapping a `timespec` value.
77
- *
78
- * @details
79
- * `timestamp` stores one `timespec` sample obtained from the system clock.
80
- * It is default-constructible (zero-initialises the `timespec`),
81
- * copy-constructible, and move-constructible, so that it can be used
82
- * efficiently in `std::optional<timestamp>` containers.
83
- *
84
- * The `has_clock()` predicate allows callers to determine whether a
85
- * real-time clock is available on the target platform before relying on
86
- * the stored value.
87
- *
88
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
89
- */
90
- class timestamp
74
+ namespace detail
91
75
  {
92
- public:
93
- /**
94
- * @brief Default constructor. Zero-initialises the internal `timespec`.
95
- */
96
- timestamp () noexcept;
97
-
98
- /**
99
- * @brief Constructs a timestamp from an existing `timespec` value.
100
- *
101
- * @param ts The `timespec` value to store.
102
- */
103
- timestamp (const timespec& ts) noexcept : value_{ ts }
104
- {
105
- }
106
-
107
- // `timespec` is trivially copyable, so copy and move are safe to default.
108
- // Defaulting these operations allows `timestamp` to be used in contexts
109
- // that require copyability or movability (e.g. containers, algorithms).
110
- /**
111
- * @brief Defaulted copy constructor.
112
- */
113
- timestamp (const timestamp&) = default;
114
-
115
- /**
116
- * @brief Defaulted move constructor.
117
- */
118
- timestamp (timestamp&&) = default;
119
-
120
- /**
121
- * @brief Defaulted copy assignment operator.
122
- */
123
- timestamp&
124
- operator= (const timestamp&) = default;
125
-
126
- /**
127
- * @brief Defaulted move assignment operator.
128
- */
129
- timestamp&
130
- operator= (timestamp&&) = default;
131
-
132
- /**
133
- * @brief Defaulted destructor.
134
- */
135
- ~timestamp () = default;
76
+ // ========================================================================
136
77
 
137
78
  /**
138
- * @brief Returns true if a monotonic clock is available on this target.
79
+ * @brief A single point-in-time measurement, wrapping a `timespec` value.
139
80
  *
140
- * @par Parameters
141
- * None.
142
- * @retval true A real-time clock is available and timestamps are valid.
143
- * @retval false No clock is available; timing data should be ignored.
144
- */
145
- bool
146
- has_clock (void) const noexcept;
147
-
148
- /**
149
- * @brief Returns a mutable reference to the underlying `timespec` value.
81
+ * @details
82
+ * `timestamp` stores one `timespec` sample obtained from the system clock.
83
+ * It is default-constructible (zero-initialises the `timespec`),
84
+ * copy-constructible, and move-constructible, so that it can be used
85
+ * efficiently in `std::optional<timestamp>` containers.
150
86
  *
151
- * @par Parameters
152
- * None.
153
- * @return A reference to the stored `timespec`.
154
- */
155
- [[nodiscard]] timespec&
156
- value () noexcept
157
- {
158
- return value_;
159
- }
160
-
161
- /**
162
- * @brief Returns a const reference to the underlying `timespec` value.
87
+ * The `has_clock()` predicate allows callers to determine whether a
88
+ * real-time clock is available on the target platform before relying on
89
+ * the stored value.
163
90
  *
164
- * @par Parameters
165
- * None.
166
- * @return A const reference to the stored `timespec`.
91
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
167
92
  */
168
- [[nodiscard]] const timespec&
169
- value () const noexcept
93
+ class timestamp
170
94
  {
171
- return value_;
172
- }
173
-
174
- protected:
175
- /**
176
- * @brief The underlying `timespec` value.
177
- */
178
- timespec value_{};
179
- };
180
-
181
- // ==========================================================================
182
-
183
- /**
184
- * @brief A begin/end timestamp pair used to measure elapsed time.
185
- *
186
- * @details
187
- * `timestamps` stores an optional begin `timestamp` and an optional end
188
- * `timestamp`. When both are available, `compute_elapsed_time()` derives
189
- * the elapsed interval in milliseconds and microseconds.
190
- *
191
- * Typical usage in the framework:
192
- * 1. Call `timestamp_begin()` just before the test suite or session
193
- * body executes.
194
- * 2. Call `timestamp_end()` immediately after it completes.
195
- * 3. Pass the elapsed values to the reporter.
196
- *
197
- * If the platform does not provide a monotonic clock, the `std::optional`
198
- * members remain empty and `has_timestamps()` returns `false`, so that the
199
- * reporter can skip timing output.
200
- *
201
- * The class is non-copyable and non-movable to prevent accidental sharing
202
- * of live timing state.
203
- *
204
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
205
- */
206
- class timestamps
207
- {
208
- public:
209
- /**
210
- * @brief Default constructor. Both timestamps are uninitialised.
211
- */
212
- timestamps () = default;
213
-
214
- /**
215
- * @brief Deleted copy constructor to prevent copying.
216
- */
217
- timestamps (const timestamps&) = delete;
218
-
219
- /**
220
- * @brief Deleted move constructor to prevent moving.
221
- */
222
- timestamps (timestamps&&) = delete;
95
+ public:
96
+ /**
97
+ * @brief Default constructor. Zero-initialises the internal `timespec`.
98
+ */
99
+ timestamp () noexcept;
100
+
101
+ /**
102
+ * @brief Constructs a timestamp from an existing `timespec` value.
103
+ *
104
+ * @param ts The `timespec` value to store.
105
+ */
106
+ timestamp (const timespec& ts) noexcept;
107
+
108
+ // `timespec` is trivially copyable, so copy and move are safe to
109
+ // default. Defaulting these operations allows `timestamp` to be used in
110
+ // contexts that require copyability or movability (e.g. containers,
111
+ // algorithms).
112
+ /**
113
+ * @brief Defaulted copy constructor.
114
+ */
115
+ timestamp (const timestamp&) = default;
116
+
117
+ /**
118
+ * @brief Defaulted move constructor.
119
+ */
120
+ timestamp (timestamp&&) = default;
121
+
122
+ /**
123
+ * @brief Defaulted copy assignment operator.
124
+ */
125
+ timestamp&
126
+ operator= (const timestamp&)
127
+ = default;
128
+
129
+ /**
130
+ * @brief Defaulted move assignment operator.
131
+ */
132
+ timestamp&
133
+ operator= (timestamp&&)
134
+ = default;
135
+
136
+ /**
137
+ * @brief Defaulted destructor.
138
+ */
139
+ ~timestamp () = default;
140
+
141
+ /**
142
+ * @brief Returns true if a monotonic clock is available on this target.
143
+ *
144
+ * @par Parameters
145
+ * None.
146
+ * @retval true A real-time clock is available and timestamps are valid.
147
+ * @retval false No clock is available; timing data should be ignored.
148
+ */
149
+ bool
150
+ has_clock (void) const noexcept;
151
+
152
+ /**
153
+ * @brief Returns a mutable reference to the underlying `timespec` value.
154
+ *
155
+ * @par Parameters
156
+ * None.
157
+ * @return A reference to the stored `timespec`.
158
+ */
159
+ [[nodiscard]] timespec&
160
+ value () noexcept;
161
+
162
+ /**
163
+ * @brief Returns a const reference to the underlying `timespec` value.
164
+ *
165
+ * @par Parameters
166
+ * None.
167
+ * @return A const reference to the stored `timespec`.
168
+ */
169
+ [[nodiscard]] const timespec&
170
+ value () const noexcept;
171
+
172
+ protected:
173
+ /**
174
+ * @brief The underlying `timespec` value.
175
+ */
176
+ timespec value_{};
177
+ };
178
+
179
+ // ========================================================================
223
180
 
224
181
  /**
225
- * @brief Deleted copy assignment operator to prevent copying.
226
- */
227
- timestamps&
228
- operator= (const timestamps&) = delete;
229
-
230
- /**
231
- * @brief Deleted move assignment operator to prevent moving.
232
- */
233
- timestamps&
234
- operator= (timestamps&&) = delete;
235
-
236
- /**
237
- * @brief Defaulted destructor.
238
- */
239
- ~timestamps () = default;
240
-
241
- /**
242
- * @brief Records the begin timestamp using the current system clock.
182
+ * @brief A begin/end timestamp pair used to measure elapsed time.
243
183
  *
244
- * @par Parameters
245
- * None.
246
- * @par Returns
247
- * Nothing.
248
- */
249
- void
250
- timestamp_begin (void) noexcept;
251
-
252
- /**
253
- * @brief Records the begin timestamp from a caller-supplied value.
184
+ * @details
185
+ * `timestamps` stores an optional begin `timestamp` and an optional end
186
+ * `timestamp`. When both are available, `compute_elapsed_time()` derives
187
+ * the elapsed interval in milliseconds and microseconds.
254
188
  *
255
- * @param ts The `timespec` value to use as the begin timestamp.
256
- * @par Returns
257
- * Nothing.
258
- */
259
- void
260
- timestamp_begin (const timespec& ts) noexcept;
261
-
262
- /**
263
- * @brief Records the end timestamp using the current system clock.
189
+ * Typical usage in the framework:
190
+ * 1. Call `timestamp_begin()` just before the test suite or session
191
+ * body executes.
192
+ * 2. Call `timestamp_end()` immediately after it completes.
193
+ * 3. Pass the elapsed values to the reporter.
264
194
  *
265
- * @par Parameters
266
- * None.
267
- * @par Returns
268
- * Nothing.
269
- */
270
- void
271
- timestamp_end (void) noexcept;
272
-
273
- /**
274
- * @brief Records the end timestamp from a caller-supplied value.
195
+ * If the platform does not provide a monotonic clock, the `std::optional`
196
+ * members remain empty and `has_timestamps()` returns `false`, so that the
197
+ * reporter can skip timing output.
275
198
  *
276
- * @param ts The `timespec` value to use as the end timestamp.
277
- * @par Returns
278
- * Nothing.
279
- */
280
- void
281
- timestamp_end (const timespec& ts) noexcept;
282
-
283
- /**
284
- * @brief Returns true if the begin timestamp has been recorded.
199
+ * The class is non-copyable and non-movable to prevent accidental sharing
200
+ * of live timing state.
285
201
  *
286
- * @par Parameters
287
- * None.
288
- * @retval true `timestamp_begin()` has been called.
289
- * @retval false `timestamp_begin()` has not been called.
202
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
290
203
  */
291
- bool
292
- has_begin () const noexcept
204
+ class timestamps
293
205
  {
294
- return begin_time_.has_value ();
295
- }
296
-
297
- /**
298
- * @brief Returns true if the end timestamp has been recorded.
299
- *
300
- * @par Parameters
301
- * None.
302
- * @retval true `timestamp_end()` has been called.
303
- * @retval false `timestamp_end()` has not been called.
304
- */
305
- bool
306
- has_end () const noexcept
307
- {
308
- return end_time_.has_value ();
309
- }
310
-
311
- /**
312
- * @brief Returns true if both begin and end timestamps are available.
313
- *
314
- * @par Parameters
315
- * None.
316
- * @retval true Both timestamps are present and elapsed time can be
317
- * computed.
318
- * @retval false At least one timestamp is absent; elapsed time is not
319
- * available.
320
- */
321
- bool
322
- has_timestamps (void) const noexcept;
323
-
324
- /**
325
- * @brief Computes the elapsed time between begin and end timestamps.
326
- *
327
- * @param[out] milliseconds The elapsed time in whole milliseconds.
328
- * @param[out] microseconds The sub-millisecond remainder in microseconds.
329
- *
330
- * @details
331
- * Both output parameters are only valid when `has_timestamps()` returns
332
- * `true`. The caller is responsible for checking this precondition.
333
- */
334
- void
335
- compute_elapsed_time (uint32_t& milliseconds,
336
- uint32_t& microseconds) const;
337
-
338
- protected:
339
- /**
340
- * @brief The timestamp recorded at the beginning of the test suite.
341
- */
342
- std::optional<timestamp> begin_time_;
343
-
344
- /**
345
- * @brief The timestamp recorded at the end of the test suite.
346
- */
347
- std::optional<timestamp> end_time_;
348
- };
349
-
206
+ public:
207
+ /**
208
+ * @brief Default constructor. Both timestamps are uninitialised.
209
+ */
210
+ timestamps () = default;
211
+
212
+ /**
213
+ * @brief Deleted copy constructor to prevent copying.
214
+ */
215
+ timestamps (const timestamps&) = delete;
216
+
217
+ /**
218
+ * @brief Deleted move constructor to prevent moving.
219
+ */
220
+ timestamps (timestamps&&) = delete;
221
+
222
+ /**
223
+ * @brief Deleted copy assignment operator to prevent copying.
224
+ */
225
+ timestamps&
226
+ operator= (const timestamps&)
227
+ = delete;
228
+
229
+ /**
230
+ * @brief Deleted move assignment operator to prevent moving.
231
+ */
232
+ timestamps&
233
+ operator= (timestamps&&)
234
+ = delete;
235
+
236
+ /**
237
+ * @brief Defaulted destructor.
238
+ */
239
+ ~timestamps () = default;
240
+
241
+ /**
242
+ * @brief Records the begin timestamp using the current system clock.
243
+ *
244
+ * @par Parameters
245
+ * None.
246
+ * @par Returns
247
+ * Nothing.
248
+ */
249
+ void
250
+ timestamp_begin (void) noexcept;
251
+
252
+ /**
253
+ * @brief Records the begin timestamp from a caller-supplied value.
254
+ *
255
+ * @param ts The `timespec` value to use as the begin timestamp.
256
+ * @par Returns
257
+ * Nothing.
258
+ */
259
+ void
260
+ timestamp_begin (const timespec& ts) noexcept;
261
+
262
+ /**
263
+ * @brief Records the end timestamp using the current system clock.
264
+ *
265
+ * @par Parameters
266
+ * None.
267
+ * @par Returns
268
+ * Nothing.
269
+ */
270
+ void
271
+ timestamp_end (void) noexcept;
272
+
273
+ /**
274
+ * @brief Records the end timestamp from a caller-supplied value.
275
+ *
276
+ * @param ts The `timespec` value to use as the end timestamp.
277
+ * @par Returns
278
+ * Nothing.
279
+ */
280
+ void
281
+ timestamp_end (const timespec& ts) noexcept;
282
+
283
+ /**
284
+ * @brief Returns true if the begin timestamp has been recorded.
285
+ *
286
+ * @par Parameters
287
+ * None.
288
+ * @retval true `timestamp_begin()` has been called.
289
+ * @retval false `timestamp_begin()` has not been called.
290
+ */
291
+ bool
292
+ has_begin () const noexcept;
293
+
294
+ /**
295
+ * @brief Returns true if the end timestamp has been recorded.
296
+ *
297
+ * @par Parameters
298
+ * None.
299
+ * @retval true `timestamp_end()` has been called.
300
+ * @retval false `timestamp_end()` has not been called.
301
+ */
302
+ bool
303
+ has_end () const noexcept;
304
+
305
+ /**
306
+ * @brief Returns true if both begin and end timestamps are available.
307
+ *
308
+ * @par Parameters
309
+ * None.
310
+ * @retval true Both timestamps are present and elapsed time can be
311
+ * computed.
312
+ * @retval false At least one timestamp is absent; elapsed time is not
313
+ * available.
314
+ */
315
+ bool
316
+ has_timestamps (void) const noexcept;
317
+
318
+ /**
319
+ * @brief Computes the elapsed time between begin and end timestamps.
320
+ *
321
+ * @param[out] milliseconds The elapsed time in whole milliseconds.
322
+ * @param[out] microseconds The sub-millisecond remainder in
323
+ * microseconds.
324
+ */
325
+ void
326
+ compute_elapsed_time (uint32_t& milliseconds,
327
+ uint32_t& microseconds) const;
328
+
329
+ protected:
330
+ /**
331
+ * @brief The timestamp recorded at the beginning of the test suite.
332
+ */
333
+ std::optional<timestamp> begin_time_;
334
+
335
+ /**
336
+ * @brief The timestamp recorded at the end of the test suite.
337
+ */
338
+ std::optional<timestamp> end_time_;
339
+ };
340
+
341
+ // ------------------------------------------------------------------------
342
+ } // namespace detail
350
343
  // ==========================================================================
351
-
352
344
  } // namespace micro_os_plus::micro_test_plus
353
345
 
354
346
  #if defined(__GNUC__)
@@ -359,6 +351,11 @@ namespace micro_os_plus::micro_test_plus
359
351
 
360
352
  #endif // __cplusplus
361
353
 
354
+ // ============================================================================
355
+ // Templates & constexpr implementations.
356
+
357
+ #include "inlines/timings-inlines.h"
358
+
362
359
  // ----------------------------------------------------------------------------
363
360
 
364
361
  #endif // MICRO_TEST_PLUS_TIMINGS_H_