@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
|
@@ -0,0 +1,170 @@
|
|
|
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++
|
|
21
|
+
* reflection utilities.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the inline implementations for the reflection utilities
|
|
25
|
+
* used within the µTest++ framework. It includes the logic for capturing and
|
|
26
|
+
* reporting source location information, such as file names and line numbers,
|
|
27
|
+
* as well as utilities for extracting type names at compile time using
|
|
28
|
+
* compiler-specific macros.
|
|
29
|
+
*
|
|
30
|
+
* The `source_location` implementation offers a lightweight,
|
|
31
|
+
* constexpr-compatible alternative to `std::source_location`, enabling
|
|
32
|
+
* enhanced diagnostics and reporting even in environments lacking C++20
|
|
33
|
+
* support. The `type_name` utility leverages compiler intrinsics to obtain
|
|
34
|
+
* human-readable type names for improved test output and debugging.
|
|
35
|
+
*
|
|
36
|
+
* All definitions reside within the
|
|
37
|
+
* `micro_os_plus::micro_test_plus::reflection` namespace, ensuring clear
|
|
38
|
+
* separation from user code and minimising the risk of naming conflicts.
|
|
39
|
+
*
|
|
40
|
+
* The header files are organised within the
|
|
41
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
42
|
+
* modular codebase.
|
|
43
|
+
*
|
|
44
|
+
* This file is intended solely for internal use within the framework and
|
|
45
|
+
* should not be included directly by user code.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
#ifndef MICRO_TEST_PLUS_REFLECTION_INLINES_H_
|
|
49
|
+
#define MICRO_TEST_PLUS_REFLECTION_INLINES_H_
|
|
50
|
+
|
|
51
|
+
// ----------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
#ifdef __cplusplus
|
|
54
|
+
|
|
55
|
+
// ----------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
#include <cstdint>
|
|
58
|
+
|
|
59
|
+
// #include "type-traits.h"
|
|
60
|
+
|
|
61
|
+
// ----------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
#if defined(__GNUC__)
|
|
64
|
+
#pragma GCC diagnostic push
|
|
65
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
66
|
+
#if defined(__clang__)
|
|
67
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
68
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
69
|
+
#endif
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
namespace micro_os_plus::micro_test_plus
|
|
73
|
+
{
|
|
74
|
+
// --------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
namespace reflection
|
|
77
|
+
{
|
|
78
|
+
// ------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
#if !defined(__cpp_lib_source_location)
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @details
|
|
84
|
+
* Returns a `source_location` instance representing the file name and
|
|
85
|
+
* line number at the point of invocation.
|
|
86
|
+
*
|
|
87
|
+
* If supported by the compiler, uses built-in macros to capture this
|
|
88
|
+
* information; otherwise, defaults to `"unknown"` and zero.
|
|
89
|
+
*/
|
|
90
|
+
[[nodiscard]] constexpr source_location
|
|
91
|
+
source_location::current (const char* file, unsigned int line) noexcept
|
|
92
|
+
{
|
|
93
|
+
source_location sl{};
|
|
94
|
+
sl.file_ = file;
|
|
95
|
+
sl.line_ = line;
|
|
96
|
+
return sl;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @details
|
|
101
|
+
* ... TBD
|
|
102
|
+
*/
|
|
103
|
+
[[nodiscard]] constexpr auto
|
|
104
|
+
source_location::file_name (void) const noexcept
|
|
105
|
+
{
|
|
106
|
+
return file_;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @details
|
|
111
|
+
* ... TBD
|
|
112
|
+
*/
|
|
113
|
+
[[nodiscard]] constexpr auto
|
|
114
|
+
source_location::line (void) const noexcept
|
|
115
|
+
{
|
|
116
|
+
return line_;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @details
|
|
123
|
+
* This function template parses the compiler-specific
|
|
124
|
+
* `__PRETTY_FUNCTION__` macro to extract a concise type name for the
|
|
125
|
+
* template parameter \c T.
|
|
126
|
+
*
|
|
127
|
+
* The implementation is compiler-dependent and may require adjustment for
|
|
128
|
+
* different toolchains. It is primarily intended for internal use within
|
|
129
|
+
* the µTest++ framework to support improved diagnostics and reporting.
|
|
130
|
+
*/
|
|
131
|
+
template <class T>
|
|
132
|
+
[[nodiscard]] constexpr auto
|
|
133
|
+
type_name (void) -> std::string_view
|
|
134
|
+
{
|
|
135
|
+
#if defined(__clang__)
|
|
136
|
+
#pragma GCC diagnostic push
|
|
137
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
138
|
+
// printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
|
|
139
|
+
// (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[78]);
|
|
140
|
+
return { &__PRETTY_FUNCTION__[78], sizeof (__PRETTY_FUNCTION__) - 80 };
|
|
141
|
+
#pragma GCC diagnostic pop
|
|
142
|
+
#elif defined(__GNUC__)
|
|
143
|
+
// printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
|
|
144
|
+
// (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[93]);
|
|
145
|
+
return { &__PRETTY_FUNCTION__[93], sizeof (__PRETTY_FUNCTION__) - 144 };
|
|
146
|
+
#else
|
|
147
|
+
#error "Unsupported compiler"
|
|
148
|
+
return "Unsupported compiler";
|
|
149
|
+
#endif
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ------------------------------------------------------------------------
|
|
153
|
+
} // namespace reflection
|
|
154
|
+
|
|
155
|
+
// --------------------------------------------------------------------------
|
|
156
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
157
|
+
|
|
158
|
+
#if defined(__GNUC__)
|
|
159
|
+
#pragma GCC diagnostic pop
|
|
160
|
+
#endif
|
|
161
|
+
|
|
162
|
+
// ----------------------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
#endif // __cplusplus
|
|
165
|
+
|
|
166
|
+
// ----------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
#endif // MICRO_TEST_PLUS_REFLECTION_INLINES_H_
|
|
169
|
+
|
|
170
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,476 @@
|
|
|
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
|
+
* reporter.
|
|
22
|
+
*
|
|
23
|
+
* @details
|
|
24
|
+
* This header provides the inline implementations for the test reporting
|
|
25
|
+
* facilities used within the µTest++ framework. It defines the logic for
|
|
26
|
+
* formatting and outputting test results, including operator overloads for
|
|
27
|
+
* various value types, containers, and comparison expressions, as well as
|
|
28
|
+
* structured output for logical and exception-related assertions.
|
|
29
|
+
*
|
|
30
|
+
* The implementations ensure that test outcomes are presented in a clear,
|
|
31
|
+
* consistent, and expressive manner, supporting both value and pointer
|
|
32
|
+
* semantics, and providing detailed diagnostics for both successful and failed
|
|
33
|
+
* test cases. Special attention is given to formatting, colour highlighting,
|
|
34
|
+
* and extensibility, enabling professional and readable test reports suitable
|
|
35
|
+
* for embedded and general C++ development.
|
|
36
|
+
*
|
|
37
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus::detail`
|
|
38
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
39
|
+
* of naming conflicts.
|
|
40
|
+
*
|
|
41
|
+
* The header files are organised within the
|
|
42
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
43
|
+
* modular codebase.
|
|
44
|
+
*
|
|
45
|
+
* This file is intended solely for internal use within the framework and
|
|
46
|
+
* should not be included directly by user code.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
#ifndef MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
|
|
50
|
+
#define MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
|
|
51
|
+
|
|
52
|
+
// ----------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
#ifdef __cplusplus
|
|
55
|
+
|
|
56
|
+
// ----------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
#include <stdio.h>
|
|
59
|
+
#include <cstring>
|
|
60
|
+
|
|
61
|
+
// ----------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
#if defined(__GNUC__)
|
|
64
|
+
#pragma GCC diagnostic push
|
|
65
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
66
|
+
#if defined(__clang__)
|
|
67
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
68
|
+
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
69
|
+
#endif
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
namespace micro_os_plus::micro_test_plus
|
|
73
|
+
{
|
|
74
|
+
// --------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @details
|
|
78
|
+
* This operator overload enables the `test_reporter` to output pointer
|
|
79
|
+
* values in a consistent and readable hexadecimal format.
|
|
80
|
+
*
|
|
81
|
+
* The pointer is formatted as a string using `snprintf` with the `%p` format
|
|
82
|
+
* specifier, ensuring portability across platforms. The resulting string is
|
|
83
|
+
* appended to the internal output buffer, allowing pointer values to be
|
|
84
|
+
* included in test reports and diagnostics.
|
|
85
|
+
*
|
|
86
|
+
* This approach provides clear and unambiguous representation of pointer
|
|
87
|
+
* addresses, which is particularly useful for debugging and verifying
|
|
88
|
+
* pointer-related test cases.
|
|
89
|
+
*/
|
|
90
|
+
template <typename T>
|
|
91
|
+
test_reporter&
|
|
92
|
+
test_reporter::operator<< (T* v)
|
|
93
|
+
{
|
|
94
|
+
char buff[20];
|
|
95
|
+
snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
|
|
96
|
+
out_.append (buff);
|
|
97
|
+
|
|
98
|
+
return *this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#if 0
|
|
102
|
+
/**
|
|
103
|
+
* @details
|
|
104
|
+
* This operator overload enables the `test_reporter` to output any type that is supported by the `detail::get` mechanism, ensuring consistent formatting and extensibility.
|
|
105
|
+
*
|
|
106
|
+
* By delegating to `detail::get`, the operator allows for custom formatting and extraction of values, supporting a wide range of types including user-defined and framework-specific types. The resulting value is then forwarded to the appropriate output handler, ensuring seamless integration into test reports and diagnostics.
|
|
107
|
+
*
|
|
108
|
+
* This approach promotes flexibility and maintainability, allowing new types to be supported with minimal changes to the reporting infrastructure.
|
|
109
|
+
*/
|
|
110
|
+
template <class T>
|
|
111
|
+
test_reporter&
|
|
112
|
+
test_reporter::operator<< (const T& t)
|
|
113
|
+
{
|
|
114
|
+
*this << detail::get (t);
|
|
115
|
+
return *this;
|
|
116
|
+
}
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @details
|
|
121
|
+
* This operator overload enables the `test_reporter` to output
|
|
122
|
+
* strongly-typed integral values in a clear and consistent decimal format.
|
|
123
|
+
*
|
|
124
|
+
* The value is converted to a string using `std::to_string` after being cast
|
|
125
|
+
* to `long long`, ensuring accurate formatting and compatibility across
|
|
126
|
+
* platforms. The resulting string is appended to the internal output buffer,
|
|
127
|
+
* allowing integral values to be included in test reports and diagnostics.
|
|
128
|
+
*
|
|
129
|
+
* This approach ensures precise and unambiguous representation of integral
|
|
130
|
+
* values, which is particularly advantageous for verifying test results and
|
|
131
|
+
* facilitating debugging.
|
|
132
|
+
*/
|
|
133
|
+
template <class T>
|
|
134
|
+
test_reporter&
|
|
135
|
+
test_reporter::operator<< (const type_traits::genuine_integral_value<T>& v)
|
|
136
|
+
{
|
|
137
|
+
out_.append (std::to_string (static_cast<long long> (v.get ())));
|
|
138
|
+
return *this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @details
|
|
143
|
+
* This operator overload enables the `test_reporter` to output container
|
|
144
|
+
* types in a structured and readable format.
|
|
145
|
+
*
|
|
146
|
+
* The contents of the container are enclosed in curly braces and each
|
|
147
|
+
* element is separated by a comma and a space. The operator iterates over
|
|
148
|
+
* the container, formatting each element in sequence, which ensures clarity
|
|
149
|
+
* and consistency in test reports and diagnostics.
|
|
150
|
+
*
|
|
151
|
+
* This approach provides a clear visual representation of container
|
|
152
|
+
* contents, making it easier to interpret test results and debug issues
|
|
153
|
+
* involving collections of values.
|
|
154
|
+
*/
|
|
155
|
+
template <class T,
|
|
156
|
+
type_traits::requires_t<type_traits::is_container_v<T>
|
|
157
|
+
and not type_traits::has_npos_v<T>>>
|
|
158
|
+
test_reporter&
|
|
159
|
+
test_reporter::operator<< (T&& t)
|
|
160
|
+
{
|
|
161
|
+
*this << '{';
|
|
162
|
+
auto first = true;
|
|
163
|
+
for (const auto& arg : t)
|
|
164
|
+
{
|
|
165
|
+
*this << (first ? "" : ", ") << arg;
|
|
166
|
+
first = false;
|
|
167
|
+
}
|
|
168
|
+
*this << '}';
|
|
169
|
+
return *this;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @details
|
|
174
|
+
* This operator overload enables the `test_reporter` to output equality
|
|
175
|
+
* comparison expressions in a clear and expressive format.
|
|
176
|
+
*
|
|
177
|
+
* The left-hand side and right-hand side values are formatted and separated
|
|
178
|
+
* by the equality operator (`==`), with appropriate colour highlighting
|
|
179
|
+
* applied for improved readability in test reports and diagnostics. This
|
|
180
|
+
* structured output assists in quickly identifying the values involved in
|
|
181
|
+
* equality assertions and facilitates efficient debugging of test failures.
|
|
182
|
+
*/
|
|
183
|
+
template <class Lhs_T, class Rhs_T>
|
|
184
|
+
test_reporter&
|
|
185
|
+
test_reporter::operator<< (const detail::eq_<Lhs_T, Rhs_T>& op)
|
|
186
|
+
{
|
|
187
|
+
return (*this << color (op) << op.lhs () << " == " << op.rhs ()
|
|
188
|
+
<< colors_.none);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @details
|
|
193
|
+
* This operator overload enables the `test_reporter` to output inequality
|
|
194
|
+
* comparison expressions in a clear and expressive format.
|
|
195
|
+
*
|
|
196
|
+
* The left-hand side and right-hand side values are formatted and separated
|
|
197
|
+
* by the inequality operator (`!=`), with appropriate colour highlighting
|
|
198
|
+
* applied for improved readability in test reports and diagnostics. This
|
|
199
|
+
* structured output assists in quickly identifying the values involved in
|
|
200
|
+
* inequality assertions and facilitates efficient debugging of test
|
|
201
|
+
* failures.
|
|
202
|
+
*/
|
|
203
|
+
template <class Lhs_T, class Rhs_T>
|
|
204
|
+
test_reporter&
|
|
205
|
+
test_reporter::operator<< (const detail::ne_<Lhs_T, Rhs_T>& op)
|
|
206
|
+
{
|
|
207
|
+
return (*this << color (op) << op.lhs () << " != " << op.rhs ()
|
|
208
|
+
<< colors_.none);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @details
|
|
213
|
+
* This operator overload enables the `test_reporter` to output greater-than
|
|
214
|
+
* comparison expressions in a clear and expressive format.
|
|
215
|
+
*
|
|
216
|
+
* The left-hand side and right-hand side values are formatted and separated
|
|
217
|
+
* by the greater-than operator (`>`), with appropriate colour highlighting
|
|
218
|
+
* applied for improved readability in test reports and diagnostics. This
|
|
219
|
+
* structured output assists in quickly identifying the values involved in
|
|
220
|
+
* greater-than assertions and facilitates efficient debugging of test
|
|
221
|
+
* failures.
|
|
222
|
+
*/
|
|
223
|
+
template <class Lhs_T, class Rhs_T>
|
|
224
|
+
test_reporter&
|
|
225
|
+
test_reporter::operator<< (const detail::gt_<Lhs_T, Rhs_T>& op)
|
|
226
|
+
{
|
|
227
|
+
return (*this << color (op) << op.lhs () << " > " << op.rhs ()
|
|
228
|
+
<< colors_.none);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @details
|
|
233
|
+
* This operator overload enables the `test_reporter` to output
|
|
234
|
+
* greater-than-or-equal-to comparison expressions in a clear and expressive
|
|
235
|
+
* format.
|
|
236
|
+
*
|
|
237
|
+
* The left-hand side and right-hand side values are formatted and separated
|
|
238
|
+
* by the greater-than-or-equal-to operator (`>=`), with appropriate colour
|
|
239
|
+
* highlighting applied for improved readability in test reports and
|
|
240
|
+
* diagnostics. This structured output assists in quickly identifying the
|
|
241
|
+
* values involved in greater-than-or-equal-to assertions and facilitates
|
|
242
|
+
* efficient debugging of test failures.
|
|
243
|
+
*/
|
|
244
|
+
template <class Lhs_T, class Rhs_T>
|
|
245
|
+
test_reporter&
|
|
246
|
+
test_reporter::operator<< (const detail::ge_<Lhs_T, Rhs_T>& op)
|
|
247
|
+
{
|
|
248
|
+
return (*this << color (op) << op.lhs () << " >= " << op.rhs ()
|
|
249
|
+
<< colors_.none);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @details
|
|
254
|
+
* This operator overload enables the `test_reporter` to output less-than
|
|
255
|
+
* comparison expressions in a clear and expressive format.
|
|
256
|
+
*
|
|
257
|
+
* The left-hand side and right-hand side values are formatted and separated
|
|
258
|
+
* by the less-than operator (`<`), with appropriate colour highlighting
|
|
259
|
+
* applied for improved readability in test reports and diagnostics. This
|
|
260
|
+
* structured output assists in quickly identifying the values involved in
|
|
261
|
+
* less-than assertions and facilitates efficient debugging of test failures.
|
|
262
|
+
*/
|
|
263
|
+
template <class Lhs_T, class Rhs_T>
|
|
264
|
+
test_reporter&
|
|
265
|
+
test_reporter::operator<< (const detail::lt_<Rhs_T, Lhs_T>& op)
|
|
266
|
+
{
|
|
267
|
+
return (*this << color (op) << op.lhs () << " < " << op.rhs ()
|
|
268
|
+
<< colors_.none);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @details
|
|
273
|
+
* This operator overload enables the `test_reporter` to output
|
|
274
|
+
* less-than-or-equal-to comparison expressions in a clear and expressive
|
|
275
|
+
* format.
|
|
276
|
+
*
|
|
277
|
+
* The left-hand side and right-hand side values are formatted and separated
|
|
278
|
+
* by the less-than-or-equal-to operator (`<=`), with appropriate colour
|
|
279
|
+
* highlighting applied for improved readability in test reports and
|
|
280
|
+
* diagnostics. This structured output assists in quickly identifying the
|
|
281
|
+
* values involved in less-than-or-equal-to assertions and facilitates
|
|
282
|
+
* efficient debugging of test failures.
|
|
283
|
+
*/
|
|
284
|
+
template <class Lhs_T, class Rhs_T>
|
|
285
|
+
test_reporter&
|
|
286
|
+
test_reporter::operator<< (const detail::le_<Rhs_T, Lhs_T>& op)
|
|
287
|
+
{
|
|
288
|
+
return (*this << color (op) << op.lhs () << " <= " << op.rhs ()
|
|
289
|
+
<< colors_.none);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @details
|
|
294
|
+
* This operator overload enables the `test_reporter` to output logical
|
|
295
|
+
* conjunction (AND) expressions in a clear and structured format.
|
|
296
|
+
*
|
|
297
|
+
* The left-hand side and right-hand side expressions are enclosed in
|
|
298
|
+
* parentheses and separated by the word "and", with appropriate colour
|
|
299
|
+
* highlighting applied for improved readability in test reports and
|
|
300
|
+
* diagnostics. This presentation assists in quickly identifying the
|
|
301
|
+
* components of logical assertions and facilitates efficient debugging of
|
|
302
|
+
* test failures involving compound conditions.
|
|
303
|
+
*/
|
|
304
|
+
template <class Lhs_T, class Rhs_T>
|
|
305
|
+
test_reporter&
|
|
306
|
+
test_reporter::operator<< (const detail::and_<Lhs_T, Rhs_T>& op)
|
|
307
|
+
{
|
|
308
|
+
return (*this << '(' << op.lhs () << color (op) << " and " << colors_.none
|
|
309
|
+
<< op.rhs () << ')');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @details
|
|
314
|
+
* This operator overload enables the `test_reporter` to output logical
|
|
315
|
+
* disjunction (OR) expressions in a clear and structured format.
|
|
316
|
+
*
|
|
317
|
+
* The left-hand side and right-hand side expressions are enclosed in
|
|
318
|
+
* parentheses and separated by the word "or", with appropriate colour
|
|
319
|
+
* highlighting applied for improved readability in test reports and
|
|
320
|
+
* diagnostics. This presentation assists in quickly identifying the
|
|
321
|
+
* components of logical assertions and facilitates efficient debugging of
|
|
322
|
+
* test failures involving compound conditions.
|
|
323
|
+
*/
|
|
324
|
+
template <class Lhs_T, class Rhs_T>
|
|
325
|
+
test_reporter&
|
|
326
|
+
test_reporter::operator<< (const detail::or_<Lhs_T, Rhs_T>& op)
|
|
327
|
+
{
|
|
328
|
+
return (*this << '(' << op.lhs () << color (op) << " or " << colors_.none
|
|
329
|
+
<< op.rhs () << ')');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @details
|
|
334
|
+
* This operator overload enhances readability and clarity by formatting the
|
|
335
|
+
* output when handling negated expressions. It applies colour styling for
|
|
336
|
+
* improved distinction and appends the negated value accordingly, ensuring
|
|
337
|
+
* that logical negations are clearly represented in test reports and
|
|
338
|
+
* diagnostics.
|
|
339
|
+
*/
|
|
340
|
+
template <class T>
|
|
341
|
+
test_reporter&
|
|
342
|
+
test_reporter::operator<< (const detail::not_<T>& op)
|
|
343
|
+
{
|
|
344
|
+
return (*this << color (op) << "not " << op.value () << colors_.none);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
#if defined(__cpp_exceptions)
|
|
348
|
+
/**
|
|
349
|
+
* @details
|
|
350
|
+
* This operator overload provides structured output for expressions that may
|
|
351
|
+
* throw exceptions. It applies colour styling for clarity and includes the
|
|
352
|
+
* exception type name for precise identification.
|
|
353
|
+
*
|
|
354
|
+
* When invoked, the output highlights the `throws` qualifier along with the
|
|
355
|
+
* specific exception type, making it immediately apparent which exception is
|
|
356
|
+
* expected. This enhances the readability and professionalism of test
|
|
357
|
+
* reports, and assists in the precise identification and debugging of
|
|
358
|
+
* exception-related test cases.
|
|
359
|
+
*/
|
|
360
|
+
template <class Expr_T, class Exception_T>
|
|
361
|
+
test_reporter&
|
|
362
|
+
test_reporter::operator<< (const detail::throws_<Expr_T, Exception_T>& op)
|
|
363
|
+
{
|
|
364
|
+
return (*this << color (op) << "throws<"
|
|
365
|
+
<< reflection::type_name<Exception_T> () << ">"
|
|
366
|
+
<< colors_.none);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* @details
|
|
371
|
+
* This operator overload formats output for expressions that may throw
|
|
372
|
+
* exceptions. It applies colour styling for clarity and ensures a structured
|
|
373
|
+
* representation of the exception handling mechanism.
|
|
374
|
+
*
|
|
375
|
+
* When invoked, the output highlights the `throws` qualifier, making it
|
|
376
|
+
* immediately apparent when an expression is expected to throw, thereby
|
|
377
|
+
* improving the readability and professionalism of the test output.
|
|
378
|
+
*/
|
|
379
|
+
template <class Expr_T>
|
|
380
|
+
test_reporter&
|
|
381
|
+
test_reporter::operator<< (const detail::throws_<Expr_T, void>& op)
|
|
382
|
+
{
|
|
383
|
+
return (*this << color (op) << "throws" << colors_.none);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* @details
|
|
388
|
+
* This operator overload formats output for expressions that do not throw
|
|
389
|
+
* exceptions. It applies colour styling for clarity and ensures a structured
|
|
390
|
+
* and concise representation of exception safety within test reports.
|
|
391
|
+
*
|
|
392
|
+
* The output highlights the `nothrow` qualifier, making it immediately
|
|
393
|
+
* apparent when an expression is guaranteed not to throw, thereby improving
|
|
394
|
+
* the readability and professionalism of the test output.
|
|
395
|
+
*/
|
|
396
|
+
template <class Expr_T>
|
|
397
|
+
test_reporter&
|
|
398
|
+
test_reporter::operator<< (const detail::nothrow_<Expr_T>& op)
|
|
399
|
+
{
|
|
400
|
+
return (*this << color (op) << "nothrow" << colors_.none);
|
|
401
|
+
}
|
|
402
|
+
#endif
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @details
|
|
406
|
+
* This operator overload formats output for expressions that do not throw
|
|
407
|
+
* exceptions. It applies colour styling for clarity and ensures a structured
|
|
408
|
+
* representation of exception safety.
|
|
409
|
+
*
|
|
410
|
+
* When invoked, the function outputs a pass prefix, followed by either the
|
|
411
|
+
* provided message or, if the message is empty, the evaluated expression
|
|
412
|
+
* itself. It then appends a pass suffix to complete the output. This
|
|
413
|
+
* approach guarantees that successful test outcomes are presented in a clear
|
|
414
|
+
* and consistent manner, enhancing the readability and professionalism of
|
|
415
|
+
* test reports.
|
|
416
|
+
*/
|
|
417
|
+
template <class Expr_T>
|
|
418
|
+
void
|
|
419
|
+
test_reporter::pass (Expr_T& expr, std::string& message)
|
|
420
|
+
{
|
|
421
|
+
current_test_suite->current_test_case.index++;
|
|
422
|
+
|
|
423
|
+
output_pass_prefix_ (message);
|
|
424
|
+
|
|
425
|
+
if (message.empty ())
|
|
426
|
+
{
|
|
427
|
+
// If there is no message, display the evaluated expression.
|
|
428
|
+
*this << expr;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
output_pass_suffix_ ();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* @details
|
|
436
|
+
* This function reports a test failure and formats the output in a clear and
|
|
437
|
+
* consistent manner. It provides contextual information, including the
|
|
438
|
+
* precise source location, and appends the evaluated expression when
|
|
439
|
+
* applicable. The failure handling process ensures uniformity in the
|
|
440
|
+
* presentation of unsuccessful test cases, aiding in the rapid
|
|
441
|
+
* identification and diagnosis of issues within test reports.
|
|
442
|
+
*/
|
|
443
|
+
template <class Expr_T>
|
|
444
|
+
void
|
|
445
|
+
test_reporter::fail (Expr_T& expr, bool abort, std::string& message,
|
|
446
|
+
const reflection::source_location& location)
|
|
447
|
+
{
|
|
448
|
+
current_test_suite->current_test_case.index++;
|
|
449
|
+
|
|
450
|
+
const bool hasExpression = type_traits::is_op_v<Expr_T>;
|
|
451
|
+
output_fail_prefix_ (message, hasExpression, location);
|
|
452
|
+
|
|
453
|
+
if constexpr (type_traits::is_op_v<Expr_T>)
|
|
454
|
+
{
|
|
455
|
+
*this << expr;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
output_fail_suffix_ (location, abort);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// --------------------------------------------------------------------------
|
|
462
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
463
|
+
|
|
464
|
+
#if defined(__GNUC__)
|
|
465
|
+
#pragma GCC diagnostic pop
|
|
466
|
+
#endif
|
|
467
|
+
|
|
468
|
+
// ----------------------------------------------------------------------------
|
|
469
|
+
|
|
470
|
+
#endif // __cplusplus
|
|
471
|
+
|
|
472
|
+
// ----------------------------------------------------------------------------
|
|
473
|
+
|
|
474
|
+
#endif // MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
|
|
475
|
+
|
|
476
|
+
// ----------------------------------------------------------------------------
|