@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
@@ -0,0 +1,363 @@
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
+ namespace detail
75
+ {
76
+ // ========================================================================
77
+
78
+ /**
79
+ * @brief A single point-in-time measurement, wrapping a `timespec` value.
80
+ *
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.
86
+ *
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.
90
+ *
91
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
92
+ */
93
+ class timestamp
94
+ {
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
+ // ========================================================================
180
+
181
+ /**
182
+ * @brief A begin/end timestamp pair used to measure elapsed time.
183
+ *
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.
188
+ *
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.
194
+ *
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.
198
+ *
199
+ * The class is non-copyable and non-movable to prevent accidental sharing
200
+ * of live timing state.
201
+ *
202
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
203
+ */
204
+ class timestamps
205
+ {
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
343
+ // ==========================================================================
344
+ } // namespace micro_os_plus::micro_test_plus
345
+
346
+ #if defined(__GNUC__)
347
+ #pragma GCC diagnostic pop
348
+ #endif
349
+
350
+ // ----------------------------------------------------------------------------
351
+
352
+ #endif // __cplusplus
353
+
354
+ // ============================================================================
355
+ // Templates & constexpr implementations.
356
+
357
+ #include "inlines/timings-inlines.h"
358
+
359
+ // ----------------------------------------------------------------------------
360
+
361
+ #endif // MICRO_TEST_PLUS_TIMINGS_H_
362
+
363
+ // ----------------------------------------------------------------------------