@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
@@ -1,304 +0,0 @@
1
- /*
2
- * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3
- * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software for any
6
- * purpose is hereby granted, under the terms of the MIT license.
7
- *
8
- * If a copy of the license was not distributed with this file, it can be
9
- * obtained from https://opensource.org/licenses/mit.
10
- *
11
- * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12
- * released under the terms of the Boost Version 1.0 Software License,
13
- * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14
- */
15
-
16
- // ----------------------------------------------------------------------------
17
-
18
- /**
19
- * @file
20
- * @brief C++ source file with implementations for the µTest++ test suite
21
- * methods.
22
- *
23
- * @details
24
- * This source file contains the core implementations for the test suite
25
- * facilities of the µTest++ framework. It provides the logic for constructing,
26
- * registering, and managing test suites and their associated test cases. The
27
- * implementation covers initialisation and clean-up routines, execution of
28
- * test suites and test cases, tracking of successful and failed checks, and
29
- * integration with the test reporter for structured output.
30
- *
31
- * The design ensures that test suites are non-copyable and non-movable,
32
- * maintaining unique ownership and consistent state. Flexible support for
33
- * callable objects enables a wide range of test suite definitions,
34
- * facilitating expressive and maintainable test organisation across embedded
35
- * and general C++ projects.
36
- *
37
- * All definitions reside within the `micro_os_plus::micro_test_plus`
38
- * namespace, ensuring clear separation from user code and minimising the risk
39
- * of naming conflicts.
40
- *
41
- * This file must be included when building the µTest++ library.
42
- */
43
-
44
- // ----------------------------------------------------------------------------
45
-
46
- #if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
47
- #include <micro-os-plus/config.h>
48
- #endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
49
-
50
- #include <micro-os-plus/micro-test-plus.h>
51
-
52
- #include <stdio.h>
53
-
54
- // ----------------------------------------------------------------------------
55
-
56
- #if defined(__clang__)
57
- #pragma clang diagnostic ignored "-Wc++98-compat"
58
- #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
59
- #endif
60
-
61
- namespace micro_os_plus::micro_test_plus
62
- {
63
- // --------------------------------------------------------------------------
64
-
65
- /**
66
- * @details
67
- * The constructor initialises a new instance of the `test_suite_base` class
68
- * with the specified name. It sets up the internal state required for
69
- * managing test cases within the suite. If tracing is enabled, the function
70
- * signature is output for diagnostic purposes. The default test suite does
71
- * not require explicit registration, ensuring seamless integration within
72
- * the µTest++ framework and supporting organised test management across all
73
- * files and folders.
74
- */
75
- test_suite_base::test_suite_base (const char* name)
76
- {
77
- #if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
78
- printf ("%s\n", __PRETTY_FUNCTION__);
79
- #endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
80
-
81
- name_ = name;
82
- // The default test suite needs no registration.
83
- }
84
-
85
- /**
86
- * @details
87
- * The destructor releases any resources associated with the
88
- * `test_suite_base` instance. It ensures that the test suite is properly
89
- * cleaned up after execution, supporting robust and reliable test management
90
- * across all files and folders within the µTest++ framework.
91
- */
92
- test_suite_base::~test_suite_base ()
93
- {
94
- }
95
-
96
- /**
97
- * @details
98
- * This method executes the test suite by invoking its associated callable
99
- * object. If tracing is enabled, the function signature is output for
100
- * diagnostic purposes. The method ensures that all test cases grouped within
101
- * the suite are executed in an organised manner, supporting comprehensive
102
- * and structured testing across all files and folders within the µTest++
103
- * framework.
104
- */
105
- void
106
- test_suite_base::run ()
107
- {
108
- #if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
109
- printf ("%s\n", __PRETTY_FUNCTION__);
110
- #endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
111
- }
112
-
113
- /**
114
- * @details
115
- * This method marks the beginning of a test suite's execution. It resets the
116
- * deferred begin flag and notifies the test reporter to start the suite,
117
- * passing the suite's name. This ensures that test suite output is clearly
118
- * delineated and properly initialised, supporting organised and readable
119
- * reporting across all test cases and folders.
120
- */
121
- void
122
- test_suite_base::begin_test_suite (void)
123
- {
124
- #if defined(_WIN32) || defined(CLOCK_MONOTONIC)
125
- #if defined(_WIN32)
126
- timespec_get (&begin_time, TIME_UTC);
127
- #else
128
- clock_gettime (CLOCK_MONOTONIC, &begin_time);
129
- #endif
130
- #endif
131
-
132
- process_deferred_begin = false;
133
-
134
- reporter->begin_test_suite (name_);
135
- }
136
-
137
- /**
138
- * @details
139
- * This method marks the end of a test suite's execution. If the suite's
140
- * start was deferred, it ensures the suite is properly begun before
141
- * finalising. The method then notifies the test reporter to conclude the
142
- * suite, passing a reference to the suite instance. This guarantees that all
143
- * results are accurately summarised and reported, supporting clear and
144
- * organised test management across all test cases and folders.
145
- */
146
- void
147
- test_suite_base::end_test_suite (void)
148
- {
149
- if (process_deferred_begin)
150
- {
151
- reporter->begin_test (runner.test_suites_count ());
152
-
153
- begin_test_suite ();
154
- }
155
-
156
- #if defined(_WIN32) || defined(CLOCK_MONOTONIC)
157
- #if defined(_WIN32)
158
- timespec_get (&end_time, TIME_UTC);
159
- #else
160
- clock_gettime (CLOCK_MONOTONIC, &end_time);
161
- #endif
162
- #endif
163
- reporter->end_test_suite (*this);
164
- }
165
-
166
- /**
167
- * @details
168
- * This method marks the beginning of a test case within the suite. If the
169
- * start of the suite was deferred, it ensures the suite is properly begun
170
- * before proceeding. The method sets the current test case name, increments
171
- * the total number of test cases, resets the current test case statistics,
172
- * and notifies the test reporter to begin the test case. This approach
173
- * guarantees that each test case is clearly identified, accurately tracked,
174
- * and properly reported across all test cases and folders.
175
- */
176
- void
177
- test_suite_base::begin_test_case (const char* name)
178
- {
179
- if (process_deferred_begin)
180
- {
181
- reporter->begin_test (runner.test_suites_count ());
182
-
183
- begin_test_suite ();
184
- }
185
-
186
- test_case_name_ = name;
187
- ++test_cases_count_;
188
-
189
- current_test_case = {};
190
-
191
- reporter->begin_test_case (test_case_name_);
192
- }
193
-
194
- /**
195
- * @details
196
- * This method marks the end of a test case within the suite. It notifies the
197
- * test reporter to conclude the test case, passing the current test case
198
- * name. This ensures that the results of the test case are accurately
199
- * finalised and clearly reported, supporting organised and reliable test
200
- * management across all test cases and folders.
201
- */
202
- void
203
- test_suite_base::end_test_case (void)
204
- {
205
- reporter->end_test_case (test_case_name_);
206
- }
207
-
208
- /**
209
- * @details
210
- * This method increments the count of successful checks for the test suite
211
- * and the current test case. It ensures that each passing assertion is
212
- * accurately recorded, supporting precise tracking and reporting of test
213
- * outcomes across all test cases and folders.
214
- */
215
- void
216
- test_suite_base::increment_successful (void)
217
- {
218
- ++successful_checks_;
219
- ++current_test_case.successful_checks;
220
- }
221
-
222
- /**
223
- * @details
224
- * This method increments the count of failed checks for the test suite and
225
- * the current test case. It ensures that each failing assertion is
226
- * accurately recorded, supporting precise tracking and reporting of test
227
- * outcomes across all test cases and folders.
228
- */
229
- void
230
- test_suite_base::increment_failed (void)
231
- {
232
- ++failed_checks_;
233
- ++current_test_case.failed_checks;
234
- }
235
-
236
- #if defined(_WIN32) || defined(CLOCK_MONOTONIC)
237
- /**
238
- * @details
239
- * Subtracts `begin_time` from `end_time` using monotonic clock arithmetic,
240
- * handling the nanosecond borrow correctly, then splits the result into
241
- * whole milliseconds and the sub-millisecond remainder expressed in
242
- * microseconds (0–999).
243
- */
244
- #pragma GCC diagnostic push
245
- #pragma GCC diagnostic ignored "-Wshadow"
246
- void
247
- test_suite_base::compute_elapsed_time (timespec& begin_time,
248
- timespec& end_time,
249
- long& milliseconds,
250
- long& microseconds)
251
- {
252
- long long delta_ns = end_time.tv_nsec - begin_time.tv_nsec;
253
- long long delta_s = end_time.tv_sec - begin_time.tv_sec;
254
- if (delta_ns < 0)
255
- {
256
- delta_ns += 1000000000LL;
257
- --delta_s;
258
- }
259
-
260
- // Split into milliseconds and microseconds.
261
- const long long total_us = delta_s * 1000000LL + delta_ns / 1000LL;
262
- milliseconds = static_cast<long> (total_us / 1000LL);
263
- microseconds = static_cast<long> (total_us % 1000LL);
264
- }
265
- #pragma GCC diagnostic pop
266
-
267
- #endif
268
-
269
- // ==========================================================================
270
-
271
- /**
272
- * @details
273
- * This method executes the test suite by invoking the stored callable object
274
- * associated with the suite. It ensures that all test cases registered
275
- * within the suite are executed in sequence, supporting comprehensive and
276
- * structured testing across all files and folders within the µTest++
277
- * framework.
278
- */
279
- void
280
- test_suite::run (void)
281
- {
282
- // Run the test suite function prepared with std::bin();
283
- callable_ ();
284
- }
285
-
286
- /**
287
- * @details
288
- * The destructor releases any resources associated with the `test_suite`
289
- * instance. If tracing is enabled, it outputs the function signature for
290
- * diagnostic purposes. This ensures that the test suite is properly cleaned
291
- * up after execution, supporting robust and reliable test management across
292
- * all files and folders within the µTest++ framework.
293
- */
294
- test_suite::~test_suite ()
295
- {
296
- #if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
297
- printf ("%s\n", __PRETTY_FUNCTION__);
298
- #endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
299
- }
300
-
301
- // --------------------------------------------------------------------------
302
- } // namespace micro_os_plus::micro_test_plus
303
-
304
- // ----------------------------------------------------------------------------