@micro-os-plus/micro-test-plus 3.3.1 → 4.1.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 +412 -2
- package/CMakeLists.txt +134 -28
- package/README.md +3 -2
- package/config/xcdl-build.json +11 -4
- package/include/micro-os-plus/micro-test-plus/README.md +6 -0
- package/include/micro-os-plus/micro-test-plus/deferred-reporter.h +267 -0
- package/include/micro-os-plus/micro-test-plus/detail.h +272 -1425
- package/include/micro-os-plus/micro-test-plus/exceptions.h +125 -0
- package/include/micro-os-plus/micro-test-plus/expression-formatter.h +669 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +15 -7
- package/include/micro-os-plus/micro-test-plus/inlines/{details-inlines.h → deferred-reporter-inlines.h} +66 -44
- package/include/micro-os-plus/micro-test-plus/inlines/detail-inlines.h +711 -0
- package/include/micro-os-plus/micro-test-plus/inlines/exceptions-inline.h +137 -0
- package/include/micro-os-plus/micro-test-plus/inlines/{test-reporter-inlines.h → expression-formatter-inlines.h} +232 -198
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +24 -20
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +50 -31
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +25 -19
- package/include/micro-os-plus/micro-test-plus/inlines/operators-inlines.h +275 -0
- package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +39 -21
- package/include/micro-os-plus/micro-test-plus/inlines/reporter-inlines.h +205 -0
- package/include/micro-os-plus/micro-test-plus/inlines/runner-inlines.h +151 -0
- package/include/micro-os-plus/micro-test-plus/inlines/runner-totals-inlines.h +152 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-inlines.h +555 -0
- package/include/micro-os-plus/micro-test-plus/inlines/timings-inlines.h +120 -0
- package/include/micro-os-plus/micro-test-plus/inlines/type-traits-inlines.h +231 -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 +12 -17
- package/include/micro-os-plus/micro-test-plus/math.h +14 -6
- package/include/micro-os-plus/micro-test-plus/operators.h +53 -209
- package/include/micro-os-plus/micro-test-plus/reflection.h +8 -4
- package/include/micro-os-plus/micro-test-plus/{test-reporter-basic.h → reporter-human.h} +80 -74
- package/include/micro-os-plus/micro-test-plus/{test-reporter-tap.h → reporter-tap.h} +77 -71
- package/include/micro-os-plus/micro-test-plus/reporter.h +619 -0
- package/include/micro-os-plus/micro-test-plus/runner-totals.h +250 -0
- package/include/micro-os-plus/micro-test-plus/runner.h +472 -0
- package/include/micro-os-plus/micro-test-plus/test.h +1013 -0
- package/include/micro-os-plus/micro-test-plus/timings.h +363 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +223 -577
- package/include/micro-os-plus/micro-test-plus/utility.h +136 -0
- package/include/micro-os-plus/micro-test-plus.h +42 -236
- package/meson.build +11 -6
- package/package.json +11 -3
- package/src/deferred-reporter.cpp +137 -0
- package/src/expression-formatter.cpp +289 -0
- package/src/reflection.cpp +97 -0
- package/src/reporter-human.cpp +816 -0
- package/src/reporter-tap.cpp +772 -0
- package/src/reporter.cpp +481 -0
- package/src/runner-totals.cpp +98 -0
- package/src/runner.cpp +669 -0
- package/src/test.cpp +503 -0
- package/src/timings.cpp +210 -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/inlines/test-suite-inlines.h +0 -115
- package/include/micro-os-plus/micro-test-plus/test-reporter.h +0 -846
- 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,136 @@
|
|
|
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++ utility helpers.
|
|
21
|
+
*
|
|
22
|
+
* @details
|
|
23
|
+
* This header provides declarations for the utility helper functions used
|
|
24
|
+
* within the µTest++ framework. It defines interfaces for string operations
|
|
25
|
+
* including file-name extraction, pattern matching, and string splitting.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifndef MICRO_TEST_PLUS_UTILITY_H_
|
|
29
|
+
#define MICRO_TEST_PLUS_UTILITY_H_
|
|
30
|
+
|
|
31
|
+
// ----------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
|
|
35
|
+
// ----------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
#include <string_view>
|
|
38
|
+
#include <vector>
|
|
39
|
+
|
|
40
|
+
// ----------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
#if defined(__GNUC__)
|
|
43
|
+
#pragma GCC diagnostic push
|
|
44
|
+
#if defined(__clang__)
|
|
45
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
46
|
+
#endif
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
// ============================================================================
|
|
50
|
+
|
|
51
|
+
namespace micro_os_plus::micro_test_plus
|
|
52
|
+
{
|
|
53
|
+
// --------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @namespace micro_os_plus::micro_test_plus::utility
|
|
57
|
+
* @brief Utility functions for the µTest++ testing framework.
|
|
58
|
+
*
|
|
59
|
+
* @details
|
|
60
|
+
* The `micro_os_plus::micro_test_plus::utility` namespace provides a suite
|
|
61
|
+
* of helper functions designed to support advanced string operations and
|
|
62
|
+
* other common tasks within the µTest++ framework.
|
|
63
|
+
*
|
|
64
|
+
* These utilities include functions for pattern matching—such as verifying
|
|
65
|
+
* whether a string matches a specified pattern—and for splitting strings
|
|
66
|
+
* into sub-strings based on delimiters. The implementations are efficient
|
|
67
|
+
* and suitable for both embedded and general C++ projects.
|
|
68
|
+
*
|
|
69
|
+
* By encapsulating these helper functions within a dedicated namespace, the
|
|
70
|
+
* framework maintains clear code organisation and minimises naming
|
|
71
|
+
* conflicts.
|
|
72
|
+
*/
|
|
73
|
+
namespace utility
|
|
74
|
+
{
|
|
75
|
+
/**
|
|
76
|
+
* @ingroup micro-test-plus-utility-functions
|
|
77
|
+
* @brief Extracts the file name component from a full path.
|
|
78
|
+
*
|
|
79
|
+
* @param [in] path A null-terminated file path string.
|
|
80
|
+
* @return A pointer to the first character of the file name within
|
|
81
|
+
* `path`, or `path` itself if no directory separator is found.
|
|
82
|
+
*/
|
|
83
|
+
[[nodiscard]] const char*
|
|
84
|
+
extract_file_name (const char* path) noexcept;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @ingroup micro-test-plus-utility-functions
|
|
88
|
+
* @brief Check if a string matches a pattern.
|
|
89
|
+
*
|
|
90
|
+
* @param [in] input The string view to be checked.
|
|
91
|
+
* @param [in] pattern The string view containing the pattern to match.
|
|
92
|
+
* @return `true` if the input string matches the pattern; otherwise,
|
|
93
|
+
* `false`.
|
|
94
|
+
*/
|
|
95
|
+
[[nodiscard]] bool
|
|
96
|
+
is_match (std::string_view input, std::string_view pattern);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @ingroup micro-test-plus-utility-functions
|
|
100
|
+
* @brief Split a string into a vector of sub-strings.
|
|
101
|
+
*
|
|
102
|
+
* @tparam T Type of the input string.
|
|
103
|
+
* @tparam Delim_T Type of the delimiter.
|
|
104
|
+
*
|
|
105
|
+
* @param [in] input Input string to split.
|
|
106
|
+
* @param [in] delim Delimiter string.
|
|
107
|
+
* @return A vector containing the resulting sub-strings.
|
|
108
|
+
*/
|
|
109
|
+
template <class T, class Delim_T>
|
|
110
|
+
[[nodiscard]] auto
|
|
111
|
+
split (T input, Delim_T delim) -> std::vector<T>;
|
|
112
|
+
|
|
113
|
+
// ------------------------------------------------------------------------
|
|
114
|
+
} // namespace utility
|
|
115
|
+
|
|
116
|
+
// --------------------------------------------------------------------------
|
|
117
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
118
|
+
|
|
119
|
+
#if defined(__GNUC__)
|
|
120
|
+
#pragma GCC diagnostic pop
|
|
121
|
+
#endif
|
|
122
|
+
|
|
123
|
+
// ----------------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
#endif // __cplusplus
|
|
126
|
+
|
|
127
|
+
// ============================================================================
|
|
128
|
+
// Templates & constexpr implementations.
|
|
129
|
+
|
|
130
|
+
#include "inlines/utility-inlines.h"
|
|
131
|
+
|
|
132
|
+
// ----------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
#endif // MICRO_TEST_PLUS_UTILITY_H_
|
|
135
|
+
|
|
136
|
+
// ----------------------------------------------------------------------------
|
|
@@ -63,34 +63,59 @@
|
|
|
63
63
|
#include <micro-os-plus/config.h>
|
|
64
64
|
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
65
65
|
|
|
66
|
+
// No deps.
|
|
67
|
+
#include "micro-test-plus/math.h"
|
|
68
|
+
|
|
69
|
+
// Requires math.h.
|
|
66
70
|
#include "micro-test-plus/type-traits.h"
|
|
71
|
+
|
|
72
|
+
// No deps.
|
|
67
73
|
#include "micro-test-plus/reflection.h"
|
|
68
74
|
|
|
75
|
+
// Requires type-traits.h, reflection.h.
|
|
69
76
|
#include "micro-test-plus/detail.h"
|
|
70
77
|
|
|
71
|
-
|
|
78
|
+
// Requires type-traits.h, math.h.
|
|
72
79
|
#include "micro-test-plus/literals.h"
|
|
80
|
+
|
|
81
|
+
// No deps.
|
|
73
82
|
#include "micro-test-plus/function-comparators.h"
|
|
83
|
+
|
|
84
|
+
// No deps.
|
|
85
|
+
#include "micro-test-plus/exceptions.h"
|
|
86
|
+
|
|
87
|
+
// Requires type-traits.h + detail.h,
|
|
74
88
|
#include "micro-test-plus/operators.h"
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
#include "micro-test-plus/
|
|
78
|
-
#include "micro-test-plus/test-reporter.h"
|
|
79
|
-
#include "micro-test-plus/test-reporter-basic.h"
|
|
80
|
-
#include "micro-test-plus/test-reporter-tap.h"
|
|
90
|
+
// Requires type-traits.h, detail.h + reflection.h.
|
|
91
|
+
#include "micro-test-plus/expression-formatter.h"
|
|
81
92
|
|
|
82
|
-
//
|
|
93
|
+
// Requires type-traits.h, detail.h, expression-formatter.h, reflection.h.
|
|
94
|
+
#include "micro-test-plus/reporter.h"
|
|
95
|
+
|
|
96
|
+
// Requires type-traits.h, reflection.h, expression-formatter.h.
|
|
97
|
+
#include "micro-test-plus/deferred-reporter.h"
|
|
98
|
+
|
|
99
|
+
// No deps.
|
|
100
|
+
#include "micro-test-plus/runner-totals.h"
|
|
101
|
+
|
|
102
|
+
// Requires reporter.h, reflection.h.
|
|
103
|
+
#include "micro-test-plus/reporter-human.h"
|
|
83
104
|
|
|
84
|
-
|
|
85
|
-
#
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#
|
|
93
|
-
|
|
105
|
+
// Requires reporter.h, reflection.h.
|
|
106
|
+
#include "micro-test-plus/reporter-tap.h"
|
|
107
|
+
|
|
108
|
+
// No deps.
|
|
109
|
+
#include "micro-test-plus/utility.h"
|
|
110
|
+
|
|
111
|
+
// Requires reporter.h, runner-totals.h, reflection.h, type-traits.h and
|
|
112
|
+
// timings.h + deferred-reporter.h, reporter.h.
|
|
113
|
+
#include "micro-test-plus/test.h"
|
|
114
|
+
|
|
115
|
+
// Requires timings.h, test.h (detail::test_node, top_suite), reflection.h.
|
|
116
|
+
#include "micro-test-plus/runner.h"
|
|
117
|
+
|
|
118
|
+
// ----------------------------------------------------------------------------
|
|
94
119
|
|
|
95
120
|
/**
|
|
96
121
|
* @namespace micro_os_plus::micro_test_plus
|
|
@@ -116,230 +141,11 @@
|
|
|
116
141
|
* folder, ensuring a clear separation from user code and facilitating
|
|
117
142
|
* straightforward integration with the wider µOS++ ecosystem.
|
|
118
143
|
*/
|
|
119
|
-
namespace micro_os_plus::micro_test_plus
|
|
120
|
-
{
|
|
121
|
-
// --------------------------------------------------------------------------
|
|
122
|
-
|
|
123
|
-
extern test_runner runner;
|
|
124
|
-
extern test_reporter* reporter;
|
|
125
|
-
extern test_suite_base* current_test_suite;
|
|
126
|
-
|
|
127
|
-
// --------------------------------------------------------------------------
|
|
128
|
-
// Public API.
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @ingroup micro-test-plus-inits
|
|
132
|
-
* @brief Initialise the µTest++ framework.
|
|
133
|
-
*
|
|
134
|
-
* @param [in] argc The number of command-line arguments.
|
|
135
|
-
* @param [in] argv Array of pointers to null-terminated argument strings.
|
|
136
|
-
* @param [in] name The name of the default test suite. Defaults to `"Main"`
|
|
137
|
-
* if not specified.
|
|
138
|
-
* @par Returns
|
|
139
|
-
* Nothing.
|
|
140
|
-
*/
|
|
141
|
-
void
|
|
142
|
-
initialize (int argc, char* argv[], const char* name = "Main");
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @ingroup micro-test-plus-inits
|
|
146
|
-
* @brief Complete the test run and return the exit code.
|
|
147
|
-
*
|
|
148
|
-
* @par Parameters
|
|
149
|
-
* None.
|
|
150
|
-
* @return 0 if all tests were successful, 1 if any test failed.
|
|
151
|
-
*/
|
|
152
|
-
[[nodiscard]] int
|
|
153
|
-
exit_code (void);
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @ingroup micro-test-plus-test-case
|
|
157
|
-
* @brief Define and execute a test case.
|
|
158
|
-
*
|
|
159
|
-
* @tparam Callable_T The type of the callable object to be executed as the
|
|
160
|
-
* test case.
|
|
161
|
-
* @tparam Args_T The types of the arguments to be passed to the callable.
|
|
162
|
-
* @param [in] name The test case name or description, used in test reports.
|
|
163
|
-
* @param [in] callable A generic callable object, usually a lambda, invoked
|
|
164
|
-
* to perform the test.
|
|
165
|
-
* @param [in] arguments A possibly empty list of arguments to be passed to
|
|
166
|
-
* the callable.
|
|
167
|
-
* @par Returns
|
|
168
|
-
* Nothing.
|
|
169
|
-
*/
|
|
170
|
-
template <typename Callable_T, typename... Args_T>
|
|
171
|
-
void
|
|
172
|
-
test_case (const char* name, Callable_T&& callable, Args_T&&... arguments);
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @ingroup micro-test-plus-expectations
|
|
176
|
-
* @brief Evaluate a generic condition and report the results.
|
|
177
|
-
*
|
|
178
|
-
* @tparam Expr_T The type of the custom expression.
|
|
179
|
-
*
|
|
180
|
-
* @par SFINAE
|
|
181
|
-
* Enabled only if `Expr_T` is derived from `detail::op` or
|
|
182
|
-
* is convertible to `bool`.
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
* @param [in] expr Logical expression to evaluate.
|
|
186
|
-
* @param [in] sl Optional source location, defaulting to the current line.
|
|
187
|
-
* @return An output stream to write optional messages.
|
|
188
|
-
*/
|
|
189
|
-
template <class Expr_T, type_traits::requires_t<
|
|
190
|
-
type_traits::is_op_v<Expr_T>
|
|
191
|
-
or type_traits::is_convertible_v<Expr_T, bool>>
|
|
192
|
-
= 0>
|
|
193
|
-
constexpr auto
|
|
194
|
-
expect (const Expr_T& expr, const reflection::source_location& sl
|
|
195
|
-
= reflection::source_location::current ());
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @ingroup micro-test-plus-assumptions
|
|
199
|
-
* @brief Check a condition and, if false, abort test execution.
|
|
200
|
-
*
|
|
201
|
-
* @tparam Expr_T The type of the custom expression.
|
|
202
|
-
*
|
|
203
|
-
* @par SFINAE
|
|
204
|
-
* Enabled only if `Expr_T` is derived from `detail::op` or
|
|
205
|
-
* is convertible to `bool`.
|
|
206
|
-
*
|
|
207
|
-
* @param [in] expr Logical expression to evaluate.
|
|
208
|
-
* @param [in] sl Optional source location, defaulting to the current line.
|
|
209
|
-
* @return An output stream to write optional messages.
|
|
210
|
-
*/
|
|
211
|
-
template <class Expr_T, type_traits::requires_t<
|
|
212
|
-
type_traits::is_op_v<Expr_T>
|
|
213
|
-
or type_traits::is_convertible_v<Expr_T, bool>>
|
|
214
|
-
= 0>
|
|
215
|
-
constexpr auto
|
|
216
|
-
assume (const Expr_T& expr, const reflection::source_location& sl
|
|
217
|
-
= reflection::source_location::current ());
|
|
218
|
-
|
|
219
|
-
// --------------------------------------------------------------------------
|
|
220
|
-
|
|
221
|
-
#if defined(__cpp_exceptions)
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @ingroup micro-test-plus-exceptions
|
|
225
|
-
* @brief Check if a callable throws a specific exception.
|
|
226
|
-
*
|
|
227
|
-
* @tparam Exception_T The type of the exception expected to be thrown.
|
|
228
|
-
* @tparam Callable_T The type of the callable object to be invoked.
|
|
229
|
-
* @param [in] func The callable object to check for exception throwing
|
|
230
|
-
* behaviour.
|
|
231
|
-
* @return An output stream to write optional messages.
|
|
232
|
-
*/
|
|
233
|
-
template <class Exception_T, class Callable_T>
|
|
234
|
-
[[nodiscard]] constexpr auto
|
|
235
|
-
throws (const Callable_T& func);
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @ingroup micro-test-plus-exceptions
|
|
239
|
-
* @brief Check if a callable throws an exception (any exception).
|
|
240
|
-
*
|
|
241
|
-
* @tparam Callable_T The type of the callable object to be invoked.
|
|
242
|
-
* @param [in] func The callable object to check for exception throwing
|
|
243
|
-
* behaviour.
|
|
244
|
-
* @return An output stream to write optional messages.
|
|
245
|
-
*/
|
|
246
|
-
template <class Callable_T>
|
|
247
|
-
[[nodiscard]] constexpr auto
|
|
248
|
-
throws (const Callable_T& func);
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* @ingroup micro-test-plus-exceptions
|
|
252
|
-
* @brief Check if a callable does not throw an exception.
|
|
253
|
-
*
|
|
254
|
-
* @tparam Callable_T The type of the callable object to be invoked.
|
|
255
|
-
* @param [in] func The callable object to check for exception safety.
|
|
256
|
-
* @return An output stream to write optional messages.
|
|
257
|
-
*/
|
|
258
|
-
template <class Callable_T>
|
|
259
|
-
[[nodiscard]] constexpr auto
|
|
260
|
-
nothrow (const Callable_T& func);
|
|
261
|
-
|
|
262
|
-
#endif
|
|
263
|
-
|
|
264
|
-
// --------------------------------------------------------------------------
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* @namespace micro_os_plus::micro_test_plus::utility
|
|
268
|
-
* @brief Utility functions for the µTest++ testing framework.
|
|
269
|
-
*
|
|
270
|
-
* @details
|
|
271
|
-
* The `micro_os_plus::micro_test_plus::utility` namespace provides a suite
|
|
272
|
-
* of helper functions designed to support advanced string operations and
|
|
273
|
-
* other common tasks within the µTest++ framework.
|
|
274
|
-
*
|
|
275
|
-
* These utilities include functions for pattern matching—such as verifying
|
|
276
|
-
* whether a string matches a specified pattern—and for splitting strings
|
|
277
|
-
* into sub-strings based on delimiters. The implementations are efficient
|
|
278
|
-
* and suitable for both embedded and general C++ projects.
|
|
279
|
-
*
|
|
280
|
-
* By encapsulating these helper functions within a dedicated namespace, the
|
|
281
|
-
* framework maintains clear code organisation and minimises naming
|
|
282
|
-
* conflicts.
|
|
283
|
-
*/
|
|
284
|
-
namespace utility
|
|
285
|
-
{
|
|
286
|
-
/**
|
|
287
|
-
* @ingroup micro-test-plus-utility-functions
|
|
288
|
-
* @brief Check if a string matches a pattern.
|
|
289
|
-
*
|
|
290
|
-
* @param [in] input The string view to be checked.
|
|
291
|
-
* @param [in] pattern The string view containing the pattern to match.
|
|
292
|
-
* @return `true` if the input string matches the pattern; otherwise,
|
|
293
|
-
* `false`.
|
|
294
|
-
*/
|
|
295
|
-
[[nodiscard]] bool
|
|
296
|
-
is_match (std::string_view input, std::string_view pattern);
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* @ingroup micro-test-plus-utility-functions
|
|
300
|
-
* @brief Split a string into a vector of sub-strings.
|
|
301
|
-
*
|
|
302
|
-
* @tparam T Type of the input string.
|
|
303
|
-
* @tparam Delim_T Type of the delimiter.
|
|
304
|
-
*
|
|
305
|
-
* @param [in] input Input string to split.
|
|
306
|
-
* @param [in] delim Delimiter string.
|
|
307
|
-
* @return A vector containing the resulting sub-strings.
|
|
308
|
-
*/
|
|
309
|
-
template <class T, class Delim_T>
|
|
310
|
-
[[nodiscard]] auto
|
|
311
|
-
split (T input, Delim_T delim) -> std::vector<T>;
|
|
312
|
-
|
|
313
|
-
// ------------------------------------------------------------------------
|
|
314
|
-
} // namespace utility
|
|
315
|
-
|
|
316
|
-
// --------------------------------------------------------------------------
|
|
317
|
-
} // namespace micro_os_plus::micro_test_plus
|
|
318
|
-
|
|
319
|
-
#if defined(__GNUC__)
|
|
320
|
-
#pragma GCC diagnostic pop
|
|
321
|
-
#endif
|
|
322
144
|
|
|
323
145
|
// ----------------------------------------------------------------------------
|
|
324
146
|
|
|
325
147
|
#endif // __cplusplus
|
|
326
148
|
|
|
327
|
-
// ===== Inlines & templates implementations
|
|
328
|
-
// ====================================
|
|
329
|
-
|
|
330
|
-
// All inlines are included **after** all declarations.
|
|
331
|
-
#include "micro-test-plus/inlines/details-inlines.h"
|
|
332
|
-
#include "micro-test-plus/inlines/literals-inlines.h"
|
|
333
|
-
#include "micro-test-plus/inlines/math-inlines.h"
|
|
334
|
-
|
|
335
|
-
#include "micro-test-plus/inlines/reflection-inlines.h"
|
|
336
|
-
#include "micro-test-plus/inlines/test-reporter-inlines.h"
|
|
337
|
-
|
|
338
|
-
#include "micro-test-plus/inlines/function-comparators-inlines.h"
|
|
339
|
-
#include "micro-test-plus/inlines/test-suite-inlines.h"
|
|
340
|
-
|
|
341
|
-
#include "micro-test-plus/inlines/micro-test-plus-inlines.h"
|
|
342
|
-
|
|
343
149
|
// ----------------------------------------------------------------------------
|
|
344
150
|
|
|
345
151
|
#endif // MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
|
package/meson.build
CHANGED
|
@@ -43,12 +43,17 @@ _local_include_directories += [
|
|
|
43
43
|
]
|
|
44
44
|
|
|
45
45
|
_local_sources += [
|
|
46
|
-
'src/
|
|
47
|
-
'src/
|
|
48
|
-
'src/
|
|
49
|
-
'src/
|
|
50
|
-
'src/
|
|
51
|
-
'src/
|
|
46
|
+
'src/runner.cpp',
|
|
47
|
+
'src/runner-totals.cpp',
|
|
48
|
+
'src/deferred-reporter.cpp',
|
|
49
|
+
'src/expression-formatter.cpp',
|
|
50
|
+
'src/reporter.cpp',
|
|
51
|
+
'src/reporter-human.cpp',
|
|
52
|
+
'src/reporter-tap.cpp',
|
|
53
|
+
'src/test.cpp',
|
|
54
|
+
'src/timings.cpp',
|
|
55
|
+
'src/reflection.cpp',
|
|
56
|
+
'src/utility.cpp',
|
|
52
57
|
]
|
|
53
58
|
|
|
54
59
|
# https://mesonbuild.com/Reference-manual_functions.html#declare_dependency
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-os-plus/micro-test-plus",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "A source code library with µTest++, a lightweight testing framework for embedded platforms",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,12 +50,20 @@
|
|
|
50
50
|
"postversion": "git push origin --all && git push origin --tags"
|
|
51
51
|
},
|
|
52
52
|
"xpack": {
|
|
53
|
-
"minimumXpmRequired": "0.20.8"
|
|
53
|
+
"minimumXpmRequired": "0.20.8",
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@xpack-dev-tools/clang": "21.1.8-1.1"
|
|
56
|
+
},
|
|
57
|
+
"actions": {
|
|
58
|
+
"clang-format": "bash scripts/clang-format.sh",
|
|
59
|
+
"cmake-format": "bash scripts/cmake-format.sh"
|
|
60
|
+
}
|
|
54
61
|
},
|
|
55
62
|
"topConfig": {
|
|
56
63
|
"descriptiveName": "µTest++ Testing Framework",
|
|
57
64
|
"permalinkName": "micro-test-plus",
|
|
58
|
-
"useDoxygen": "true"
|
|
65
|
+
"useDoxygen": "true",
|
|
66
|
+
"hasObjectLibrary": "true"
|
|
59
67
|
},
|
|
60
68
|
"engines": {
|
|
61
69
|
"node": ">=20.0"
|
|
@@ -0,0 +1,137 @@
|
|
|
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++ deferred
|
|
21
|
+
* reporter methods.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This source file contains the implementation of the
|
|
25
|
+
* `detail::deferred_reporter_base` class, which supports deferred
|
|
26
|
+
* reporting of test expression results. The constructor captures the
|
|
27
|
+
* result value, source location, and subtest reference; the destructor
|
|
28
|
+
* updates the subtest counters and optionally aborts execution on
|
|
29
|
+
* critical failures.
|
|
30
|
+
*
|
|
31
|
+
* All definitions reside within the
|
|
32
|
+
* `micro_os_plus::micro_test_plus::detail` namespace.
|
|
33
|
+
*
|
|
34
|
+
* This file must be included when building the µTest++ library.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
// ----------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
40
|
+
#include <micro-os-plus/config.h>
|
|
41
|
+
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
42
|
+
|
|
43
|
+
#if defined(MICRO_OS_PLUS_TRACE)
|
|
44
|
+
#include <micro-os-plus/diag/trace.h>
|
|
45
|
+
#endif // MICRO_OS_PLUS_TRACE
|
|
46
|
+
|
|
47
|
+
#include "micro-os-plus/micro-test-plus/deferred-reporter.h"
|
|
48
|
+
#include "micro-os-plus/micro-test-plus/test.h"
|
|
49
|
+
|
|
50
|
+
// ----------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
#if defined(__GNUC__)
|
|
53
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
54
|
+
#if defined(__clang__)
|
|
55
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
56
|
+
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
|
57
|
+
#pragma clang diagnostic ignored "-Wglobal-constructors"
|
|
58
|
+
#endif
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
// ============================================================================
|
|
62
|
+
|
|
63
|
+
namespace micro_os_plus::micro_test_plus
|
|
64
|
+
{
|
|
65
|
+
// --------------------------------------------------------------------------
|
|
66
|
+
namespace detail
|
|
67
|
+
{
|
|
68
|
+
/**
|
|
69
|
+
* @details
|
|
70
|
+
* Stores the evaluated Boolean @p value, the @p location identifying
|
|
71
|
+
* the source line of the assertion, and a reference to the owning
|
|
72
|
+
* @p subtest. The subtest's check index counter is incremented
|
|
73
|
+
* immediately so that the first check is reported as check #1.
|
|
74
|
+
*/
|
|
75
|
+
deferred_reporter_base::deferred_reporter_base (
|
|
76
|
+
bool value, const reflection::source_location& location,
|
|
77
|
+
subtest& subtest)
|
|
78
|
+
: value_{ value }, location_{ location }, subtest_{ subtest }
|
|
79
|
+
{
|
|
80
|
+
// The index starts at 0, must be incremented before the first check is
|
|
81
|
+
// reported, to ensure that the first check is reported as check #1.
|
|
82
|
+
subtest_.increment_subtest_index ();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @details
|
|
87
|
+
* The destructor finalises the deferred reporting process for a test
|
|
88
|
+
* expression. If the evaluated expression is true, the reporter records a
|
|
89
|
+
* successful outcome along with any accumulated message. If the expression
|
|
90
|
+
* is false, the reporter records a failure, including the abort status,
|
|
91
|
+
* message, and source location for comprehensive reporting.
|
|
92
|
+
*
|
|
93
|
+
* This mechanism ensures that all relevant information about the test
|
|
94
|
+
* outcome is captured and reported accurately when the deferred reporter
|
|
95
|
+
* goes out of scope.
|
|
96
|
+
*
|
|
97
|
+
* The destructor ensures that if an abort condition is set and the test
|
|
98
|
+
* expression has failed, the test output is flushed and the process is
|
|
99
|
+
* terminated. This mechanism guarantees immediate feedback and halts
|
|
100
|
+
* further execution upon critical test failures, aiding in rapid
|
|
101
|
+
* identification and resolution of issues during test runs.
|
|
102
|
+
*/
|
|
103
|
+
deferred_reporter_base::~deferred_reporter_base ()
|
|
104
|
+
{
|
|
105
|
+
#if defined(MICRO_OS_PLUS_TRACE) \
|
|
106
|
+
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
|
|
107
|
+
trace::printf ("%s\n", __PRETTY_FUNCTION__);
|
|
108
|
+
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
|
|
109
|
+
|
|
110
|
+
auto& expression_str = subtest_.reporter ().expression ().str ();
|
|
111
|
+
|
|
112
|
+
if (value_) [[likely]]
|
|
113
|
+
{
|
|
114
|
+
subtest_.reporter ().pass (deferred_output_, expression_str,
|
|
115
|
+
subtest_);
|
|
116
|
+
subtest_.totals ().increment_successful_checks ();
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
{
|
|
120
|
+
subtest_.reporter ().fail (abort_, deferred_output_, expression_str,
|
|
121
|
+
has_expression_, location_, subtest_);
|
|
122
|
+
subtest_.totals ().increment_failed_checks ();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (abort_ && !value_) [[unlikely]]
|
|
126
|
+
{
|
|
127
|
+
subtest_.reporter ().write_buffer_to_stdout ();
|
|
128
|
+
subtest_.reporter ().flush ();
|
|
129
|
+
subtest_.abort (location_);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} // namespace detail
|
|
133
|
+
|
|
134
|
+
// ==========================================================================
|
|
135
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
136
|
+
|
|
137
|
+
// ----------------------------------------------------------------------------
|