@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.
- package/.cmake-format.yaml +11 -0
- package/CHANGELOG.md +417 -2
- package/CMakeLists.txt +33 -30
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/{xcdl.json → config/xcdl-build.json} +6 -6
- package/include/micro-os-plus/micro-test-plus/detail.h +1908 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +333 -0
- package/include/micro-os-plus/micro-test-plus/inlines/details-inlines.h +172 -0
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +341 -0
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +604 -0
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +315 -0
- package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +313 -0
- package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +170 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-reporter-inlines.h +476 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +115 -0
- package/include/micro-os-plus/micro-test-plus/literals.h +912 -0
- package/include/micro-os-plus/micro-test-plus/math.h +217 -0
- package/include/micro-os-plus/micro-test-plus/operators.h +514 -0
- package/include/micro-os-plus/micro-test-plus/reflection.h +233 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter-basic.h +289 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter-tap.h +281 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter.h +846 -0
- package/include/micro-os-plus/micro-test-plus/test-runner.h +281 -0
- package/include/micro-os-plus/micro-test-plus/test-suite.h +492 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
- package/include/micro-os-plus/micro-test-plus.h +172 -552
- package/meson.build +7 -5
- package/package.json +29 -34
- package/src/micro-test-plus.cpp +134 -37
- package/src/test-reporter-basic.cpp +466 -0
- package/src/test-reporter-tap.cpp +530 -0
- package/src/test-reporter.cpp +207 -240
- package/src/test-runner.cpp +135 -23
- package/src/test-suite.cpp +182 -10
- package/include/micro-os-plus/detail.h +0 -765
- package/include/micro-os-plus/inlines.h +0 -209
- package/include/micro-os-plus/literals.h +0 -512
- package/include/micro-os-plus/math.h +0 -204
- package/include/micro-os-plus/reflection.h +0 -139
- package/include/micro-os-plus/test-reporter-inlines.h +0 -230
- package/include/micro-os-plus/test-reporter.h +0 -356
- package/include/micro-os-plus/test-runner.h +0 -132
- package/include/micro-os-plus/test-suite.h +0 -306
- package/include/micro-os-plus/type-traits.h +0 -389
package/src/test-runner.cpp
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
|
|
3
|
-
* Copyright (c) 2021 Liviu Ionescu. All rights reserved.
|
|
3
|
+
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
|
|
4
4
|
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
-
*
|
|
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
7
|
*
|
|
8
|
-
* If a copy of the license was not distributed with this file, it can
|
|
9
|
-
*
|
|
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
10
|
*
|
|
11
11
|
* Major parts of the code are inspired from v1.1.8 of the Boost UT project,
|
|
12
12
|
* released under the terms of the Boost Version 1.0 Software License,
|
|
@@ -15,6 +15,29 @@
|
|
|
15
15
|
|
|
16
16
|
// ----------------------------------------------------------------------------
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @file
|
|
20
|
+
* @brief C++ source file with implementations for the µTest++ test runner
|
|
21
|
+
* methods.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This source file contains the core implementations for the test runner
|
|
25
|
+
* facilities of the µTest++ framework. It provides the logic for initialising
|
|
26
|
+
* the test environment, registering and managing test suites, handling
|
|
27
|
+
* command-line arguments, orchestrating test execution, and determining the
|
|
28
|
+
* overall test result. The implementation supports automated discovery and
|
|
29
|
+
* execution of test suites, flexible verbosity control, and robust mechanisms
|
|
30
|
+
* for aborting test execution in critical scenarios.
|
|
31
|
+
*
|
|
32
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
33
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
34
|
+
* of naming conflicts.
|
|
35
|
+
*
|
|
36
|
+
* This file must be included when building the µTest++ library.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// ----------------------------------------------------------------------------
|
|
40
|
+
|
|
18
41
|
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
19
42
|
#include <micro-os-plus/config.h>
|
|
20
43
|
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
@@ -22,6 +45,7 @@
|
|
|
22
45
|
#include <micro-os-plus/micro-test-plus.h>
|
|
23
46
|
|
|
24
47
|
#include <stdio.h>
|
|
48
|
+
#include <stdlib.h>
|
|
25
49
|
#include <vector>
|
|
26
50
|
|
|
27
51
|
// ----------------------------------------------------------------------------
|
|
@@ -37,6 +61,15 @@ namespace micro_os_plus::micro_test_plus
|
|
|
37
61
|
{
|
|
38
62
|
// --------------------------------------------------------------------------
|
|
39
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @details
|
|
66
|
+
* The constructor initialises a new instance of the `test_runner` class,
|
|
67
|
+
* preparing the test runner for managing test suites and cases within the
|
|
68
|
+
* µTest++ framework. If tracing is enabled, it outputs the function
|
|
69
|
+
* signature for diagnostic purposes. This setup ensures the test runner is
|
|
70
|
+
* ready to coordinate the registration, execution, and reporting of tests
|
|
71
|
+
* across all test cases and folders.
|
|
72
|
+
*/
|
|
40
73
|
test_runner::test_runner ()
|
|
41
74
|
{
|
|
42
75
|
#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
@@ -48,6 +81,18 @@ namespace micro_os_plus::micro_test_plus
|
|
|
48
81
|
#if defined(__clang__)
|
|
49
82
|
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
50
83
|
#endif
|
|
84
|
+
/**
|
|
85
|
+
* @details
|
|
86
|
+
* This method initialises the test runner by capturing the command-line
|
|
87
|
+
* arguments and the default test suite name, configuring the framework for
|
|
88
|
+
* subsequent test execution. It parses the arguments to determine the
|
|
89
|
+
* desired verbosity level (normal, verbose, quiet, or silent) and applies
|
|
90
|
+
* this setting to the test reporter. The method also outputs build and
|
|
91
|
+
* environment information when appropriate, aiding diagnostics and
|
|
92
|
+
* transparency. Finally, it creates and registers the default test suite,
|
|
93
|
+
* preparing the framework to manage and execute all test cases and suites
|
|
94
|
+
* across the project’s folders.
|
|
95
|
+
*/
|
|
51
96
|
void
|
|
52
97
|
test_runner::initialize (int argc, char* argv[], const char* name)
|
|
53
98
|
{
|
|
@@ -55,6 +100,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
55
100
|
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
56
101
|
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
57
102
|
|
|
103
|
+
#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
|
|
104
|
+
#if defined(_WIN32)
|
|
105
|
+
timespec_get (&begin_time, TIME_UTC);
|
|
106
|
+
#else
|
|
107
|
+
clock_gettime (CLOCK_MONOTONIC, &begin_time);
|
|
108
|
+
#endif
|
|
109
|
+
#endif
|
|
110
|
+
|
|
58
111
|
argc_ = argc;
|
|
59
112
|
argv_ = argv;
|
|
60
113
|
|
|
@@ -76,6 +129,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
76
129
|
#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
|
|
77
130
|
|
|
78
131
|
verbosity_t verbosity = verbosity::normal;
|
|
132
|
+
const char* reporter_name = "tap";
|
|
79
133
|
for (int i = 0; i < argc; ++i)
|
|
80
134
|
{
|
|
81
135
|
if (strcmp (argv[i], "--verbose") == 0)
|
|
@@ -90,10 +144,27 @@ namespace micro_os_plus::micro_test_plus
|
|
|
90
144
|
{
|
|
91
145
|
verbosity = verbosity::silent;
|
|
92
146
|
}
|
|
147
|
+
else if (strncmp (argv[i], "--reporter=", 11) == 0)
|
|
148
|
+
{
|
|
149
|
+
reporter_name = argv[i] + 11;
|
|
150
|
+
}
|
|
93
151
|
}
|
|
94
152
|
|
|
95
|
-
//
|
|
96
|
-
|
|
153
|
+
// Initialize and configure the reporter.
|
|
154
|
+
if (strcmp (reporter_name, "basic") == 0)
|
|
155
|
+
{
|
|
156
|
+
reporter = new test_reporter_basic ();
|
|
157
|
+
}
|
|
158
|
+
else if (strcmp (reporter_name, "tap") == 0)
|
|
159
|
+
{
|
|
160
|
+
reporter = new test_reporter_tap ();
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
{
|
|
164
|
+
fprintf (stderr, "error: unknown reporter '%s'\n", reporter_name);
|
|
165
|
+
exit (1);
|
|
166
|
+
}
|
|
167
|
+
reporter->verbosity = verbosity;
|
|
97
168
|
|
|
98
169
|
// ------------------------------------------------------------------------
|
|
99
170
|
|
|
@@ -133,11 +204,12 @@ namespace micro_os_plus::micro_test_plus
|
|
|
133
204
|
|
|
134
205
|
// ------------------------------------------------------------------------
|
|
135
206
|
|
|
136
|
-
|
|
137
|
-
current_test_suite =
|
|
207
|
+
default_test_suite = new test_suite_base (default_suite_name_);
|
|
208
|
+
current_test_suite = default_test_suite;
|
|
138
209
|
|
|
139
210
|
// Deferred to first test case or test suite end, to allow various
|
|
140
211
|
// initialisations to display their messages.
|
|
212
|
+
// reporter->begin_test (test_suites_count ());
|
|
141
213
|
// default_test_suite_->begin_test_suite ();
|
|
142
214
|
}
|
|
143
215
|
#pragma GCC diagnostic pop
|
|
@@ -147,32 +219,62 @@ namespace micro_os_plus::micro_test_plus
|
|
|
147
219
|
{
|
|
148
220
|
bool was_successful = true;
|
|
149
221
|
|
|
150
|
-
if (!
|
|
222
|
+
if (!default_test_suite->unused ())
|
|
151
223
|
{
|
|
152
|
-
|
|
153
|
-
was_successful =
|
|
224
|
+
default_test_suite->end_test_suite ();
|
|
225
|
+
was_successful = default_test_suite->was_successful ();
|
|
226
|
+
|
|
227
|
+
totals.successful_checks += default_test_suite->successful_checks ();
|
|
228
|
+
totals.failed_checks += default_test_suite->failed_checks ();
|
|
229
|
+
totals.test_cases_count += default_test_suite->test_cases_count ();
|
|
154
230
|
}
|
|
155
231
|
|
|
156
|
-
if (
|
|
232
|
+
if (test_suites != nullptr)
|
|
157
233
|
{
|
|
158
|
-
for (auto
|
|
234
|
+
for (auto test_suite : *test_suites)
|
|
159
235
|
{
|
|
160
|
-
current_test_suite =
|
|
236
|
+
current_test_suite = test_suite;
|
|
237
|
+
|
|
238
|
+
test_suite->begin_test_suite ();
|
|
239
|
+
test_suite->run ();
|
|
240
|
+
test_suite->end_test_suite ();
|
|
161
241
|
|
|
162
|
-
|
|
163
|
-
suite->run ();
|
|
164
|
-
suite->end_test_suite ();
|
|
242
|
+
was_successful &= test_suite->was_successful ();
|
|
165
243
|
|
|
166
|
-
|
|
244
|
+
totals.successful_checks += test_suite->successful_checks ();
|
|
245
|
+
totals.failed_checks += test_suite->failed_checks ();
|
|
246
|
+
totals.test_cases_count += test_suite->test_cases_count ();
|
|
167
247
|
}
|
|
168
|
-
if (reporter
|
|
248
|
+
if (reporter->verbosity != verbosity::silent)
|
|
169
249
|
{
|
|
170
250
|
// printf ("\n");
|
|
171
251
|
}
|
|
172
252
|
}
|
|
253
|
+
|
|
254
|
+
#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
|
|
255
|
+
#if defined(_WIN32)
|
|
256
|
+
timespec_get (&end_time, TIME_UTC);
|
|
257
|
+
#else
|
|
258
|
+
clock_gettime (CLOCK_MONOTONIC, &end_time);
|
|
259
|
+
#endif
|
|
260
|
+
#endif
|
|
261
|
+
|
|
262
|
+
reporter->end_test (*this);
|
|
263
|
+
|
|
173
264
|
return was_successful ? 0 : 1;
|
|
174
265
|
}
|
|
175
266
|
|
|
267
|
+
/**
|
|
268
|
+
* @details
|
|
269
|
+
* This method registers a new test suite with the test runner. If the
|
|
270
|
+
* internal collection of test suites has not yet been created, it is
|
|
271
|
+
* initialised at this point. The provided test suite is then added to the
|
|
272
|
+
* collection, enabling the framework to manage and execute multiple test
|
|
273
|
+
* suites across different files and folders within the project.
|
|
274
|
+
*
|
|
275
|
+
* Called by test suite constructors to register themselves with the
|
|
276
|
+
* runner, enabling automatic management and execution.
|
|
277
|
+
*/
|
|
176
278
|
void
|
|
177
279
|
test_runner::register_test_suite (test_suite_base* suite)
|
|
178
280
|
{
|
|
@@ -180,13 +282,23 @@ namespace micro_os_plus::micro_test_plus
|
|
|
180
282
|
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
181
283
|
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
182
284
|
|
|
183
|
-
if (
|
|
285
|
+
if (test_suites == nullptr)
|
|
184
286
|
{
|
|
185
|
-
|
|
287
|
+
test_suites = new std::vector<test_suite_base*> ();
|
|
186
288
|
}
|
|
187
|
-
|
|
289
|
+
test_suites->push_back (suite);
|
|
290
|
+
suite->index = test_suites->size () + 1;
|
|
188
291
|
}
|
|
189
292
|
|
|
293
|
+
/**
|
|
294
|
+
* @details
|
|
295
|
+
* This method immediately terminates the process by invoking the standard C
|
|
296
|
+
* library `abort()` function. It is used to halt test execution in critical
|
|
297
|
+
* failure scenarios, ensuring that no further tests are run and that the
|
|
298
|
+
* cause of the failure can be promptly investigated. This approach provides
|
|
299
|
+
* a robust mechanism for enforcing strict test outcomes across all test
|
|
300
|
+
* cases and folders.
|
|
301
|
+
*/
|
|
190
302
|
void
|
|
191
303
|
test_runner::abort (void)
|
|
192
304
|
{
|
package/src/test-suite.cpp
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
|
|
3
|
-
* Copyright (c) 2021 Liviu Ionescu. All rights reserved.
|
|
3
|
+
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
|
|
4
4
|
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
-
*
|
|
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
7
|
*
|
|
8
|
-
* If a copy of the license was not distributed with this file, it can
|
|
9
|
-
*
|
|
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
10
|
*
|
|
11
11
|
* Major parts of the code are inspired from v1.1.8 of the Boost UT project,
|
|
12
12
|
* released under the terms of the Boost Version 1.0 Software License,
|
|
@@ -15,6 +15,34 @@
|
|
|
15
15
|
|
|
16
16
|
// ----------------------------------------------------------------------------
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @file
|
|
20
|
+
* @brief C++ source file with implementations for the µTest++ test suite
|
|
21
|
+
* methods.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This source file contains the core implementations for the test suite
|
|
25
|
+
* facilities of the µTest++ framework. It provides the logic for constructing,
|
|
26
|
+
* registering, and managing test suites and their associated test cases. The
|
|
27
|
+
* implementation covers initialisation and clean-up routines, execution of
|
|
28
|
+
* test suites and test cases, tracking of successful and failed checks, and
|
|
29
|
+
* integration with the test reporter for structured output.
|
|
30
|
+
*
|
|
31
|
+
* The design ensures that test suites are non-copyable and non-movable,
|
|
32
|
+
* maintaining unique ownership and consistent state. Flexible support for
|
|
33
|
+
* callable objects enables a wide range of test suite definitions,
|
|
34
|
+
* facilitating expressive and maintainable test organisation across embedded
|
|
35
|
+
* and general C++ projects.
|
|
36
|
+
*
|
|
37
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus`
|
|
38
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
39
|
+
* of naming conflicts.
|
|
40
|
+
*
|
|
41
|
+
* This file must be included when building the µTest++ library.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
// ----------------------------------------------------------------------------
|
|
45
|
+
|
|
18
46
|
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
|
|
19
47
|
#include <micro-os-plus/config.h>
|
|
20
48
|
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
|
|
@@ -34,6 +62,16 @@ namespace micro_os_plus::micro_test_plus
|
|
|
34
62
|
{
|
|
35
63
|
// --------------------------------------------------------------------------
|
|
36
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @details
|
|
67
|
+
* The constructor initialises a new instance of the `test_suite_base` class
|
|
68
|
+
* with the specified name. It sets up the internal state required for
|
|
69
|
+
* managing test cases within the suite. If tracing is enabled, the function
|
|
70
|
+
* signature is output for diagnostic purposes. The default test suite does
|
|
71
|
+
* not require explicit registration, ensuring seamless integration within
|
|
72
|
+
* the µTest++ framework and supporting organised test management across all
|
|
73
|
+
* files and folders.
|
|
74
|
+
*/
|
|
37
75
|
test_suite_base::test_suite_base (const char* name)
|
|
38
76
|
{
|
|
39
77
|
#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|
|
@@ -44,10 +82,26 @@ namespace micro_os_plus::micro_test_plus
|
|
|
44
82
|
// The default test suite needs no registration.
|
|
45
83
|
}
|
|
46
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @details
|
|
87
|
+
* The destructor releases any resources associated with the
|
|
88
|
+
* `test_suite_base` instance. It ensures that the test suite is properly
|
|
89
|
+
* cleaned up after execution, supporting robust and reliable test management
|
|
90
|
+
* across all files and folders within the µTest++ framework.
|
|
91
|
+
*/
|
|
47
92
|
test_suite_base::~test_suite_base ()
|
|
48
93
|
{
|
|
49
94
|
}
|
|
50
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @details
|
|
98
|
+
* This method executes the test suite by invoking its associated callable
|
|
99
|
+
* object. If tracing is enabled, the function signature is output for
|
|
100
|
+
* diagnostic purposes. The method ensures that all test cases grouped within
|
|
101
|
+
* the suite are executed in an organised manner, supporting comprehensive
|
|
102
|
+
* and structured testing across all files and folders within the µTest++
|
|
103
|
+
* framework.
|
|
104
|
+
*/
|
|
51
105
|
void
|
|
52
106
|
test_suite_base::run ()
|
|
53
107
|
{
|
|
@@ -56,46 +110,108 @@ namespace micro_os_plus::micro_test_plus
|
|
|
56
110
|
#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
|
|
57
111
|
}
|
|
58
112
|
|
|
113
|
+
/**
|
|
114
|
+
* @details
|
|
115
|
+
* This method marks the beginning of a test suite's execution. It resets the
|
|
116
|
+
* deferred begin flag and notifies the test reporter to start the suite,
|
|
117
|
+
* passing the suite's name. This ensures that test suite output is clearly
|
|
118
|
+
* delineated and properly initialised, supporting organised and readable
|
|
119
|
+
* reporting across all test cases and folders.
|
|
120
|
+
*/
|
|
59
121
|
void
|
|
60
122
|
test_suite_base::begin_test_suite (void)
|
|
61
123
|
{
|
|
124
|
+
#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
|
|
125
|
+
#if defined(_WIN32)
|
|
126
|
+
timespec_get (&begin_time, TIME_UTC);
|
|
127
|
+
#else
|
|
128
|
+
clock_gettime (CLOCK_MONOTONIC, &begin_time);
|
|
129
|
+
#endif
|
|
130
|
+
#endif
|
|
131
|
+
|
|
62
132
|
process_deferred_begin = false;
|
|
63
133
|
|
|
64
|
-
reporter
|
|
134
|
+
reporter->begin_test_suite (name_);
|
|
65
135
|
}
|
|
66
136
|
|
|
137
|
+
/**
|
|
138
|
+
* @details
|
|
139
|
+
* This method marks the end of a test suite's execution. If the suite's
|
|
140
|
+
* start was deferred, it ensures the suite is properly begun before
|
|
141
|
+
* finalising. The method then notifies the test reporter to conclude the
|
|
142
|
+
* suite, passing a reference to the suite instance. This guarantees that all
|
|
143
|
+
* results are accurately summarised and reported, supporting clear and
|
|
144
|
+
* organised test management across all test cases and folders.
|
|
145
|
+
*/
|
|
67
146
|
void
|
|
68
147
|
test_suite_base::end_test_suite (void)
|
|
69
148
|
{
|
|
70
149
|
if (process_deferred_begin)
|
|
71
150
|
{
|
|
151
|
+
reporter->begin_test (runner.test_suites_count ());
|
|
152
|
+
|
|
72
153
|
begin_test_suite ();
|
|
73
154
|
}
|
|
74
|
-
|
|
155
|
+
|
|
156
|
+
#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
|
|
157
|
+
#if defined(_WIN32)
|
|
158
|
+
timespec_get (&end_time, TIME_UTC);
|
|
159
|
+
#else
|
|
160
|
+
clock_gettime (CLOCK_MONOTONIC, &end_time);
|
|
161
|
+
#endif
|
|
162
|
+
#endif
|
|
163
|
+
reporter->end_test_suite (*this);
|
|
75
164
|
}
|
|
76
165
|
|
|
166
|
+
/**
|
|
167
|
+
* @details
|
|
168
|
+
* This method marks the beginning of a test case within the suite. If the
|
|
169
|
+
* start of the suite was deferred, it ensures the suite is properly begun
|
|
170
|
+
* before proceeding. The method sets the current test case name, increments
|
|
171
|
+
* the total number of test cases, resets the current test case statistics,
|
|
172
|
+
* and notifies the test reporter to begin the test case. This approach
|
|
173
|
+
* guarantees that each test case is clearly identified, accurately tracked,
|
|
174
|
+
* and properly reported across all test cases and folders.
|
|
175
|
+
*/
|
|
77
176
|
void
|
|
78
177
|
test_suite_base::begin_test_case (const char* name)
|
|
79
178
|
{
|
|
80
179
|
if (process_deferred_begin)
|
|
81
180
|
{
|
|
181
|
+
reporter->begin_test (runner.test_suites_count ());
|
|
182
|
+
|
|
82
183
|
begin_test_suite ();
|
|
83
184
|
}
|
|
84
185
|
|
|
85
186
|
test_case_name_ = name;
|
|
86
|
-
++
|
|
187
|
+
++test_cases_count_;
|
|
87
188
|
|
|
88
189
|
current_test_case = {};
|
|
89
190
|
|
|
90
|
-
reporter
|
|
191
|
+
reporter->begin_test_case (test_case_name_);
|
|
91
192
|
}
|
|
92
193
|
|
|
194
|
+
/**
|
|
195
|
+
* @details
|
|
196
|
+
* This method marks the end of a test case within the suite. It notifies the
|
|
197
|
+
* test reporter to conclude the test case, passing the current test case
|
|
198
|
+
* name. This ensures that the results of the test case are accurately
|
|
199
|
+
* finalised and clearly reported, supporting organised and reliable test
|
|
200
|
+
* management across all test cases and folders.
|
|
201
|
+
*/
|
|
93
202
|
void
|
|
94
203
|
test_suite_base::end_test_case (void)
|
|
95
204
|
{
|
|
96
|
-
reporter
|
|
205
|
+
reporter->end_test_case (test_case_name_);
|
|
97
206
|
}
|
|
98
207
|
|
|
208
|
+
/**
|
|
209
|
+
* @details
|
|
210
|
+
* This method increments the count of successful checks for the test suite
|
|
211
|
+
* and the current test case. It ensures that each passing assertion is
|
|
212
|
+
* accurately recorded, supporting precise tracking and reporting of test
|
|
213
|
+
* outcomes across all test cases and folders.
|
|
214
|
+
*/
|
|
99
215
|
void
|
|
100
216
|
test_suite_base::increment_successful (void)
|
|
101
217
|
{
|
|
@@ -103,6 +219,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
103
219
|
++current_test_case.successful_checks;
|
|
104
220
|
}
|
|
105
221
|
|
|
222
|
+
/**
|
|
223
|
+
* @details
|
|
224
|
+
* This method increments the count of failed checks for the test suite and
|
|
225
|
+
* the current test case. It ensures that each failing assertion is
|
|
226
|
+
* accurately recorded, supporting precise tracking and reporting of test
|
|
227
|
+
* outcomes across all test cases and folders.
|
|
228
|
+
*/
|
|
106
229
|
void
|
|
107
230
|
test_suite_base::increment_failed (void)
|
|
108
231
|
{
|
|
@@ -110,8 +233,49 @@ namespace micro_os_plus::micro_test_plus
|
|
|
110
233
|
++current_test_case.failed_checks;
|
|
111
234
|
}
|
|
112
235
|
|
|
236
|
+
#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
|
|
237
|
+
/**
|
|
238
|
+
* @details
|
|
239
|
+
* Subtracts `begin_time` from `end_time` using monotonic clock arithmetic,
|
|
240
|
+
* handling the nanosecond borrow correctly, then splits the result into
|
|
241
|
+
* whole milliseconds and the sub-millisecond remainder expressed in
|
|
242
|
+
* microseconds (0–999).
|
|
243
|
+
*/
|
|
244
|
+
#pragma GCC diagnostic push
|
|
245
|
+
#pragma GCC diagnostic ignored "-Wshadow"
|
|
246
|
+
void
|
|
247
|
+
test_suite_base::compute_elapsed_time (timespec& begin_time,
|
|
248
|
+
timespec& end_time,
|
|
249
|
+
long& milliseconds,
|
|
250
|
+
long& microseconds)
|
|
251
|
+
{
|
|
252
|
+
long long delta_ns = end_time.tv_nsec - begin_time.tv_nsec;
|
|
253
|
+
long long delta_s = end_time.tv_sec - begin_time.tv_sec;
|
|
254
|
+
if (delta_ns < 0)
|
|
255
|
+
{
|
|
256
|
+
delta_ns += 1000000000LL;
|
|
257
|
+
--delta_s;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Split into milliseconds and microseconds.
|
|
261
|
+
const long long total_us = delta_s * 1000000LL + delta_ns / 1000LL;
|
|
262
|
+
milliseconds = static_cast<long> (total_us / 1000LL);
|
|
263
|
+
microseconds = static_cast<long> (total_us % 1000LL);
|
|
264
|
+
}
|
|
265
|
+
#pragma GCC diagnostic pop
|
|
266
|
+
|
|
267
|
+
#endif
|
|
268
|
+
|
|
113
269
|
// ==========================================================================
|
|
114
270
|
|
|
271
|
+
/**
|
|
272
|
+
* @details
|
|
273
|
+
* This method executes the test suite by invoking the stored callable object
|
|
274
|
+
* associated with the suite. It ensures that all test cases registered
|
|
275
|
+
* within the suite are executed in sequence, supporting comprehensive and
|
|
276
|
+
* structured testing across all files and folders within the µTest++
|
|
277
|
+
* framework.
|
|
278
|
+
*/
|
|
115
279
|
void
|
|
116
280
|
test_suite::run (void)
|
|
117
281
|
{
|
|
@@ -119,6 +283,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
119
283
|
callable_ ();
|
|
120
284
|
}
|
|
121
285
|
|
|
286
|
+
/**
|
|
287
|
+
* @details
|
|
288
|
+
* The destructor releases any resources associated with the `test_suite`
|
|
289
|
+
* instance. If tracing is enabled, it outputs the function signature for
|
|
290
|
+
* diagnostic purposes. This ensures that the test suite is properly cleaned
|
|
291
|
+
* up after execution, supporting robust and reliable test management across
|
|
292
|
+
* all files and folders within the µTest++ framework.
|
|
293
|
+
*/
|
|
122
294
|
test_suite::~test_suite ()
|
|
123
295
|
{
|
|
124
296
|
#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
|