@micro-os-plus/micro-test-plus 3.2.0 → 3.2.3

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.
Files changed (42) hide show
  1. package/.cmake-format.yaml +11 -0
  2. package/CHANGELOG.md +502 -11
  3. package/CMakeLists.txt +33 -32
  4. package/LICENSE +1 -1
  5. package/README.md +15 -14
  6. package/config/xcdl-build.json +32 -0
  7. package/include/micro-os-plus/micro-test-plus/detail.h +1885 -0
  8. package/include/micro-os-plus/micro-test-plus/function-comparators.h +333 -0
  9. package/include/micro-os-plus/micro-test-plus/inlines/details-inlines.h +172 -0
  10. package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +341 -0
  11. package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +604 -0
  12. package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +315 -0
  13. package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +313 -0
  14. package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +170 -0
  15. package/include/micro-os-plus/micro-test-plus/inlines/test-reporter-inlines.h +471 -0
  16. package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +115 -0
  17. package/include/micro-os-plus/micro-test-plus/literals.h +912 -0
  18. package/include/micro-os-plus/micro-test-plus/math.h +217 -0
  19. package/include/micro-os-plus/micro-test-plus/operators.h +514 -0
  20. package/include/micro-os-plus/micro-test-plus/reflection.h +233 -0
  21. package/include/micro-os-plus/micro-test-plus/test-reporter.h +801 -0
  22. package/include/micro-os-plus/micro-test-plus/test-runner.h +241 -0
  23. package/include/micro-os-plus/micro-test-plus/test-suite.h +456 -0
  24. package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
  25. package/include/micro-os-plus/micro-test-plus.h +171 -554
  26. package/meson.build +6 -7
  27. package/package.json +40 -32
  28. package/src/micro-test-plus.cpp +143 -42
  29. package/src/test-reporter.cpp +350 -9
  30. package/src/test-runner.cpp +77 -14
  31. package/src/test-suite.cpp +132 -14
  32. package/LICENSE-Boost +0 -23
  33. package/include/micro-os-plus/detail.h +0 -766
  34. package/include/micro-os-plus/inlines.h +0 -204
  35. package/include/micro-os-plus/literals.h +0 -513
  36. package/include/micro-os-plus/math.h +0 -205
  37. package/include/micro-os-plus/reflection.h +0 -139
  38. package/include/micro-os-plus/test-reporter-inlines.h +0 -231
  39. package/include/micro-os-plus/test-reporter.h +0 -357
  40. package/include/micro-os-plus/test-runner.h +0 -133
  41. package/include/micro-os-plus/test-suite.h +0 -307
  42. package/include/micro-os-plus/type-traits.h +0 -390
@@ -1,205 +0,0 @@
1
- /*
2
- * This file is part of the µOS++ distribution.
3
- * (https://github.com/micro-os-plus/)
4
- * Copyright (c) 2021 Liviu Ionescu.
5
- *
6
- * Permission to use, copy, modify, and/or distribute this software
7
- * for any purpose is hereby granted, under the terms of the MIT license.
8
- *
9
- * If a copy of the license was not distributed with this file, it can
10
- * be obtained from <https://opensource.org/licenses/MIT/>.
11
- *
12
- * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
13
- * released under the terms of the Boost Version 1.0 Software License,
14
- * which can be obtained from <https://www.boost.org/LICENSE_1_0.txt>.
15
- */
16
-
17
- #ifndef MICRO_TEST_PLUS_MATH_H_
18
- #define MICRO_TEST_PLUS_MATH_H_
19
-
20
- // ----------------------------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- #include <array>
27
-
28
- // ----------------------------------------------------------------------------
29
-
30
- #if defined(__GNUC__)
31
- #pragma GCC diagnostic push
32
- #pragma GCC diagnostic ignored "-Wconversion"
33
- #if defined(__clang__)
34
- #pragma clang diagnostic ignored "-Wc++98-compat"
35
- #endif
36
- #endif
37
-
38
- namespace micro_os_plus::micro_test_plus
39
- {
40
- // --------------------------------------------------------------------------
41
-
42
- /**
43
- * @brief Local mathematical functions.
44
- *
45
- * Some may have equivalents in the standard library, but may be
46
- * more complicated to use, or have only floating point variants, or
47
- * not be constexpr.
48
- */
49
- namespace math
50
- {
51
- /**
52
- * @brief Generic absolute of any value.
53
- */
54
- template <class T>
55
- [[nodiscard]] constexpr auto
56
- abs (const T t) -> T
57
- {
58
- return t < T{} ? -t : t;
59
- }
60
-
61
- /**
62
- * @brief Generic minimum of two values.
63
- */
64
- template <class T>
65
- [[nodiscard]] constexpr auto
66
- min_value (const T& lhs, const T& rhs) -> const T&
67
- {
68
- return (rhs < lhs) ? rhs : lhs;
69
- }
70
-
71
- /**
72
- * @brief Generic 'power of', to raise base to exponent (base ^ exp).
73
- */
74
- template <class T, class Exp_T>
75
- [[nodiscard]] constexpr auto
76
- pow (const T base, const Exp_T exp) -> T
77
- {
78
- // If the exponent is 0, return 1, otherwise recurse.
79
- return exp ? T (base * pow (base, exp - Exp_T (1))) : T (1);
80
- }
81
-
82
- /**
83
- * @brief Compute the integral value of a number represented as
84
- * an array of characters.
85
- */
86
- template <class T, char... Cs>
87
- [[nodiscard]] constexpr auto
88
- num () -> T
89
- {
90
- // Assume all are digits or dot or apostrophe.
91
- static_assert (
92
- ((Cs == '.' or Cs == '\'' or (Cs >= '0' and Cs <= '9')) and ...));
93
- T result{};
94
- for (const char c : { Cs... })
95
- {
96
- if (c == '.')
97
- {
98
- break;
99
- }
100
- if (c >= '0' and c <= '9')
101
- {
102
- result = result * T (10) + T (c - '0');
103
- }
104
- }
105
- return result;
106
- }
107
-
108
- /**
109
- * @brief Compute the decimals of a number represented as
110
- * an array of characters.
111
- */
112
- template <class T, char... Cs>
113
- [[nodiscard]] constexpr auto
114
- den () -> T
115
- {
116
- constexpr const std::array cs{ Cs... };
117
- T result{};
118
- auto i = 0u;
119
- while (cs[i++] != '.')
120
- {
121
- }
122
-
123
- for (auto j = i; j < sizeof...(Cs); ++j)
124
- {
125
- result += pow (T (10), sizeof...(Cs) - j) * T (cs[j] - '0');
126
- }
127
- return result;
128
- }
129
-
130
- /**
131
- * @brief Compute the number of decimal places of a number represented as
132
- * an array of characters.
133
- */
134
- template <class T, char... Cs>
135
- [[nodiscard]] constexpr auto
136
- den_size () -> T
137
- {
138
- constexpr const std::array cs{ Cs... };
139
- T i{};
140
- #if defined(__GNUC__)
141
- #pragma GCC diagnostic push
142
- #pragma GCC diagnostic ignored "-Wconversion"
143
- #endif
144
- while (cs[i++] != '.')
145
- #if defined(__GNUC__)
146
- #pragma GCC diagnostic pop
147
- #endif
148
- {
149
- }
150
-
151
- return T (sizeof...(Cs)) - i + T (1);
152
- }
153
-
154
- /**
155
- * @brief Compute the number of decimal places of a value,
156
- * up to 7 digits.
157
- */
158
- template <class T, class Value_T>
159
- [[nodiscard]] constexpr auto
160
- den_size (Value_T value) -> T
161
- {
162
- constexpr auto precision = Value_T (1e-7);
163
- T result{};
164
- Value_T tmp{};
165
- do
166
- {
167
- value *= 10;
168
- #if defined(__GNUC__)
169
- #pragma GCC diagnostic push
170
- #if !defined(__clang__) // GCC only
171
- #pragma GCC diagnostic ignored "-Warith-conversion"
172
- #endif
173
- #if defined(__clang__)
174
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
175
- #endif
176
- #endif
177
- tmp = value - T (value);
178
- #if defined(__GNUC__)
179
- #pragma GCC diagnostic pop
180
- #endif
181
- ++result;
182
- }
183
- while (tmp > precision);
184
-
185
- return result;
186
- }
187
-
188
- } // namespace math
189
-
190
- // --------------------------------------------------------------------------
191
- } // namespace micro_os_plus::micro_test_plus
192
-
193
- #if defined(__GNUC__)
194
- #pragma GCC diagnostic pop
195
- #endif
196
-
197
- // ----------------------------------------------------------------------------
198
-
199
- #endif // __cplusplus
200
-
201
- // ----------------------------------------------------------------------------
202
-
203
- #endif // MICRO_TEST_PLUS_MATH_H_
204
-
205
- // ----------------------------------------------------------------------------
@@ -1,139 +0,0 @@
1
- /*
2
- * This file is part of the µOS++ distribution.
3
- * (https://github.com/micro-os-plus/)
4
- * Copyright (c) 2021 Liviu Ionescu.
5
- *
6
- * Permission to use, copy, modify, and/or distribute this software
7
- * for any purpose is hereby granted, under the terms of the MIT license.
8
- *
9
- * If a copy of the license was not distributed with this file, it can
10
- * be obtained from <https://opensource.org/licenses/MIT/>.
11
- *
12
- * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
13
- * released under the terms of the Boost Version 1.0 Software License,
14
- * which can be obtained from <https://www.boost.org/LICENSE_1_0.txt>.
15
- */
16
-
17
- #ifndef MICRO_TEST_PLUS_REFLECTION_H_
18
- #define MICRO_TEST_PLUS_REFLECTION_H_
19
-
20
- // ----------------------------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- #include <string_view>
27
-
28
- #if defined(__cpp_lib_source_location)
29
- #include <source_location>
30
- #endif
31
-
32
- // ----------------------------------------------------------------------------
33
-
34
- #if defined(__GNUC__)
35
- #pragma GCC diagnostic push
36
- #pragma GCC diagnostic ignored "-Wpadded"
37
- #pragma GCC diagnostic ignored "-Waggregate-return"
38
- #if defined(__clang__)
39
- #pragma clang diagnostic ignored "-Wc++98-compat"
40
- #pragma clang diagnostic ignored "-Wunknown-warning-option"
41
- #endif
42
- #endif
43
-
44
- namespace micro_os_plus::micro_test_plus
45
- {
46
- // --------------------------------------------------------------------------
47
-
48
- namespace reflection
49
- {
50
- #if defined(__cpp_lib_source_location)
51
- using source_location = std::source_location;
52
- #else
53
- /**
54
- * @brief Local implementation of the std::source_location.
55
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
56
- */
57
- class source_location
58
- {
59
- public:
60
- [[nodiscard]] static constexpr auto
61
- current (
62
- #if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
63
- const char* file = __builtin_FILE (), int line = __builtin_LINE ()
64
- #else
65
- const char* file = "unknown", int line = {}
66
- #endif
67
- ) noexcept
68
- {
69
- source_location sl{};
70
- sl.file_ = file;
71
- sl.line_ = line;
72
- return sl;
73
- }
74
-
75
- [[nodiscard]] constexpr auto
76
- file_name () const noexcept
77
- {
78
- return file_;
79
- }
80
-
81
- [[nodiscard]] constexpr auto
82
- line () const noexcept
83
- {
84
- return line_;
85
- }
86
-
87
- private:
88
- const char* file_{ "unknown" };
89
- int line_{};
90
- };
91
-
92
- #endif
93
-
94
- const char*
95
- short_name (const char* name);
96
-
97
- // TODO: update for the new namespaces.
98
-
99
- /**
100
- * @brief Parse the __PRETTY_FUNCTION__ macro to extract the type name.
101
- */
102
- template <class T>
103
- [[nodiscard]] constexpr auto
104
- type_name () -> std::string_view
105
- {
106
- #if defined(__clang__)
107
- #pragma GCC diagnostic push
108
- #pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
109
- // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
110
- // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[78]);
111
- return { &__PRETTY_FUNCTION__[78], sizeof (__PRETTY_FUNCTION__) - 80 };
112
- #pragma GCC diagnostic pop
113
- #elif defined(__GNUC__)
114
- // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
115
- // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[93]);
116
- return { &__PRETTY_FUNCTION__[93], sizeof (__PRETTY_FUNCTION__) - 144 };
117
- #else
118
- #error "Unsupported compiler"
119
- return "Unsupported compiler";
120
- #endif
121
- }
122
- } // namespace reflection
123
-
124
- // --------------------------------------------------------------------------
125
- } // namespace micro_os_plus::micro_test_plus
126
-
127
- #if defined(__GNUC__)
128
- #pragma GCC diagnostic pop
129
- #endif
130
-
131
- // ----------------------------------------------------------------------------
132
-
133
- #endif // __cplusplus
134
-
135
- // ----------------------------------------------------------------------------
136
-
137
- #endif // MICRO_TEST_PLUS_REFLECTION_H_
138
-
139
- // ----------------------------------------------------------------------------
@@ -1,231 +0,0 @@
1
- /*
2
- * This file is part of the µOS++ distribution.
3
- * (https://github.com/micro-os-plus/)
4
- * Copyright (c) 2021 Liviu Ionescu.
5
- *
6
- * Permission to use, copy, modify, and/or distribute this software
7
- * for any purpose is hereby granted, under the terms of the MIT license.
8
- *
9
- * If a copy of the license was not distributed with this file, it can
10
- * be obtained from <https://opensource.org/licenses/MIT/>.
11
- *
12
- * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
13
- * released under the terms of the Boost Version 1.0 Software License,
14
- * which can be obtained from <https://www.boost.org/LICENSE_1_0.txt>.
15
- */
16
-
17
- #ifndef MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
18
- #define MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
19
-
20
- // ----------------------------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- #include <stdio.h>
27
- #include <cstring>
28
-
29
- // ----------------------------------------------------------------------------
30
-
31
- #if defined(__GNUC__)
32
- #pragma GCC diagnostic push
33
- #pragma GCC diagnostic ignored "-Waggregate-return"
34
- #if defined(__clang__)
35
- #pragma clang diagnostic ignored "-Wc++98-compat"
36
- #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
37
- #endif
38
- #endif
39
-
40
- namespace micro_os_plus::micro_test_plus
41
- {
42
- // --------------------------------------------------------------------------
43
-
44
- template <typename T>
45
- test_reporter&
46
- test_reporter::operator<< (T* v)
47
- {
48
- char buff[20];
49
- snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
50
- out_.append (buff);
51
-
52
- return *this;
53
- }
54
-
55
- #if 0
56
- template <class T>
57
- test_reporter&
58
- test_reporter::operator<< (const T& t)
59
- {
60
- *this << detail::get (t);
61
- return *this;
62
- }
63
- #endif
64
-
65
- template <class T>
66
- test_reporter&
67
- test_reporter::operator<< (const type_traits::genuine_integral_value<T>& v)
68
- {
69
- out_.append (std::to_string (static_cast<long long> (v.get ())));
70
- return *this;
71
- }
72
-
73
- template <class T,
74
- type_traits::requires_t<type_traits::is_container_v<T>
75
- and not type_traits::has_npos_v<T>>>
76
- test_reporter&
77
- test_reporter::operator<< (T&& t)
78
- {
79
- *this << '{';
80
- auto first = true;
81
- for (const auto& arg : t)
82
- {
83
- *this << (first ? "" : ", ") << arg;
84
- first = false;
85
- }
86
- *this << '}';
87
- return *this;
88
- }
89
-
90
- template <class Lhs_T, class Rhs_T>
91
- test_reporter&
92
- test_reporter::operator<< (const detail::eq_<Lhs_T, Rhs_T>& op)
93
- {
94
- return (*this << color (op) << op.lhs () << " == " << op.rhs ()
95
- << colors_.none);
96
- }
97
-
98
- template <class Lhs_T, class Rhs_T>
99
- test_reporter&
100
- test_reporter::operator<< (const detail::ne_<Lhs_T, Rhs_T>& op)
101
- {
102
- return (*this << color (op) << op.lhs () << " != " << op.rhs ()
103
- << colors_.none);
104
- }
105
-
106
- template <class Lhs_T, class Rhs_T>
107
- test_reporter&
108
- test_reporter::operator<< (const detail::gt_<Lhs_T, Rhs_T>& op)
109
- {
110
- return (*this << color (op) << op.lhs () << " > " << op.rhs ()
111
- << colors_.none);
112
- }
113
-
114
- template <class Lhs_T, class Rhs_T>
115
- test_reporter&
116
- test_reporter::operator<< (const detail::ge_<Lhs_T, Rhs_T>& op)
117
- {
118
- return (*this << color (op) << op.lhs () << " >= " << op.rhs ()
119
- << colors_.none);
120
- }
121
-
122
- template <class Lhs_T, class Rhs_T>
123
- test_reporter&
124
- test_reporter::operator<< (const detail::lt_<Rhs_T, Lhs_T>& op)
125
- {
126
- return (*this << color (op) << op.lhs () << " < " << op.rhs ()
127
- << colors_.none);
128
- }
129
-
130
- template <class Lhs_T, class Rhs_T>
131
- test_reporter&
132
- test_reporter::operator<< (const detail::le_<Rhs_T, Lhs_T>& op)
133
- {
134
- return (*this << color (op) << op.lhs () << " <= " << op.rhs ()
135
- << colors_.none);
136
- }
137
-
138
- template <class Lhs_T, class Rhs_T>
139
- test_reporter&
140
- test_reporter::operator<< (const detail::and_<Lhs_T, Rhs_T>& op)
141
- {
142
- return (*this << '(' << op.lhs () << color (op) << " and " << colors_.none
143
- << op.rhs () << ')');
144
- }
145
-
146
- template <class Lhs_T, class Rhs_T>
147
- test_reporter&
148
- test_reporter::operator<< (const detail::or_<Lhs_T, Rhs_T>& op)
149
- {
150
- return (*this << '(' << op.lhs () << color (op) << " or " << colors_.none
151
- << op.rhs () << ')');
152
- }
153
-
154
- template <class T>
155
- test_reporter&
156
- test_reporter::operator<< (const detail::not_<T>& op)
157
- {
158
- return (*this << color (op) << "not " << op.value () << colors_.none);
159
- }
160
-
161
- #if defined(__cpp_exceptions)
162
- template <class Expr_T, class Exception_T>
163
- test_reporter&
164
- test_reporter::operator<< (const detail::throws_<Expr_T, Exception_T>& op)
165
- {
166
- return (*this << color (op) << "throws<"
167
- << reflection::type_name<Exception_T> () << ">"
168
- << colors_.none);
169
- }
170
-
171
- template <class Expr_T>
172
- test_reporter&
173
- test_reporter::operator<< (const detail::throws_<Expr_T, void>& op)
174
- {
175
- return (*this << color (op) << "throws" << colors_.none);
176
- }
177
-
178
- template <class Expr_T>
179
- test_reporter&
180
- test_reporter::operator<< (const detail::nothrow_<Expr_T>& op)
181
- {
182
- return (*this << color (op) << "nothrow" << colors_.none);
183
- }
184
- #endif
185
-
186
- template <class Expr_T>
187
- void
188
- test_reporter::pass (Expr_T& expr, std::string& message)
189
- {
190
- output_pass_prefix_ (message);
191
-
192
- if (message.empty ())
193
- {
194
- // If there is no message, display the evaluated expression.
195
- *this << expr;
196
- }
197
-
198
- output_pass_suffix_ ();
199
- }
200
-
201
- template <class Expr_T>
202
- void
203
- test_reporter::fail (Expr_T& expr, bool abort, std::string& message,
204
- const reflection::source_location& location)
205
- {
206
- output_fail_prefix_ (message, location);
207
-
208
- if constexpr (type_traits::is_op_v<Expr_T>)
209
- {
210
- *this << ", " << expr;
211
- }
212
-
213
- output_fail_suffix_ (abort);
214
- }
215
-
216
- // --------------------------------------------------------------------------
217
- } // namespace micro_os_plus::micro_test_plus
218
-
219
- #if defined(__GNUC__)
220
- #pragma GCC diagnostic pop
221
- #endif
222
-
223
- // ----------------------------------------------------------------------------
224
-
225
- #endif // __cplusplus
226
-
227
- // ----------------------------------------------------------------------------
228
-
229
- #endif // MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
230
-
231
- // ----------------------------------------------------------------------------