@micro-os-plus/micro-test-plus 3.3.1 → 4.0.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 (53) hide show
  1. package/CHANGELOG.md +330 -2
  2. package/CMakeLists.txt +79 -23
  3. package/README.md +1 -1
  4. package/config/xcdl-build.json +11 -4
  5. package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +292 -0
  6. package/include/micro-os-plus/micro-test-plus/detail.h +462 -1076
  7. package/include/micro-os-plus/micro-test-plus/exceptions.h +126 -0
  8. package/include/micro-os-plus/micro-test-plus/function-comparators.h +10 -7
  9. package/include/micro-os-plus/micro-test-plus/inlines/{details-inlines.h → deferred-reporter-inlines.h} +49 -22
  10. package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +67 -4
  11. package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +3 -6
  12. package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +21 -15
  13. package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +35 -17
  14. package/include/micro-os-plus/micro-test-plus/inlines/{test-reporter-inlines.h → reporter-inlines.h} +176 -106
  15. package/include/micro-os-plus/micro-test-plus/inlines/{test-suite-inlines.h → runner-inlines.h} +41 -43
  16. package/include/micro-os-plus/micro-test-plus/inlines/test-inlines.h +369 -0
  17. package/include/micro-os-plus/micro-test-plus/inlines/utility-inlines.h +126 -0
  18. package/include/micro-os-plus/micro-test-plus/literals.h +4 -3
  19. package/include/micro-os-plus/micro-test-plus/math.h +9 -6
  20. package/include/micro-os-plus/micro-test-plus/operators.h +38 -44
  21. package/include/micro-os-plus/micro-test-plus/reflection.h +15 -4
  22. package/include/micro-os-plus/micro-test-plus/{test-reporter-basic.h → reporter-human.h} +72 -72
  23. package/include/micro-os-plus/micro-test-plus/{test-reporter-tap.h → reporter-tap.h} +69 -69
  24. package/include/micro-os-plus/micro-test-plus/{test-reporter.h → reporter.h} +296 -200
  25. package/include/micro-os-plus/micro-test-plus/runner-totals.h +264 -0
  26. package/include/micro-os-plus/micro-test-plus/runner.h +453 -0
  27. package/include/micro-os-plus/micro-test-plus/test.h +1069 -0
  28. package/include/micro-os-plus/micro-test-plus/timings.h +366 -0
  29. package/include/micro-os-plus/micro-test-plus/type-traits.h +239 -545
  30. package/include/micro-os-plus/micro-test-plus/utility.h +135 -0
  31. package/include/micro-os-plus/micro-test-plus.h +25 -228
  32. package/meson.build +10 -6
  33. package/package.json +1 -1
  34. package/src/deferred-reporter.cpp +118 -0
  35. package/src/reflection.cpp +95 -0
  36. package/src/reporter-human.cpp +822 -0
  37. package/src/reporter-tap.cpp +782 -0
  38. package/src/reporter.cpp +676 -0
  39. package/src/runner-totals.cpp +95 -0
  40. package/src/runner.cpp +563 -0
  41. package/src/test.cpp +496 -0
  42. package/src/timings.cpp +209 -0
  43. package/src/utility.cpp +163 -0
  44. package/.cmake-format.yaml +0 -11
  45. package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +0 -313
  46. package/include/micro-os-plus/micro-test-plus/test-runner.h +0 -281
  47. package/include/micro-os-plus/micro-test-plus/test-suite.h +0 -492
  48. package/src/micro-test-plus.cpp +0 -316
  49. package/src/test-reporter-basic.cpp +0 -466
  50. package/src/test-reporter-tap.cpp +0 -530
  51. package/src/test-reporter.cpp +0 -399
  52. package/src/test-runner.cpp +0 -311
  53. package/src/test-suite.cpp +0 -304
@@ -0,0 +1,366 @@
1
+
2
+ // ----------------------------------------------------------------------------
3
+ /*
4
+ * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
5
+ * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose is hereby granted, under the terms of the MIT license.
9
+ *
10
+ * If a copy of the license was not distributed with this file, it can be
11
+ * obtained from https://opensource.org/licenses/mit.
12
+ */
13
+
14
+ // ----------------------------------------------------------------------------
15
+
16
+ /**
17
+ * @file
18
+ * @brief C++ header file with declarations for the µTest++ timing utilities.
19
+ *
20
+ * @details
21
+ * This header provides two lightweight classes used to measure the elapsed
22
+ * time of test suites and test sessions within the µTest++ framework:
23
+ *
24
+ * - `timestamp` wraps a single `timespec` value and records one point in
25
+ * time. It is default-constructible and trivially copyable.
26
+ * - `timestamps` pairs a begin and an end `timestamp` (both stored as
27
+ * `std::optional<timestamp>`) and exposes methods for recording the
28
+ * start and finish of an operation, querying whether both timestamps are
29
+ * available, and computing the elapsed time in milliseconds and
30
+ * microseconds.
31
+ *
32
+ * Timing support relies on `clock_gettime(CLOCK_MONOTONIC_RAW, ...)` when
33
+ * available; if the clock is not present (e.g. on bare-metal targets without
34
+ * an RTC) the timestamps are simply omitted and no timing information is
35
+ * reported.
36
+ *
37
+ * All definitions reside within the `micro_os_plus::micro_test_plus`
38
+ * namespace, ensuring clear separation from user code and minimising the
39
+ * risk of naming conflicts.
40
+ *
41
+ * This file is intended solely for internal use within the framework and
42
+ * should not be included directly by user code.
43
+ */
44
+
45
+ #ifndef MICRO_TEST_PLUS_TIMINGS_H_
46
+ #define MICRO_TEST_PLUS_TIMINGS_H_
47
+
48
+ // ----------------------------------------------------------------------------
49
+
50
+ #ifdef __cplusplus
51
+
52
+ // ----------------------------------------------------------------------------
53
+
54
+ #include <cstdint>
55
+ #include <optional>
56
+ #include <ctime>
57
+
58
+ // ----------------------------------------------------------------------------
59
+
60
+ #if defined(__GNUC__)
61
+ #pragma GCC diagnostic push
62
+ #if defined(__clang__)
63
+ #pragma clang diagnostic ignored "-Wc++98-compat"
64
+ #pragma clang diagnostic ignored "-Wpre-c++17-compat"
65
+ #endif
66
+ #endif
67
+
68
+ // ===========================================================================
69
+
70
+ namespace micro_os_plus::micro_test_plus
71
+ {
72
+
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
91
+ {
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;
136
+
137
+ /**
138
+ * @brief Returns true if a monotonic clock is available on this target.
139
+ *
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.
150
+ *
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.
163
+ *
164
+ * @par Parameters
165
+ * None.
166
+ * @return A const reference to the stored `timespec`.
167
+ */
168
+ [[nodiscard]] const timespec&
169
+ value () const noexcept
170
+ {
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;
223
+
224
+ /**
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.
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
+ 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
+
350
+ // ==========================================================================
351
+
352
+ } // namespace micro_os_plus::micro_test_plus
353
+
354
+ #if defined(__GNUC__)
355
+ #pragma GCC diagnostic pop
356
+ #endif
357
+
358
+ // ----------------------------------------------------------------------------
359
+
360
+ #endif // __cplusplus
361
+
362
+ // ----------------------------------------------------------------------------
363
+
364
+ #endif // MICRO_TEST_PLUS_TIMINGS_H_
365
+
366
+ // ----------------------------------------------------------------------------