@micro-os-plus/micro-test-plus 4.0.0 → 4.1.1

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 +95 -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 +202 -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 +30 -52
  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
@@ -60,193 +60,174 @@ namespace micro_os_plus::micro_test_plus
60
60
  {
61
61
  // --------------------------------------------------------------------------
62
62
 
63
- /**
64
- * @brief Aggregated pass/fail/subtest counters for a node in the test tree.
65
- *
66
- * @details
67
- * `runner_totals` records three counters that are maintained throughout a
68
- * test session:
69
- * - the number of checks that passed (`successful_checks_`),
70
- * - the number of checks that failed (`failed_checks_`), and
71
- * - the number of subtests that were executed (`executed_subtests_`).
72
- *
73
- * Every `test_node`-derived object (`runner`, `suite`, `subtest`) owns a
74
- * `runner_totals` member and accumulates its counts in place. At the end
75
- * of each suite or session the operator `+=` propagates the child totals
76
- * up to the parent node.
77
- *
78
- * The class is non-copyable and non-movable to prevent accidental
79
- * duplication of live counters.
80
- *
81
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
82
- */
83
- class runner_totals
63
+ namespace detail
84
64
  {
85
- public:
86
- /**
87
- * @brief Default constructor. All counters are zero-initialised.
88
- */
89
- runner_totals () = default;
90
-
91
- /**
92
- * @brief Deleted copy constructor to prevent copying.
93
- */
94
- runner_totals (const runner_totals&) = delete;
95
-
96
- /**
97
- * @brief Deleted move constructor to prevent moving.
98
- */
99
- runner_totals (runner_totals&&) = delete;
100
-
101
- /**
102
- * @brief Deleted copy assignment operator to prevent copying.
103
- */
104
- runner_totals&
105
- operator= (const runner_totals&) = delete;
106
-
107
- /**
108
- * @brief Deleted move assignment operator to prevent moving.
109
- */
110
- runner_totals&
111
- operator= (runner_totals&&) = delete;
112
-
113
- /**
114
- * @brief Accumulates the totals from another instance into this one.
115
- *
116
- * @param other The instance whose totals are to be added.
117
- * @return Reference to this instance.
118
- */
119
- runner_totals&
120
- operator+= (const runner_totals& other) noexcept;
121
-
122
- /**
123
- * @brief Increments the successful-checks counter.
124
- *
125
- * @param count The number of successful checks to add (default 1).
126
- * @par Returns
127
- * Nothing.
128
- */
129
- void
130
- increment_successful_checks (size_t count = 1) noexcept
131
- {
132
- successful_checks_ += count;
133
- }
134
-
135
- /**
136
- * @brief Increments the failed-checks counter.
137
- *
138
- * @param count The number of failed checks to add (default 1).
139
- * @par Returns
140
- * Nothing.
141
- */
142
- void
143
- increment_failed_checks (size_t count = 1) noexcept
144
- {
145
- failed_checks_ += count;
146
- }
147
-
148
- /**
149
- * @brief Increments the executed-subtests counter.
150
- *
151
- * @param count The number of subtests to add (default 1).
152
- * @par Returns
153
- * Nothing.
154
- */
155
- void
156
- increment_executed_subtests (size_t count = 1) noexcept
157
- {
158
- executed_subtests_ += count;
159
- }
65
+ // ========================================================================
160
66
 
161
67
  /**
162
- * @brief Returns the number of checks that passed.
68
+ * @brief Aggregated pass/fail/subtest counters for a node in the test
69
+ * tree.
163
70
  *
164
- * @par Parameters
165
- * None.
166
- * @return The cumulative count of successful checks.
167
- */
168
- [[nodiscard]] size_t
169
- successful_checks () const noexcept
170
- {
171
- return successful_checks_;
172
- }
173
-
174
- /**
175
- * @brief Returns the number of checks that failed.
71
+ * @details
72
+ * `runner_totals` records three counters that are maintained throughout a
73
+ * test session:
74
+ * - the number of checks that passed (`successful_checks_`),
75
+ * - the number of checks that failed (`failed_checks_`), and
76
+ * - the number of subtests that were executed (`executed_subtests_`).
176
77
  *
177
- * @par Parameters
178
- * None.
179
- * @return The cumulative count of failed checks.
180
- */
181
- [[nodiscard]] size_t
182
- failed_checks () const noexcept
183
- {
184
- return failed_checks_;
185
- }
186
-
187
- /**
188
- * @brief Returns the total number of checks executed.
78
+ * Every `test_node`-derived object (`runner`, `suite`, `subtest`) owns a
79
+ * `runner_totals` member and accumulates its counts in place. At the end
80
+ * of each suite or session the operator `+=` propagates the child totals
81
+ * up to the parent node.
189
82
  *
190
- * @par Parameters
191
- * None.
192
- * @return The sum of successful and failed checks.
193
- */
194
- [[nodiscard]] size_t
195
- executed_checks () const noexcept
196
- {
197
- return successful_checks_ + failed_checks_;
198
- }
199
-
200
- /**
201
- * @brief Returns the number of subtests that were executed.
83
+ * The class is non-copyable and non-movable to prevent accidental
84
+ * duplication of live counters.
202
85
  *
203
- * @par Parameters
204
- * None.
205
- * @return The cumulative count of executed subtests.
86
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
206
87
  */
207
- [[nodiscard]] size_t
208
- executed_subtests () const noexcept
88
+ class runner_totals
209
89
  {
210
- return executed_subtests_;
211
- }
212
-
213
- /**
214
- * @brief Checks whether all executed checks were successful.
215
- *
216
- * @par Parameters
217
- * None.
218
- * @retval true No checks failed.
219
- * @retval false At least one check failed.
220
- *
221
- * @details
222
- * A runner with no checks at all is considered successful, as it
223
- * did not fail any check.
224
- */
225
- [[nodiscard]] bool
226
- was_successful (void) const noexcept
227
- {
228
- return failed_checks_ == 0;
229
- }
230
-
231
- protected:
232
- /**
233
- * @brief Total number of successful checks.
234
- */
235
- size_t successful_checks_ = 0;
236
-
237
- /**
238
- * @brief Total number of failed checks.
239
- */
240
- size_t failed_checks_ = 0;
241
-
242
- /**
243
- * @brief Total number of tests executed.
244
- */
245
- size_t executed_subtests_ = 0;
246
- };
90
+ public:
91
+ /**
92
+ * @brief Default constructor. All counters are zero-initialised.
93
+ */
94
+ runner_totals () = default;
95
+
96
+ /**
97
+ * @brief Deleted copy constructor to prevent copying.
98
+ */
99
+ runner_totals (const runner_totals&) = delete;
100
+
101
+ /**
102
+ * @brief Deleted move constructor to prevent moving.
103
+ */
104
+ runner_totals (runner_totals&&) = delete;
105
+
106
+ /**
107
+ * @brief Deleted copy assignment operator to prevent copying.
108
+ */
109
+ runner_totals&
110
+ operator= (const runner_totals&)
111
+ = delete;
112
+
113
+ /**
114
+ * @brief Deleted move assignment operator to prevent moving.
115
+ */
116
+ runner_totals&
117
+ operator= (runner_totals&&)
118
+ = delete;
119
+
120
+ /**
121
+ * @brief Accumulates the totals from another instance into this one.
122
+ *
123
+ * @param other The instance whose totals are to be added.
124
+ * @return Reference to this instance.
125
+ */
126
+ runner_totals&
127
+ operator+= (const runner_totals& other) noexcept;
128
+
129
+ /**
130
+ * @brief Increments the successful-checks counter.
131
+ *
132
+ * @param count The number of successful checks to add (default 1).
133
+ * @par Returns
134
+ * Nothing.
135
+ */
136
+ void
137
+ increment_successful_checks (size_t count = 1) noexcept;
138
+
139
+ /**
140
+ * @brief Increments the failed-checks counter.
141
+ *
142
+ * @param count The number of failed checks to add (default 1).
143
+ * @par Returns
144
+ * Nothing.
145
+ */
146
+ void
147
+ increment_failed_checks (size_t count = 1) noexcept;
148
+
149
+ /**
150
+ * @brief Increments the executed-subtests counter.
151
+ *
152
+ * @param count The number of subtests to add (default 1).
153
+ * @par Returns
154
+ * Nothing.
155
+ */
156
+ void
157
+ increment_executed_subtests (size_t count = 1) noexcept;
158
+
159
+ /**
160
+ * @brief Returns the number of checks that passed.
161
+ *
162
+ * @par Parameters
163
+ * None.
164
+ * @return The cumulative count of successful checks.
165
+ */
166
+ [[nodiscard]] size_t
167
+ successful_checks () const noexcept;
168
+
169
+ /**
170
+ * @brief Returns the number of checks that failed.
171
+ *
172
+ * @par Parameters
173
+ * None.
174
+ * @return The cumulative count of failed checks.
175
+ */
176
+ [[nodiscard]] size_t
177
+ failed_checks () const noexcept;
178
+
179
+ /**
180
+ * @brief Returns the total number of checks executed.
181
+ *
182
+ * @par Parameters
183
+ * None.
184
+ * @return The sum of successful and failed checks.
185
+ */
186
+ [[nodiscard]] size_t
187
+ executed_checks () const noexcept;
188
+
189
+ /**
190
+ * @brief Returns the number of subtests that were executed.
191
+ *
192
+ * @par Parameters
193
+ * None.
194
+ * @return The cumulative count of executed subtests.
195
+ */
196
+ [[nodiscard]] size_t
197
+ executed_subtests () const noexcept;
198
+
199
+ /**
200
+ * @brief Checks whether all executed checks were successful.
201
+ *
202
+ * @par Parameters
203
+ * None.
204
+ * @retval true No checks failed.
205
+ * @retval false At least one check failed.
206
+ */
207
+ [[nodiscard]] bool
208
+ was_successful (void) const noexcept;
209
+
210
+ protected:
211
+ /**
212
+ * @brief Total number of successful checks.
213
+ */
214
+ size_t successful_checks_ = 0;
215
+
216
+ /**
217
+ * @brief Total number of failed checks.
218
+ */
219
+ size_t failed_checks_ = 0;
220
+
221
+ /**
222
+ * @brief Total number of tests executed.
223
+ */
224
+ size_t executed_subtests_ = 0;
225
+ };
226
+
227
+ // ------------------------------------------------------------------------
228
+ } // namespace detail
247
229
 
248
230
  // --------------------------------------------------------------------------
249
-
250
231
  } // namespace micro_os_plus::micro_test_plus
251
232
 
252
233
  #if defined(__GNUC__)
@@ -257,6 +238,11 @@ namespace micro_os_plus::micro_test_plus
257
238
 
258
239
  #endif // __cplusplus
259
240
 
241
+ // ============================================================================
242
+ // Templates & constexpr implementations.
243
+
244
+ #include "inlines/runner-totals-inlines.h"
245
+
260
246
  // ----------------------------------------------------------------------------
261
247
 
262
248
  #endif // MICRO_TEST_PLUS_TEST_RUNNER_TOTALS_H_
@@ -53,10 +53,11 @@
53
53
 
54
54
  #include <functional>
55
55
  #include <memory>
56
+ #include <string>
56
57
 
57
- #include "reporter.h"
58
58
  #include "timings.h"
59
59
  #include "test.h"
60
+ #include "reflection.h"
60
61
 
61
62
  // ----------------------------------------------------------------------------
62
63
 
@@ -78,6 +79,12 @@ namespace micro_os_plus::micro_test_plus
78
79
  {
79
80
  // --------------------------------------------------------------------------
80
81
 
82
+ class suite;
83
+ class top_suite;
84
+ class reporter;
85
+
86
+ // ==========================================================================
87
+
81
88
  /**
82
89
  * @ingroup micro-test-plus-runners
83
90
  * @brief The test runner for the µTest++ framework.
@@ -100,14 +107,24 @@ namespace micro_os_plus::micro_test_plus
100
107
  *
101
108
  * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
102
109
  */
103
- class runner : public test_node
110
+ class runner : public detail::test_node
104
111
  {
105
112
  public:
106
113
  /**
107
- * @brief Default constructor for the runner class.
114
+ * @brief Constructor for the runner class.
108
115
  *
109
- * @details
110
- * The rule of five is enforced to prevent accidental copying or moving.
116
+ * @par Parameters
117
+ * None.
118
+ */
119
+ runner (void);
120
+
121
+ /**
122
+ * @brief Deprecated constructor for the runner class.
123
+ *
124
+ * @param [in] top_suite_name The name given to the implicit top suite.
125
+ * Defaults to an empty string.
126
+ *
127
+ * @deprecated Use the anonymous constructor.
111
128
  */
112
129
  runner (const char* top_suite_name);
113
130
 
@@ -125,13 +142,15 @@ namespace micro_os_plus::micro_test_plus
125
142
  * @brief Deleted copy assignment operator to prevent copying.
126
143
  */
127
144
  runner&
128
- operator= (const runner&) = delete;
145
+ operator= (const runner&)
146
+ = delete;
129
147
 
130
148
  /**
131
149
  * @brief Deleted move assignment operator to prevent moving.
132
150
  */
133
151
  runner&
134
- operator= (runner&&) = delete;
152
+ operator= (runner&&)
153
+ = delete;
135
154
 
136
155
  /**
137
156
  * @brief Destructor for the runner class.
@@ -143,10 +162,12 @@ namespace micro_os_plus::micro_test_plus
143
162
  *
144
163
  * @param argc The argument count from main().
145
164
  * @param argv The argument vector from main().
165
+ * @param top_suite_name The name given to the implicit top suite. Defaults
166
+ * to an empty string.
146
167
  * @return Reference to the top-level test suite.
147
168
  */
148
169
  class suite&
149
- initialise (int argc, char* argv[]);
170
+ initialise (int argc, char* argv[], const char* top_suite_name = "");
150
171
 
151
172
  /**
152
173
  * @brief Returns 0 if all tests were successful, 1 otherwise.
@@ -195,11 +216,6 @@ namespace micro_os_plus::micro_test_plus
195
216
  /**
196
217
  * @brief Returns the total count of registered test suites.
197
218
  *
198
- * @details
199
- * The base implementation counts only the dynamically registered child
200
- * suites plus the implicit top suite. `static_runner` overrides this
201
- * method to also include statically registered suites.
202
- *
203
219
  * @par Parameters
204
220
  * None.
205
221
  * @return The total number of test suites managed by this runner.
@@ -212,14 +228,10 @@ namespace micro_os_plus::micro_test_plus
212
228
  *
213
229
  * @par Parameters
214
230
  * None.
215
- * @par Returns
216
- * Reference to the test reporter.
231
+ * @return Reference to the test reporter.
217
232
  */
218
233
  [[nodiscard]] class reporter&
219
- reporter (void) const noexcept
220
- {
221
- return *reporter_;
222
- }
234
+ reporter (void) const noexcept;
223
235
 
224
236
  /**
225
237
  * @brief Gets the timings for this runner.
@@ -228,11 +240,8 @@ namespace micro_os_plus::micro_test_plus
228
240
  * None.
229
241
  * @return A reference to the timestamps instance.
230
242
  */
231
- [[nodiscard]] timestamps&
232
- timings () noexcept
233
- {
234
- return timings_;
235
- }
243
+ [[nodiscard]] detail::timestamps&
244
+ timings () noexcept;
236
245
 
237
246
  /**
238
247
  * @brief Gets the timings for this runner (const overload).
@@ -241,11 +250,8 @@ namespace micro_os_plus::micro_test_plus
241
250
  * None.
242
251
  * @return A const reference to the timestamps instance.
243
252
  */
244
- [[nodiscard]] const timestamps&
245
- timings () const noexcept
246
- {
247
- return timings_;
248
- }
253
+ [[nodiscard]] const detail::timestamps&
254
+ timings () const noexcept;
249
255
 
250
256
  /**
251
257
  * @brief Returns the count of test suites.
@@ -261,11 +267,6 @@ namespace micro_os_plus::micro_test_plus
261
267
  /**
262
268
  * @brief Runs all registered test suites.
263
269
  *
264
- * @details
265
- * The base implementation runs all dynamically registered child suites.
266
- * `static_runner` overrides this method to additionally run all
267
- * statically registered suites.
268
- *
269
270
  * @par Parameters
270
271
  * None.
271
272
  */
@@ -307,7 +308,12 @@ namespace micro_os_plus::micro_test_plus
307
308
  /**
308
309
  * @brief Timings for this runner.
309
310
  */
310
- timestamps timings_;
311
+ detail::timestamps timings_;
312
+
313
+ /**
314
+ * @brief Owned storage for the implicit top-suite name.
315
+ */
316
+ std::string top_suite_name_;
311
317
  };
312
318
 
313
319
  // ==========================================================================
@@ -338,10 +344,21 @@ namespace micro_os_plus::micro_test_plus
338
344
  class static_runner final : public runner
339
345
  {
340
346
  public:
347
+ /**
348
+ * @brief Constructor for the runner class.
349
+ *
350
+ * @par Parameters
351
+ * None.
352
+ */
353
+ static_runner (void);
354
+
341
355
  /**
342
356
  * @brief Constructs the static runner with a top-suite name.
343
357
  *
344
358
  * @param top_suite_name The name of the implicit top-level suite.
359
+ * Defaults to an empty string.
360
+ *
361
+ * @deprecated Use the anonymous constructor.
345
362
  */
346
363
  static_runner (const char* top_suite_name);
347
364
 
@@ -359,13 +376,15 @@ namespace micro_os_plus::micro_test_plus
359
376
  * @brief Deleted copy assignment operator to prevent copying.
360
377
  */
361
378
  static_runner&
362
- operator= (const static_runner&) = delete;
379
+ operator= (const static_runner&)
380
+ = delete;
363
381
 
364
382
  /**
365
383
  * @brief Deleted move assignment operator to prevent moving.
366
384
  */
367
385
  static_runner&
368
- operator= (static_runner&&) = delete;
386
+ operator= (static_runner&&)
387
+ = delete;
369
388
 
370
389
  /**
371
390
  * @brief Destructor for the static_runner class.
@@ -408,11 +427,6 @@ namespace micro_os_plus::micro_test_plus
408
427
  /**
409
428
  * @brief Runs all child suites, including statically registered ones.
410
429
  *
411
- * @details
412
- * Overrides `runner::run_suites_()` to first invoke the base
413
- * implementation (dynamic suites), then iterate over all statically
414
- * registered suites and run them.
415
- *
416
430
  * @par Parameters
417
431
  * None.
418
432
  */
@@ -446,6 +460,11 @@ namespace micro_os_plus::micro_test_plus
446
460
 
447
461
  #endif // __cplusplus
448
462
 
463
+ // ============================================================================
464
+ // Templates & constexpr implementations.
465
+
466
+ #include "inlines/runner-inlines.h"
467
+
449
468
  // ----------------------------------------------------------------------------
450
469
 
451
470
  #endif // MICRO_TEST_PLUS_TEST_RUNNER_H_