@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.
- package/CHANGELOG.md +330 -2
- package/CMakeLists.txt +79 -23
- package/README.md +1 -1
- package/config/xcdl-build.json +11 -4
- package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +292 -0
- package/include/micro-os-plus/micro-test-plus/detail.h +462 -1076
- package/include/micro-os-plus/micro-test-plus/exceptions.h +126 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +10 -7
- package/include/micro-os-plus/micro-test-plus/inlines/{details-inlines.h → deferred-reporter-inlines.h} +49 -22
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +67 -4
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +3 -6
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +21 -15
- package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +35 -17
- package/include/micro-os-plus/micro-test-plus/inlines/{test-reporter-inlines.h → reporter-inlines.h} +176 -106
- package/include/micro-os-plus/micro-test-plus/inlines/{test-suite-inlines.h → runner-inlines.h} +41 -43
- package/include/micro-os-plus/micro-test-plus/inlines/test-inlines.h +369 -0
- package/include/micro-os-plus/micro-test-plus/inlines/utility-inlines.h +126 -0
- package/include/micro-os-plus/micro-test-plus/literals.h +4 -3
- package/include/micro-os-plus/micro-test-plus/math.h +9 -6
- package/include/micro-os-plus/micro-test-plus/operators.h +38 -44
- package/include/micro-os-plus/micro-test-plus/reflection.h +15 -4
- package/include/micro-os-plus/micro-test-plus/{test-reporter-basic.h → reporter-human.h} +72 -72
- package/include/micro-os-plus/micro-test-plus/{test-reporter-tap.h → reporter-tap.h} +69 -69
- package/include/micro-os-plus/micro-test-plus/{test-reporter.h → reporter.h} +296 -200
- package/include/micro-os-plus/micro-test-plus/runner-totals.h +264 -0
- package/include/micro-os-plus/micro-test-plus/runner.h +453 -0
- package/include/micro-os-plus/micro-test-plus/test.h +1069 -0
- package/include/micro-os-plus/micro-test-plus/timings.h +366 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +239 -545
- package/include/micro-os-plus/micro-test-plus/utility.h +135 -0
- package/include/micro-os-plus/micro-test-plus.h +25 -228
- package/meson.build +10 -6
- package/package.json +1 -1
- package/src/deferred-reporter.cpp +118 -0
- package/src/reflection.cpp +95 -0
- package/src/reporter-human.cpp +822 -0
- package/src/reporter-tap.cpp +782 -0
- package/src/reporter.cpp +676 -0
- package/src/runner-totals.cpp +95 -0
- package/src/runner.cpp +563 -0
- package/src/test.cpp +496 -0
- package/src/timings.cpp +209 -0
- package/src/utility.cpp +163 -0
- package/.cmake-format.yaml +0 -11
- package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +0 -313
- package/include/micro-os-plus/micro-test-plus/test-runner.h +0 -281
- package/include/micro-os-plus/micro-test-plus/test-suite.h +0 -492
- package/src/micro-test-plus.cpp +0 -316
- package/src/test-reporter-basic.cpp +0 -466
- package/src/test-reporter-tap.cpp +0 -530
- package/src/test-reporter.cpp +0 -399
- package/src/test-runner.cpp +0 -311
- package/src/test-suite.cpp +0 -304
package/src/micro-test-plus.cpp
DELETED
|
@@ -1,316 +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++ methods.
|
|
21
|
-
*
|
|
22
|
-
* @details
|
|
23
|
-
* This source file contains the core implementations for the µTest++ testing
|
|
24
|
-
* framework, including initialisation and shutdown routines, utility
|
|
25
|
-
* functions, and the management of global framework state. It provides the
|
|
26
|
-
* logic for setting up the test environment, registering and executing test
|
|
27
|
-
* suites, reporting results, and supporting utility operations such as file
|
|
28
|
-
* name extraction and pattern-based string matching.
|
|
29
|
-
*
|
|
30
|
-
* All definitions are contained within the `micro_os_plus::micro_test_plus`
|
|
31
|
-
* namespace and its nested namespaces, ensuring clear separation from user
|
|
32
|
-
* code and minimising the risk of naming conflicts.
|
|
33
|
-
*
|
|
34
|
-
* The implementation is optimised for embedded environments, avoiding heavy
|
|
35
|
-
* dependencies and providing lightweight, efficient mechanisms for test
|
|
36
|
-
* execution and reporting.
|
|
37
|
-
*
|
|
38
|
-
* This file must be included when building the µTest++ library.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
// ----------------------------------------------------------------------------
|
|
42
|
-
|
|
43
|
-
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
44
|
-
#include <micro-os-plus/config.h>
|
|
45
|
-
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
46
|
-
|
|
47
|
-
#include <micro-os-plus/micro-test-plus.h>
|
|
48
|
-
#include <cstring>
|
|
49
|
-
// <iostream> is too heavy for embedded, use printf().
|
|
50
|
-
#include <stdio.h>
|
|
51
|
-
#include <unistd.h>
|
|
52
|
-
|
|
53
|
-
// ----------------------------------------------------------------------------
|
|
54
|
-
|
|
55
|
-
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
56
|
-
#if defined(__clang__)
|
|
57
|
-
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
58
|
-
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
|
59
|
-
#pragma clang diagnostic ignored "-Wglobal-constructors"
|
|
60
|
-
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
61
|
-
#endif
|
|
62
|
-
|
|
63
|
-
namespace micro_os_plus::micro_test_plus
|
|
64
|
-
{
|
|
65
|
-
// --------------------------------------------------------------------------
|
|
66
|
-
// Public API.
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @details
|
|
70
|
-
* The `initialize` function sets up the µTest++ testing framework, preparing
|
|
71
|
-
* it for test execution. It processes command-line arguments, configures the
|
|
72
|
-
* test environment, and establishes the default test suite name. This
|
|
73
|
-
* function should be called at the beginning of the test programme,
|
|
74
|
-
* typically from the `main()` function, to ensure proper initialisation of
|
|
75
|
-
* all framework components.
|
|
76
|
-
*
|
|
77
|
-
* The provided arguments may be used to configure verbosity or other
|
|
78
|
-
* run-time options for the test session.
|
|
79
|
-
*/
|
|
80
|
-
void
|
|
81
|
-
initialize (int argc, char* argv[], const char* name)
|
|
82
|
-
{
|
|
83
|
-
#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
84
|
-
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
85
|
-
#endif
|
|
86
|
-
runner.initialize (argc, argv, name);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @details
|
|
91
|
-
* In addition to the test cases defined in `main()`, additional test suites
|
|
92
|
-
* may be declared as static objects either within the same file or in other
|
|
93
|
-
* files, and are automatically registered via the static constructors
|
|
94
|
-
* mechanism.
|
|
95
|
-
*
|
|
96
|
-
* The `exit_code` function finalises the execution of all registered test
|
|
97
|
-
* suites and test cases within the µTest++ framework, and returns an
|
|
98
|
-
* appropriate exit code to the operating system. This function should be
|
|
99
|
-
* called at the end of the test program, typically from the `main()`
|
|
100
|
-
* function, to ensure that all results are properly reported and the correct
|
|
101
|
-
* status is communicated.
|
|
102
|
-
*
|
|
103
|
-
* The returned value indicates the overall success or failure of the test
|
|
104
|
-
* run, allowing integration with build systems and continuous integration
|
|
105
|
-
* environments.
|
|
106
|
-
*/
|
|
107
|
-
int
|
|
108
|
-
exit_code (void)
|
|
109
|
-
{
|
|
110
|
-
return runner.exit_code ();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// --------------------------------------------------------------------------
|
|
114
|
-
// Too small to deserve a separate source file.
|
|
115
|
-
namespace reflection
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @details
|
|
120
|
-
* This function extracts the short name from a given file path by locating
|
|
121
|
-
* the final folder separator ('/'). If a separator is found, it returns a
|
|
122
|
-
* pointer to the character immediately following it, effectively providing
|
|
123
|
-
* the file or folder name. If no separator is present, the original input
|
|
124
|
-
* string is returned. This utility is useful for reporting concise file or
|
|
125
|
-
* folder names in test output.
|
|
126
|
-
*/
|
|
127
|
-
const char*
|
|
128
|
-
short_name (const char* name)
|
|
129
|
-
{
|
|
130
|
-
#pragma GCC diagnostic push
|
|
131
|
-
#if defined(__clang__)
|
|
132
|
-
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
133
|
-
#endif
|
|
134
|
-
const char* p = strrchr (name, '/');
|
|
135
|
-
if (p != nullptr)
|
|
136
|
-
return p + 1;
|
|
137
|
-
else
|
|
138
|
-
return name;
|
|
139
|
-
#pragma GCC diagnostic pop
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
} // namespace reflection
|
|
143
|
-
|
|
144
|
-
namespace utility
|
|
145
|
-
{
|
|
146
|
-
#if defined(__clang__)
|
|
147
|
-
#pragma clang diagnostic push
|
|
148
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
149
|
-
#endif
|
|
150
|
-
/**
|
|
151
|
-
* @details
|
|
152
|
-
* This function enables pattern-based string comparison for tests, supporting
|
|
153
|
-
* both exact matches and wildcard patterns. The pattern may include `*` to
|
|
154
|
-
* match any sequence of characters and `?` to match any single character. This
|
|
155
|
-
* allows for flexible validation of string content in test assertions,
|
|
156
|
-
* accommodating variable or partially known values.
|
|
157
|
-
*
|
|
158
|
-
* @par Examples
|
|
159
|
-
*
|
|
160
|
-
* @code{.cpp}
|
|
161
|
-
* namespace mt = micro_os_plus::micro_test_plus;
|
|
162
|
-
*
|
|
163
|
-
* mt::expect (mt::utility::is_match ("abc", "a?c")) << "abc matches a?c";
|
|
164
|
-
* mt::expect (mt::utility::is_match ("abc", "a*c")) << "abc matches a*c";
|
|
165
|
-
* @endcode
|
|
166
|
-
*/
|
|
167
|
-
#if defined(__clang__)
|
|
168
|
-
#pragma clang diagnostic pop
|
|
169
|
-
#endif
|
|
170
|
-
[[nodiscard]] bool
|
|
171
|
-
is_match (std::string_view input, std::string_view pattern)
|
|
172
|
-
{
|
|
173
|
-
if (std::empty (pattern))
|
|
174
|
-
{
|
|
175
|
-
return std::empty (input);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (std::empty (input))
|
|
179
|
-
{
|
|
180
|
-
return pattern[0] == '*' ? is_match (input, pattern.substr (1))
|
|
181
|
-
: false;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (pattern[0] != '?' and pattern[0] != '*' and pattern[0] != input[0])
|
|
185
|
-
{
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (pattern[0] == '*')
|
|
190
|
-
{
|
|
191
|
-
for (decltype (std::size (input)) i = 0u; i <= std::size (input);
|
|
192
|
-
++i)
|
|
193
|
-
{
|
|
194
|
-
if (is_match (input.substr (i), pattern.substr (1)))
|
|
195
|
-
{
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return is_match (input.substr (1), pattern.substr (1));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
} // namespace utility
|
|
206
|
-
|
|
207
|
-
namespace detail
|
|
208
|
-
{
|
|
209
|
-
/**
|
|
210
|
-
* @details
|
|
211
|
-
* This constructor updates the current test suite's statistics based on
|
|
212
|
-
* the outcome of the test expression. If the evaluated value is true, the
|
|
213
|
-
* count of successful tests is incremented; otherwise, the count of failed
|
|
214
|
-
* tests is incremented. The source location is recorded for reporting
|
|
215
|
-
* purposes, enabling precise identification of the test case within the
|
|
216
|
-
* relevant file or folder.
|
|
217
|
-
*/
|
|
218
|
-
deferred_reporter_base::deferred_reporter_base (
|
|
219
|
-
bool value, const reflection::source_location location)
|
|
220
|
-
: value_{ value }, location_{ location }
|
|
221
|
-
{
|
|
222
|
-
if (value_)
|
|
223
|
-
{
|
|
224
|
-
current_test_suite->increment_successful ();
|
|
225
|
-
}
|
|
226
|
-
else
|
|
227
|
-
{
|
|
228
|
-
current_test_suite->increment_failed ();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* @details
|
|
234
|
-
* The destructor ensures that if an abort condition is set and the test
|
|
235
|
-
* expression has failed, the test output is flushed and the process is
|
|
236
|
-
* terminated. This mechanism guarantees immediate feedback and halts
|
|
237
|
-
* further execution upon critical test failures, aiding in rapid
|
|
238
|
-
* identification and resolution of issues during test runs.
|
|
239
|
-
*/
|
|
240
|
-
deferred_reporter_base::~deferred_reporter_base ()
|
|
241
|
-
{
|
|
242
|
-
#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
243
|
-
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
244
|
-
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
245
|
-
|
|
246
|
-
if (abort_ && !value_)
|
|
247
|
-
{
|
|
248
|
-
printf ("\n");
|
|
249
|
-
reporter->output ();
|
|
250
|
-
abort ();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
} // namespace detail
|
|
255
|
-
|
|
256
|
-
// ==========================================================================
|
|
257
|
-
|
|
258
|
-
#if defined(__GNUC__)
|
|
259
|
-
#pragma GCC diagnostic push
|
|
260
|
-
#if defined(__clang__)
|
|
261
|
-
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
|
262
|
-
#pragma clang diagnostic ignored "-Wglobal-constructors"
|
|
263
|
-
#endif
|
|
264
|
-
#endif
|
|
265
|
-
|
|
266
|
-
// Static instances;
|
|
267
|
-
/**
|
|
268
|
-
* @brief Global instance of `test_runner`.
|
|
269
|
-
*
|
|
270
|
-
* @details
|
|
271
|
-
* This global instance of `test_runner` manages the lifecycle of test suites
|
|
272
|
-
* and test cases within the µTest++ framework. It is responsible for
|
|
273
|
-
* initialising the test environment, registering test suites, executing
|
|
274
|
-
* tests, and collecting results. By maintaining a single shared runner, the
|
|
275
|
-
* framework ensures consistent test execution and reporting across all test
|
|
276
|
-
* cases and folders.
|
|
277
|
-
*/
|
|
278
|
-
test_runner runner;
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* @brief Global pointer to `test_reporter`.
|
|
282
|
-
*
|
|
283
|
-
* @details
|
|
284
|
-
* This global pointer to `test_reporter` is responsible for collecting,
|
|
285
|
-
* formatting, and outputting the results of test execution within the
|
|
286
|
-
* µTest++ framework. It manages the reporting of test outcomes, including
|
|
287
|
-
* successes and failures, and ensures that all relevant information is
|
|
288
|
-
* presented clearly to the user. By maintaining a single shared reporter,
|
|
289
|
-
* the framework provides consistent and centralised reporting across all
|
|
290
|
-
* test cases and folders. The reporter is initialized in
|
|
291
|
-
* test_runner::initialize().
|
|
292
|
-
*/
|
|
293
|
-
test_reporter* reporter = nullptr;
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @brief Global pointer references the currently active test suite.
|
|
297
|
-
*
|
|
298
|
-
* @details
|
|
299
|
-
* This global pointer references the currently active test suite within the
|
|
300
|
-
* µTest++ framework. It is used to track and update the state of the test
|
|
301
|
-
* suite during test execution, including recording test results and
|
|
302
|
-
* statistics. By maintaining a pointer to the current test suite, the
|
|
303
|
-
* framework ensures accurate association of test outcomes with their
|
|
304
|
-
* respective suites, supporting clear and organised reporting across all
|
|
305
|
-
* test cases and folders.
|
|
306
|
-
*/
|
|
307
|
-
test_suite_base* current_test_suite;
|
|
308
|
-
|
|
309
|
-
#if defined(__GNUC__)
|
|
310
|
-
#pragma GCC diagnostic pop
|
|
311
|
-
#endif
|
|
312
|
-
|
|
313
|
-
// --------------------------------------------------------------------------
|
|
314
|
-
} // namespace micro_os_plus::micro_test_plus
|
|
315
|
-
|
|
316
|
-
// ----------------------------------------------------------------------------
|