@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
|
@@ -0,0 +1,369 @@
|
|
|
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 inline implementations for the µTest++ test
|
|
21
|
+
* suite.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the inline implementations for the test suite
|
|
25
|
+
* facilities used within the µTest++ framework. It defines the logic for
|
|
26
|
+
* constructing and registering test suites, including the binding of callable
|
|
27
|
+
* objects and their arguments for flexible test suite definitions.
|
|
28
|
+
*
|
|
29
|
+
* The implementation ensures that each test suite is automatically registered
|
|
30
|
+
* with the global test runner upon construction, enabling automated discovery
|
|
31
|
+
* and execution of test suites. The use of `std::bind` allows for versatile
|
|
32
|
+
* test suite initialisation with arbitrary callable types and arguments.
|
|
33
|
+
*
|
|
34
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
35
|
+
* namespace, maintaining a clear separation from user code and minimising the
|
|
36
|
+
* risk 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_INLINES_H_
|
|
47
|
+
#define MICRO_TEST_PLUS_TEST_INLINES_H_
|
|
48
|
+
|
|
49
|
+
// ----------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
#ifdef __cplusplus
|
|
52
|
+
|
|
53
|
+
// ----------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
#include <cstdio>
|
|
56
|
+
#include <cstring>
|
|
57
|
+
|
|
58
|
+
// ----------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
#if defined(__GNUC__)
|
|
61
|
+
#pragma GCC diagnostic push
|
|
62
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
63
|
+
#if defined(__clang__)
|
|
64
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
65
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
66
|
+
#else // GCC only
|
|
67
|
+
#endif
|
|
68
|
+
#endif
|
|
69
|
+
|
|
70
|
+
// ============================================================================
|
|
71
|
+
|
|
72
|
+
namespace micro_os_plus::micro_test_plus
|
|
73
|
+
{
|
|
74
|
+
// ==========================================================================
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @details
|
|
78
|
+
* Binds the callable and its arguments into the stored `callable_` function
|
|
79
|
+
* object. When `run()` is called, the stored function is invoked with a
|
|
80
|
+
* reference to the derived `Self_T` instance as its first argument,
|
|
81
|
+
* followed by the bound arguments.
|
|
82
|
+
*/
|
|
83
|
+
template <typename Self_T>
|
|
84
|
+
template <typename Callable_T, typename... Args_T>
|
|
85
|
+
runnable<Self_T>::runnable (const char* name, class runner& runner,
|
|
86
|
+
size_t own_index, Callable_T&& callable,
|
|
87
|
+
Args_T&&... arguments)
|
|
88
|
+
: runnable_base{ name, runner, own_index }
|
|
89
|
+
{
|
|
90
|
+
// When there are no extra arguments the callable already has the signature
|
|
91
|
+
// void(Self_T&), so store it directly. Only use std::bind when additional
|
|
92
|
+
// arguments must be pre-bound, to avoid triggering a GCC ARM bug in
|
|
93
|
+
// __is_nothrow_invocable<_Bind<...>, Self_T&> (GCC 15.2.1).
|
|
94
|
+
if constexpr (sizeof...(arguments) == 0)
|
|
95
|
+
{
|
|
96
|
+
callable_ = std::forward<Callable_T> (callable);
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
callable_ = std::bind (std::forward<Callable_T> (callable),
|
|
101
|
+
std::placeholders::_1,
|
|
102
|
+
std::forward<Args_T> (arguments)...);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
106
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
107
|
+
#if defined(__GNUC__)
|
|
108
|
+
#pragma GCC diagnostic push
|
|
109
|
+
#if defined(__clang__)
|
|
110
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
111
|
+
#endif
|
|
112
|
+
#endif
|
|
113
|
+
trace::printf ("%s '%s' %zu\n", __PRETTY_FUNCTION__, name, own_index_);
|
|
114
|
+
#if defined(__GNUC__)
|
|
115
|
+
#pragma GCC diagnostic pop
|
|
116
|
+
#endif
|
|
117
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @details
|
|
122
|
+
* No-op in production builds. When tracing is enabled via
|
|
123
|
+
* `MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS`, emits a trace
|
|
124
|
+
* message identifying the instance being destroyed.
|
|
125
|
+
*/
|
|
126
|
+
template <typename Self_T>
|
|
127
|
+
runnable<Self_T>::~runnable ()
|
|
128
|
+
{
|
|
129
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
130
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
131
|
+
#if defined(__GNUC__)
|
|
132
|
+
#pragma GCC diagnostic push
|
|
133
|
+
#if defined(__clang__)
|
|
134
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
135
|
+
#endif
|
|
136
|
+
#endif
|
|
137
|
+
trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
|
|
138
|
+
#if defined(__GNUC__)
|
|
139
|
+
#pragma GCC diagnostic pop
|
|
140
|
+
#endif
|
|
141
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ==========================================================================
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @details
|
|
148
|
+
* Delegates to `runnable`, which binds the callable with
|
|
149
|
+
* its arguments.
|
|
150
|
+
*/
|
|
151
|
+
template <typename Callable_T, typename... Args_T>
|
|
152
|
+
subtest::subtest (const char* name, class runner& runner,
|
|
153
|
+
suite& parent_suite, size_t own_index,
|
|
154
|
+
size_t nesting_depth, Callable_T&& callable,
|
|
155
|
+
Args_T&&... arguments)
|
|
156
|
+
: runnable<subtest>{ name, runner, own_index,
|
|
157
|
+
std::forward<Callable_T> (callable),
|
|
158
|
+
std::forward<Args_T> (arguments)... },
|
|
159
|
+
parent_suite_{ parent_suite }, nesting_depth_{ nesting_depth }
|
|
160
|
+
{
|
|
161
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
162
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
163
|
+
#if defined(__GNUC__)
|
|
164
|
+
#pragma GCC diagnostic push
|
|
165
|
+
#if defined(__clang__)
|
|
166
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
167
|
+
#endif
|
|
168
|
+
#endif
|
|
169
|
+
trace::printf ("%s '%s' %zu %zu\n", __PRETTY_FUNCTION__, name, own_index_,
|
|
170
|
+
nesting_depth_);
|
|
171
|
+
#if defined(__GNUC__)
|
|
172
|
+
#pragma GCC diagnostic pop
|
|
173
|
+
#endif
|
|
174
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @details
|
|
179
|
+
* Allocates a child `subtest` on the heap, incrementing the subtest index
|
|
180
|
+
* and deepening the nesting level by one relative to this subtest's depth,
|
|
181
|
+
* then transfers ownership to the framework via `after_subtest_create_()`.
|
|
182
|
+
*/
|
|
183
|
+
template <typename Callable_T, typename... Args_T>
|
|
184
|
+
void
|
|
185
|
+
subtest::test (const char* name, Callable_T&& callable,
|
|
186
|
+
Args_T&&... arguments)
|
|
187
|
+
{
|
|
188
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
189
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
190
|
+
#if defined(__GNUC__)
|
|
191
|
+
#pragma GCC diagnostic push
|
|
192
|
+
#if defined(__clang__)
|
|
193
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
194
|
+
#endif
|
|
195
|
+
#endif
|
|
196
|
+
trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name);
|
|
197
|
+
#if defined(__GNUC__)
|
|
198
|
+
#pragma GCC diagnostic pop
|
|
199
|
+
#endif
|
|
200
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
201
|
+
|
|
202
|
+
size_t own_index = increment_subtest_index ();
|
|
203
|
+
auto child_subtest = std::make_unique<subtest> (
|
|
204
|
+
name, runner (), parent_suite_, own_index, nesting_depth_ + 1,
|
|
205
|
+
std::forward<Callable_T> (callable),
|
|
206
|
+
std::forward<Args_T> (arguments)...);
|
|
207
|
+
|
|
208
|
+
after_subtest_create_ (std::move (child_subtest), parent_suite_);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ==========================================================================
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @details
|
|
215
|
+
* Delegates to `runnable`, which binds the callable with
|
|
216
|
+
* its arguments. After construction, the suite is registered with the
|
|
217
|
+
* static test runner.
|
|
218
|
+
*/
|
|
219
|
+
template <typename Callable_T, typename... Args_T>
|
|
220
|
+
suite::suite (const char* name, class runner& runner, Callable_T&& callable,
|
|
221
|
+
Args_T&&... arguments)
|
|
222
|
+
: runnable<suite>{ name, runner, 0, std::forward<Callable_T> (callable),
|
|
223
|
+
std::forward<Args_T> (arguments)... }
|
|
224
|
+
{
|
|
225
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
226
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
227
|
+
#if defined(__GNUC__)
|
|
228
|
+
#pragma GCC diagnostic push
|
|
229
|
+
#if defined(__clang__)
|
|
230
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
231
|
+
#endif
|
|
232
|
+
#endif
|
|
233
|
+
trace::printf ("%s '%s' %zu\n", __PRETTY_FUNCTION__, name, own_index_);
|
|
234
|
+
#if defined(__GNUC__)
|
|
235
|
+
#pragma GCC diagnostic pop
|
|
236
|
+
#endif
|
|
237
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#if defined(__GNUC__)
|
|
241
|
+
#pragma GCC diagnostic push
|
|
242
|
+
#if defined(__clang__)
|
|
243
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
244
|
+
#endif
|
|
245
|
+
#endif
|
|
246
|
+
/**
|
|
247
|
+
* @details
|
|
248
|
+
* The `test` function template registers and executes a test case
|
|
249
|
+
* within the µTest++ framework. It accepts a descriptive name, a callable
|
|
250
|
+
* object (such as a lambda or function pointer), and an optional list of
|
|
251
|
+
* arguments to be passed to the callable. The test case is reported using
|
|
252
|
+
* the provided name, and its execution is managed by the framework's test
|
|
253
|
+
* runner.
|
|
254
|
+
*
|
|
255
|
+
* Each test case typically involves evaluating a logical expression, such as
|
|
256
|
+
* comparing a computed result to an expected value. For C++ projects, it is
|
|
257
|
+
* also possible to verify whether evaluating an expression throws
|
|
258
|
+
* exceptions. Each test either succeeds or fails, and for expectations, the
|
|
259
|
+
* test runner maintains counts of successful and failed checks.
|
|
260
|
+
*
|
|
261
|
+
* This function template enables flexible and expressive test case
|
|
262
|
+
* definitions, supporting both parameterised and non-parameterised tests. It
|
|
263
|
+
* is typically invoked at global scope or within test suite definitions to
|
|
264
|
+
* ensure automatic registration and execution.
|
|
265
|
+
*
|
|
266
|
+
* A test case is characterised by a name, a function that performs the
|
|
267
|
+
* checks, and optionally, arguments to be passed to that function. The
|
|
268
|
+
* implementation of `test` invokes the provided function with the given
|
|
269
|
+
* arguments and reports the results to the test runner.
|
|
270
|
+
*
|
|
271
|
+
* @par Example
|
|
272
|
+
*
|
|
273
|
+
* @code{.cpp}
|
|
274
|
+
* namespace mt = micro_os_plus::micro_test_plus;
|
|
275
|
+
*
|
|
276
|
+
* ts.test ("Check answer with comparator", [] (auto& t) {
|
|
277
|
+
* t.expect (mt::eq (compute_answer (), 42)) << "answer is 42";
|
|
278
|
+
* });
|
|
279
|
+
* @endcode
|
|
280
|
+
*/
|
|
281
|
+
#if defined(__GNUC__)
|
|
282
|
+
#pragma GCC diagnostic pop
|
|
283
|
+
#endif
|
|
284
|
+
template <typename Callable_T, typename... Args_T>
|
|
285
|
+
void
|
|
286
|
+
suite::test (const char* name, Callable_T&& callable, Args_T&&... arguments)
|
|
287
|
+
{
|
|
288
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
289
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
290
|
+
#if defined(__GNUC__)
|
|
291
|
+
#pragma GCC diagnostic push
|
|
292
|
+
#if defined(__clang__)
|
|
293
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
294
|
+
#endif
|
|
295
|
+
#endif
|
|
296
|
+
trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name);
|
|
297
|
+
#if defined(__GNUC__)
|
|
298
|
+
#pragma GCC diagnostic pop
|
|
299
|
+
#endif
|
|
300
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
301
|
+
|
|
302
|
+
size_t own_index = increment_subtest_index ();
|
|
303
|
+
auto child_subtest
|
|
304
|
+
= std::make_unique<subtest> (name, runner (), *this, own_index, 1,
|
|
305
|
+
std::forward<Callable_T> (callable),
|
|
306
|
+
std::forward<Args_T> (arguments)...);
|
|
307
|
+
|
|
308
|
+
after_subtest_create_ (std::move (child_subtest), *this);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ==========================================================================
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* @details
|
|
315
|
+
* Delegates to `runnable`, which binds the callable with
|
|
316
|
+
* its arguments. After construction, the suite is registered with the
|
|
317
|
+
* static test runner.
|
|
318
|
+
*/
|
|
319
|
+
template <typename Callable_T, typename... Args_T>
|
|
320
|
+
static_suite::static_suite (const char* name, static_runner& runner,
|
|
321
|
+
Callable_T&& callable, Args_T&&... arguments)
|
|
322
|
+
// The nullptr passed to the base constructor is an optimisation to save
|
|
323
|
+
// some space, since this callble is not used by the static runner.
|
|
324
|
+
: suite{ name, runner, nullptr }
|
|
325
|
+
{
|
|
326
|
+
if constexpr (sizeof...(arguments) == 0)
|
|
327
|
+
{
|
|
328
|
+
static_callable_ = std::forward<Callable_T> (callable);
|
|
329
|
+
}
|
|
330
|
+
else
|
|
331
|
+
{
|
|
332
|
+
static_callable_ = std::bind (std::forward<Callable_T> (callable),
|
|
333
|
+
std::placeholders::_1,
|
|
334
|
+
std::forward<Args_T> (arguments)...);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
338
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
339
|
+
#if defined(__GNUC__)
|
|
340
|
+
#pragma GCC diagnostic push
|
|
341
|
+
#if defined(__clang__)
|
|
342
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
|
|
343
|
+
#endif
|
|
344
|
+
#endif
|
|
345
|
+
trace::printf ("%s '%s' %zu\n", __PRETTY_FUNCTION__, name, own_index_);
|
|
346
|
+
#if defined(__GNUC__)
|
|
347
|
+
#pragma GCC diagnostic pop
|
|
348
|
+
#endif
|
|
349
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
350
|
+
|
|
351
|
+
static_runner::register_static_suite (runner, *this);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// --------------------------------------------------------------------------
|
|
355
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
356
|
+
|
|
357
|
+
#if defined(__GNUC__)
|
|
358
|
+
#pragma GCC diagnostic pop
|
|
359
|
+
#endif
|
|
360
|
+
|
|
361
|
+
// ----------------------------------------------------------------------------
|
|
362
|
+
|
|
363
|
+
#endif // __cplusplus
|
|
364
|
+
|
|
365
|
+
// ----------------------------------------------------------------------------
|
|
366
|
+
|
|
367
|
+
#endif // MICRO_TEST_PLUS_TEST_INLINES_H_
|
|
368
|
+
|
|
369
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,126 @@
|
|
|
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 inline implementations for the µTest++ utility
|
|
21
|
+
* functions.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the inline implementations for the utility function
|
|
25
|
+
* templates used within the µTest++ framework. It defines the logic for
|
|
26
|
+
* splitting strings into substrings using a specified delimiter, enabling
|
|
27
|
+
* convenient and type-safe string parsing in test expressions.
|
|
28
|
+
*
|
|
29
|
+
* All definitions reside within the
|
|
30
|
+
* `micro_os_plus::micro_test_plus::utility` namespace, ensuring clear
|
|
31
|
+
* separation from user code and minimising the risk of naming conflicts.
|
|
32
|
+
*
|
|
33
|
+
* The header files are organised within the
|
|
34
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
35
|
+
* modular codebase.
|
|
36
|
+
*
|
|
37
|
+
* This file is intended solely for internal use within the framework and
|
|
38
|
+
* should not be included directly by user code.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
#ifndef MICRO_TEST_PLUS_UTILITY_INLINES_H_
|
|
42
|
+
#define MICRO_TEST_PLUS_UTILITY_INLINES_H_
|
|
43
|
+
|
|
44
|
+
// ----------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
#ifdef __cplusplus
|
|
47
|
+
|
|
48
|
+
// ----------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
#if defined(__GNUC__)
|
|
51
|
+
#pragma GCC diagnostic push
|
|
52
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
53
|
+
#if defined(__clang__)
|
|
54
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
55
|
+
#endif
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
// ============================================================================
|
|
59
|
+
|
|
60
|
+
namespace micro_os_plus::micro_test_plus
|
|
61
|
+
{
|
|
62
|
+
// --------------------------------------------------------------------------
|
|
63
|
+
namespace utility
|
|
64
|
+
{
|
|
65
|
+
/**
|
|
66
|
+
* @details
|
|
67
|
+
* This function template facilitates string handling in tests by splitting
|
|
68
|
+
* a string into a vector of substrings, using the specified delimiter.
|
|
69
|
+
*
|
|
70
|
+
* The function iterates through the input string, identifying delimiter
|
|
71
|
+
* positions and extracting substrings between them. Each resulting
|
|
72
|
+
* substring is added to the output vector. This approach supports flexible
|
|
73
|
+
* parsing of delimited data, which is particularly useful for validating
|
|
74
|
+
* string processing logic in test cases.
|
|
75
|
+
*
|
|
76
|
+
* **Example**
|
|
77
|
+
*
|
|
78
|
+
* @code{.cpp}
|
|
79
|
+
* namespace mt = micro_os_plus::micro_test_plus;
|
|
80
|
+
*
|
|
81
|
+
* t.expect (std::vector<std::string_view>{ "a", "b" }
|
|
82
|
+
* == mt::utility::split<std::string_view> ("a.b", "."))
|
|
83
|
+
* << "a.b splits into [a,b]";
|
|
84
|
+
* @endcode
|
|
85
|
+
*/
|
|
86
|
+
template <class T = std::string_view, class Delim_T>
|
|
87
|
+
[[nodiscard]] auto
|
|
88
|
+
split (T input, Delim_T delim) -> std::vector<T>
|
|
89
|
+
{
|
|
90
|
+
std::vector<T> output{};
|
|
91
|
+
std::size_t first{};
|
|
92
|
+
while (first < std::size (input))
|
|
93
|
+
{
|
|
94
|
+
const auto second = input.find_first_of (delim, first);
|
|
95
|
+
if (first != second)
|
|
96
|
+
{
|
|
97
|
+
output.emplace_back (input.substr (first, second - first));
|
|
98
|
+
}
|
|
99
|
+
if (second == T::npos)
|
|
100
|
+
{
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
first = second + 1;
|
|
104
|
+
}
|
|
105
|
+
return output;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ------------------------------------------------------------------------
|
|
109
|
+
} // namespace utility
|
|
110
|
+
|
|
111
|
+
// --------------------------------------------------------------------------
|
|
112
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
113
|
+
|
|
114
|
+
#if defined(__GNUC__)
|
|
115
|
+
#pragma GCC diagnostic pop
|
|
116
|
+
#endif
|
|
117
|
+
|
|
118
|
+
// ----------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
#endif // __cplusplus
|
|
121
|
+
|
|
122
|
+
// ----------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
#endif // MICRO_TEST_PLUS_UTILITY_INLINES_H_
|
|
125
|
+
|
|
126
|
+
// ----------------------------------------------------------------------------
|
|
@@ -74,6 +74,8 @@
|
|
|
74
74
|
#endif
|
|
75
75
|
#endif
|
|
76
76
|
|
|
77
|
+
// =============================================================================
|
|
78
|
+
|
|
77
79
|
namespace micro_os_plus::micro_test_plus
|
|
78
80
|
{
|
|
79
81
|
// --------------------------------------------------------------------------
|
|
@@ -324,7 +326,6 @@ namespace micro_os_plus::micro_test_plus
|
|
|
324
326
|
*
|
|
325
327
|
* @return A `type_traits::integral_constant` instance holding the parsed
|
|
326
328
|
* `uint8_t` value.
|
|
327
|
-
* and reporting mechanisms.
|
|
328
329
|
*/
|
|
329
330
|
template <char... Cs>
|
|
330
331
|
[[nodiscard]] constexpr auto
|
|
@@ -675,8 +676,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
675
676
|
*
|
|
676
677
|
* @code
|
|
677
678
|
* int x = 42;
|
|
678
|
-
*
|
|
679
|
-
*
|
|
679
|
+
* // Explicitly treat x as an int for test comparison.
|
|
680
|
+
* auto wrapped = to_i{x};
|
|
680
681
|
* @endcode
|
|
681
682
|
*
|
|
682
683
|
* @since 3.2.0
|
|
@@ -64,9 +64,12 @@
|
|
|
64
64
|
#pragma GCC diagnostic ignored "-Wconversion"
|
|
65
65
|
#if defined(__clang__)
|
|
66
66
|
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
67
|
+
#pragma clang diagnostic ignored "-Wc++20-compat"
|
|
67
68
|
#endif
|
|
68
69
|
#endif
|
|
69
70
|
|
|
71
|
+
// ============================================================================
|
|
72
|
+
|
|
70
73
|
namespace micro_os_plus::micro_test_plus
|
|
71
74
|
{
|
|
72
75
|
// --------------------------------------------------------------------------
|
|
@@ -103,7 +106,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
103
106
|
*/
|
|
104
107
|
template <class T>
|
|
105
108
|
[[nodiscard]] constexpr auto
|
|
106
|
-
abs (const T t) -> T;
|
|
109
|
+
abs (const T t) noexcept -> T;
|
|
107
110
|
|
|
108
111
|
/**
|
|
109
112
|
* @brief Computes the minimum of two comparable values.
|
|
@@ -117,7 +120,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
117
120
|
*/
|
|
118
121
|
template <class T>
|
|
119
122
|
[[nodiscard]] constexpr auto
|
|
120
|
-
min_value (const T& lhs, const T& rhs) -> const T&;
|
|
123
|
+
min_value (const T& lhs, const T& rhs) noexcept -> const T&;
|
|
121
124
|
|
|
122
125
|
/**
|
|
123
126
|
* @brief Generic exponentiation function to compute the power of a base
|
|
@@ -134,7 +137,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
134
137
|
*/
|
|
135
138
|
template <class T, class Exp_T>
|
|
136
139
|
[[nodiscard]] constexpr auto
|
|
137
|
-
pow (const T base, const Exp_T exp) -> T;
|
|
140
|
+
pow (const T base, const Exp_T exp) noexcept -> T;
|
|
138
141
|
|
|
139
142
|
/**
|
|
140
143
|
* @brief Computes the integral value of a number represented as an array
|
|
@@ -148,7 +151,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
148
151
|
* @return The parsed integral value of type \c T.
|
|
149
152
|
*/
|
|
150
153
|
template <class T, char... Cs>
|
|
151
|
-
[[nodiscard]]
|
|
154
|
+
[[nodiscard]] consteval auto
|
|
152
155
|
num (void) -> T;
|
|
153
156
|
|
|
154
157
|
/**
|
|
@@ -163,7 +166,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
163
166
|
* @return The parsed decimal part as an integral value of type \c T.
|
|
164
167
|
*/
|
|
165
168
|
template <class T, char... Cs>
|
|
166
|
-
[[nodiscard]]
|
|
169
|
+
[[nodiscard]] consteval auto
|
|
167
170
|
den (void) -> T;
|
|
168
171
|
|
|
169
172
|
/**
|
|
@@ -178,7 +181,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
178
181
|
* @return The number of decimal places as a value of type \c T.
|
|
179
182
|
*/
|
|
180
183
|
template <class T, char... Cs>
|
|
181
|
-
[[nodiscard]]
|
|
184
|
+
[[nodiscard]] consteval auto
|
|
182
185
|
den_size (void) -> T;
|
|
183
186
|
|
|
184
187
|
/**
|