@micro-os-plus/micro-test-plus 3.2.2 → 3.3.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 (45) hide show
  1. package/.cmake-format.yaml +11 -0
  2. package/CHANGELOG.md +417 -2
  3. package/CMakeLists.txt +33 -30
  4. package/LICENSE +1 -1
  5. package/README.md +1 -1
  6. package/{xcdl.json → config/xcdl-build.json} +6 -6
  7. package/include/micro-os-plus/micro-test-plus/detail.h +1908 -0
  8. package/include/micro-os-plus/micro-test-plus/function-comparators.h +333 -0
  9. package/include/micro-os-plus/micro-test-plus/inlines/details-inlines.h +172 -0
  10. package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +341 -0
  11. package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +604 -0
  12. package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +315 -0
  13. package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +313 -0
  14. package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +170 -0
  15. package/include/micro-os-plus/micro-test-plus/inlines/test-reporter-inlines.h +476 -0
  16. package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +115 -0
  17. package/include/micro-os-plus/micro-test-plus/literals.h +912 -0
  18. package/include/micro-os-plus/micro-test-plus/math.h +217 -0
  19. package/include/micro-os-plus/micro-test-plus/operators.h +514 -0
  20. package/include/micro-os-plus/micro-test-plus/reflection.h +233 -0
  21. package/include/micro-os-plus/micro-test-plus/test-reporter-basic.h +289 -0
  22. package/include/micro-os-plus/micro-test-plus/test-reporter-tap.h +281 -0
  23. package/include/micro-os-plus/micro-test-plus/test-reporter.h +846 -0
  24. package/include/micro-os-plus/micro-test-plus/test-runner.h +281 -0
  25. package/include/micro-os-plus/micro-test-plus/test-suite.h +492 -0
  26. package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
  27. package/include/micro-os-plus/micro-test-plus.h +172 -552
  28. package/meson.build +7 -5
  29. package/package.json +29 -34
  30. package/src/micro-test-plus.cpp +134 -37
  31. package/src/test-reporter-basic.cpp +466 -0
  32. package/src/test-reporter-tap.cpp +530 -0
  33. package/src/test-reporter.cpp +207 -240
  34. package/src/test-runner.cpp +135 -23
  35. package/src/test-suite.cpp +182 -10
  36. package/include/micro-os-plus/detail.h +0 -765
  37. package/include/micro-os-plus/inlines.h +0 -209
  38. package/include/micro-os-plus/literals.h +0 -512
  39. package/include/micro-os-plus/math.h +0 -204
  40. package/include/micro-os-plus/reflection.h +0 -139
  41. package/include/micro-os-plus/test-reporter-inlines.h +0 -230
  42. package/include/micro-os-plus/test-reporter.h +0 -356
  43. package/include/micro-os-plus/test-runner.h +0 -132
  44. package/include/micro-os-plus/test-suite.h +0 -306
  45. package/include/micro-os-plus/type-traits.h +0 -389
@@ -0,0 +1,233 @@
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++ header file with declarations for the µTest++ reflection
21
+ * utilities.
22
+ *
23
+ * @details
24
+ * This header provides the declarations for the reflection utilities used
25
+ * within the µTest++ framework. It defines interfaces for obtaining source
26
+ * location information and extracting type names at compile time, supporting
27
+ * advanced diagnostics and reporting capabilities.
28
+ *
29
+ * The reflection utilities include a local implementation of `source_location`
30
+ * for environments lacking C++20 standard support, as well as functions for
31
+ * extracting concise type names using compiler-specific macros such as
32
+ * `__PRETTY_FUNCTION__`. These facilities enable precise identification of
33
+ * code locations and types in test reports, enhancing the clarity and
34
+ * professionalism of diagnostic output.
35
+ *
36
+ * All definitions reside within the
37
+ * `micro_os_plus::micro_test_plus::reflection` namespace, ensuring clear
38
+ * separation from user code and minimising the risk of naming conflicts.
39
+ *
40
+ * The header files are organised within the
41
+ * `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
42
+ * modular codebase.
43
+ *
44
+ * This file is intended solely for internal use within the framework and
45
+ * should not be included directly by user code.
46
+ */
47
+
48
+ #ifndef MICRO_TEST_PLUS_REFLECTION_H_
49
+ #define MICRO_TEST_PLUS_REFLECTION_H_
50
+
51
+ // ----------------------------------------------------------------------------
52
+
53
+ #ifdef __cplusplus
54
+
55
+ // ----------------------------------------------------------------------------
56
+
57
+ #include <string_view>
58
+
59
+ #if defined(__cpp_lib_source_location)
60
+ #include <source_location>
61
+ #endif
62
+
63
+ // ----------------------------------------------------------------------------
64
+
65
+ #if defined(__GNUC__)
66
+ #pragma GCC diagnostic push
67
+ #pragma GCC diagnostic ignored "-Wpadded"
68
+ #pragma GCC diagnostic ignored "-Waggregate-return"
69
+ #if defined(__clang__)
70
+ #pragma clang diagnostic ignored "-Wc++98-compat"
71
+ #pragma clang diagnostic ignored "-Wunknown-warning-option"
72
+ #endif
73
+ #endif
74
+
75
+ namespace micro_os_plus::micro_test_plus
76
+ {
77
+ // --------------------------------------------------------------------------
78
+
79
+ /**
80
+ * @namespace micro_os_plus::micro_test_plus::reflection
81
+ * @brief Reflection utilities for the µTest++ testing framework.
82
+ *
83
+ * @details
84
+ * The `reflection` namespace provides facilities for obtaining source
85
+ * location information and type names at compile time, thereby supporting
86
+ * advanced reporting and diagnostics within the µTest++ framework.
87
+ *
88
+ * It includes a local implementation of `source_location` for environments
89
+ * lacking C++20 standard support, as well as utilities for extracting
90
+ * concise type names from compiler-specific macros such as
91
+ * `__PRETTY_FUNCTION__`.
92
+ *
93
+ * All definitions within this namespace are intended to facilitate advanced
94
+ * reflection and reporting capabilities.
95
+ */
96
+ namespace reflection
97
+ {
98
+ // ------------------------------------------------------------------------
99
+
100
+ #if defined(__cpp_lib_source_location)
101
+ /**
102
+ * @brief Alias for source location information.
103
+ *
104
+ * @details
105
+ * The `source_location` type provides access to source code location
106
+ * details, such as file name and line number, for enhanced diagnostics and
107
+ * reporting within the µTest++ framework. When C++20 standard support is
108
+ * available, this alias refers to `std::source_location`; otherwise, a
109
+ * local implementation is used to ensure consistent functionality across
110
+ * all supported environments. This abstraction enables precise
111
+ * identification of code locations in test reports, supporting clear and
112
+ * professional diagnostics across all files and folders.
113
+ */
114
+ using source_location = std::source_location;
115
+ #else
116
+ /**
117
+ * @brief Local implementation of source location information for
118
+ * diagnostics.
119
+ *
120
+ * @details
121
+ * This class provides a lightweight, constexpr-compatible alternative to
122
+ * `std::source_location` for environments lacking C++20 standard support.
123
+ *
124
+ * It enables retrieval of the file name and line number at the point of
125
+ * invocation, supporting enhanced diagnostics and reporting within the
126
+ * µTest++ framework.
127
+ *
128
+ * The static `current()` method captures the current source location,
129
+ * using compiler built-ins where available, or defaulting to `"unknown"`
130
+ * and zero otherwise.
131
+ *
132
+ * @since 3.0.0
133
+ *
134
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
135
+ */
136
+ class source_location
137
+ {
138
+ public:
139
+ /**
140
+ * @brief Obtain the current source location.
141
+ *
142
+ * @param file The file name (automatically provided by the compiler).
143
+ * @param line The line number (automatically provided by the compiler).
144
+ * @return A `source_location` instance with the captured information.
145
+ */
146
+ [[nodiscard]] static constexpr source_location
147
+ current (
148
+ #if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
149
+ const char* file = __builtin_FILE (),
150
+ unsigned int line = __builtin_LINE ()
151
+ #else
152
+ const char* file = "unknown", unsigned int line = {}
153
+ #endif
154
+ ) noexcept;
155
+
156
+ /**
157
+ * @brief Retrieve the file name associated with this source location.
158
+ *
159
+ * @par Parameters
160
+ * None.
161
+ * @return The file name as a constant character pointer.
162
+ */
163
+ [[nodiscard]] constexpr auto
164
+ file_name (void) const noexcept;
165
+
166
+ /**
167
+ * @brief Retrieve the line number associated with this source location.
168
+ *
169
+ * @par Parameters
170
+ * None.
171
+ * @return The line number as an unsigned integer.
172
+ */
173
+ [[nodiscard]] constexpr auto
174
+ line (void) const noexcept;
175
+
176
+ private:
177
+ /**
178
+ * @brief The file name where the source location was captured.
179
+ */
180
+ const char* file_{ "unknown" };
181
+
182
+ /**
183
+ * @brief The line number where the source location was captured.
184
+ */
185
+ unsigned int line_{};
186
+ };
187
+
188
+ #endif
189
+
190
+ /**
191
+ * @brief Extract a short type or function name from a fully qualified
192
+ * name.
193
+ *
194
+ * @param name The fully qualified name as a C-string.
195
+ * @return A pointer to the short name within the input string.
196
+ */
197
+ const char*
198
+ short_name (const char* name);
199
+
200
+ // TODO: update for the new namespaces.
201
+
202
+ /**
203
+ * @brief Extract the type name from the `__PRETTY_FUNCTION__` macro.
204
+ *
205
+ * @tparam T The type whose name is to be extracted.
206
+ *
207
+ * @par Parameters
208
+ * None.
209
+ * @return A `std::string_view` containing the extracted type name.
210
+ */
211
+ template <class T>
212
+ [[nodiscard]] constexpr auto
213
+ type_name (void) -> std::string_view;
214
+
215
+ // ------------------------------------------------------------------------
216
+ } // namespace reflection
217
+
218
+ // --------------------------------------------------------------------------
219
+ } // namespace micro_os_plus::micro_test_plus
220
+
221
+ #if defined(__GNUC__)
222
+ #pragma GCC diagnostic pop
223
+ #endif
224
+
225
+ // ----------------------------------------------------------------------------
226
+
227
+ #endif // __cplusplus
228
+
229
+ // ----------------------------------------------------------------------------
230
+
231
+ #endif // MICRO_TEST_PLUS_REFLECTION_H_
232
+
233
+ // ----------------------------------------------------------------------------
@@ -0,0 +1,289 @@
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++ header file with declarations for the µTest++ basic test
21
+ * reporter.
22
+ *
23
+ * @details
24
+ * This header provides the declaration for `test_reporter_basic`, the default
25
+ * concrete implementation of the `test_reporter` abstract interface. It
26
+ * formats and presents test results using `printf`-based standard output,
27
+ * accumulating output in an internal string buffer and supporting
28
+ * colour-coded diagnostics and multiple verbosity levels.
29
+ *
30
+ * Users who require custom output behaviour (e.g. redirecting to a serial
31
+ * port on bare-metal targets) may derive a new class from `test_reporter`
32
+ * instead of using this class.
33
+ *
34
+ * All definitions reside within the `micro_os_plus::micro_test_plus`
35
+ * namespace, ensuring clear separation from user code and minimising the risk
36
+ * of naming conflicts.
37
+ *
38
+ * The header files are organised within the
39
+ * `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
40
+ * modular codebase.
41
+ *
42
+ * This file is intended solely for internal use within the framework and
43
+ * should not be included directly by user code.
44
+ */
45
+
46
+ #ifndef MICRO_TEST_PLUS_TEST_REPORTER_BASIC_H_
47
+ #define MICRO_TEST_PLUS_TEST_REPORTER_BASIC_H_
48
+
49
+ // ----------------------------------------------------------------------------
50
+
51
+ #ifdef __cplusplus
52
+
53
+ // ----------------------------------------------------------------------------
54
+
55
+ #include "test-reporter.h"
56
+
57
+ // ----------------------------------------------------------------------------
58
+
59
+ #if defined(__GNUC__)
60
+ #pragma GCC diagnostic push
61
+ #pragma GCC diagnostic ignored "-Wpadded"
62
+ #if defined(__clang__)
63
+ #pragma clang diagnostic ignored "-Wc++98-compat"
64
+ #endif
65
+ #endif
66
+
67
+ namespace micro_os_plus::micro_test_plus
68
+ {
69
+ // --------------------------------------------------------------------------
70
+
71
+ /**
72
+ * @brief Basic (standard output) implementation of `test_reporter`.
73
+ *
74
+ * @details
75
+ * `test_reporter_basic` provides the default concrete implementation of the
76
+ * `test_reporter` abstract interface, formatting and presenting test results
77
+ * using `printf`-based output. It accumulates output in an internal string
78
+ * buffer and writes it to the standard output stream, supporting
79
+ * colour-coded diagnostics and multiple verbosity levels.
80
+ *
81
+ * Users who require custom output behaviour (e.g. redirecting to a serial
82
+ * port on bare-metal targets) may derive a new class from `test_reporter`
83
+ * and supply an instance via the `reporter` global pointer before calling
84
+ * `initialize()`.
85
+ *
86
+ * All members and methods are defined within the
87
+ * `micro_os_plus::micro_test_plus` namespace, ensuring clear separation from
88
+ * user code and minimising the risk of naming conflicts.
89
+ *
90
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
91
+ */
92
+ class test_reporter_basic final : public test_reporter
93
+ {
94
+ public:
95
+ /**
96
+ * @brief Constructor for the test_reporter_basic class.
97
+ *
98
+ * @details
99
+ * The rule of five is enforced to prevent accidental copying or moving.
100
+ */
101
+ test_reporter_basic ();
102
+
103
+ /**
104
+ * @brief Deleted copy constructor to prevent copying.
105
+ */
106
+ test_reporter_basic (const test_reporter_basic&) = delete;
107
+
108
+ /**
109
+ * @brief Deleted move constructor to prevent moving.
110
+ */
111
+ test_reporter_basic (test_reporter_basic&&) = delete;
112
+
113
+ /**
114
+ * @brief Deleted copy assignment operator to prevent copying.
115
+ */
116
+ test_reporter_basic&
117
+ operator= (const test_reporter_basic&)
118
+ = delete;
119
+
120
+ /**
121
+ * @brief Deleted move assignment operator to prevent moving.
122
+ */
123
+ test_reporter_basic&
124
+ operator= (test_reporter_basic&&)
125
+ = delete;
126
+
127
+ /**
128
+ * @brief Destructor for the test_reporter_basic class.
129
+ */
130
+ ~test_reporter_basic () override = default;
131
+
132
+ /**
133
+ * @brief Inserts a line ending into the output buffer.
134
+ *
135
+ * @par Parameters
136
+ * None.
137
+ * @par Returns
138
+ * Nothing.
139
+ */
140
+ void
141
+ endline (void) override;
142
+
143
+ /**
144
+ * @brief Mark the beginning of a test case.
145
+ *
146
+ * @param name The name of the test case.
147
+ * @par Returns
148
+ * Nothing.
149
+ */
150
+ void
151
+ begin_test_case (const char* name) override;
152
+
153
+ /**
154
+ * @brief Mark the end of a test case.
155
+ *
156
+ * @param name The name of the test case.
157
+ * @par Returns
158
+ * Nothing.
159
+ */
160
+ void
161
+ end_test_case (const char* name) override;
162
+
163
+ /**
164
+ * @brief Mark the beginning of a test suite.
165
+ *
166
+ * @param name The name of the test suite.
167
+ * @par Returns
168
+ * Nothing.
169
+ */
170
+ void
171
+ begin_test_suite (const char* name) override;
172
+
173
+ /**
174
+ * @brief Mark the end of a test suite.
175
+ *
176
+ * @param suite Reference to the test suite base.
177
+ * @par Returns
178
+ * Nothing.
179
+ */
180
+ void
181
+ end_test_suite (test_suite_base& suite) override;
182
+
183
+ /**
184
+ * @brief Mark the beginning of a test.
185
+ *
186
+ * @param test_suites_count The number of test suites, or zero if unknown.
187
+ * @par Returns
188
+ * Nothing.
189
+ */
190
+ void
191
+ begin_test (size_t test_suites_count) override;
192
+
193
+ /**
194
+ * @brief Mark the end of a test.
195
+ *
196
+ * @param runner Reference to the test runner.
197
+ * @par Returns
198
+ * Nothing.
199
+ */
200
+ void
201
+ end_test (test_runner& runner) override;
202
+
203
+ /**
204
+ * @brief Flush the current buffered content.
205
+ *
206
+ * @par Parameters
207
+ * None.
208
+ * @par Returns
209
+ * Nothing.
210
+ */
211
+ void
212
+ flush (void) override;
213
+
214
+ /**
215
+ * @brief Output the current buffered content.
216
+ *
217
+ * @par Parameters
218
+ * None.
219
+ * @par Returns
220
+ * Nothing.
221
+ */
222
+ void
223
+ output (void) override;
224
+
225
+ protected:
226
+ /**
227
+ * @brief Outputs the prefix for a passing condition.
228
+ *
229
+ * @param message The message to display.
230
+ * @par Returns
231
+ * Nothing.
232
+ */
233
+ void
234
+ output_pass_prefix_ (std::string& message) override;
235
+
236
+ /**
237
+ * @brief Outputs the suffix for a passing condition.
238
+ *
239
+ * @par Parameters
240
+ * None.
241
+ * @par Returns
242
+ * Nothing.
243
+ */
244
+ void
245
+ output_pass_suffix_ (void) override;
246
+
247
+ /**
248
+ * @brief Outputs the prefix for a failing condition.
249
+ *
250
+ * @param message The message to display.
251
+ * @param hasExpression Whether the failure is associated with an
252
+ * expression.
253
+ * @param location The source location of the failure.
254
+ * @par Returns
255
+ * Nothing.
256
+ */
257
+ void
258
+ output_fail_prefix_ (std::string& message, const bool hasExpression,
259
+ const reflection::source_location& location) override;
260
+
261
+ /**
262
+ * @brief Outputs the suffix for a failing condition.
263
+ *
264
+ * @param location The source location of the failure.
265
+ * @param abort Whether to abort execution after failure.
266
+ * @par Returns
267
+ * Nothing.
268
+ */
269
+ void
270
+ output_fail_suffix_ (const reflection::source_location& location,
271
+ bool abort) override;
272
+ };
273
+
274
+ // --------------------------------------------------------------------------
275
+ } // namespace micro_os_plus::micro_test_plus
276
+
277
+ #if defined(__GNUC__)
278
+ #pragma GCC diagnostic pop
279
+ #endif
280
+
281
+ // ----------------------------------------------------------------------------
282
+
283
+ #endif // __cplusplus
284
+
285
+ // ----------------------------------------------------------------------------
286
+
287
+ #endif // MICRO_TEST_PLUS_TEST_REPORTER_BASIC_H_
288
+
289
+ // ----------------------------------------------------------------------------