@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,307 +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_SUITE_H_
18
- #define MICRO_TEST_PLUS_TEST_SUITE_H_
19
-
20
- // ----------------------------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- #include <functional>
27
-
28
- // ----------------------------------------------------------------------------
29
-
30
- #if defined(__GNUC__)
31
- #pragma GCC diagnostic push
32
- #pragma GCC diagnostic ignored "-Wpadded"
33
- #if !defined(__clang__) // GCC only
34
- #pragma GCC diagnostic ignored "-Wsuggest-final-types"
35
- #pragma GCC diagnostic ignored "-Wsuggest-final-methods"
36
- #endif
37
- #if defined(__clang__)
38
- #pragma clang diagnostic ignored "-Wc++98-compat"
39
- #endif
40
- #endif
41
-
42
- namespace micro_os_plus::micro_test_plus
43
- {
44
- // --------------------------------------------------------------------------
45
-
46
- /**
47
- * @brief Base class for all test suites.
48
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
49
- */
50
- class test_suite_base
51
- {
52
- public:
53
- /**
54
- * @brief Construct a test suite.
55
- * @param [in] name The test suite name.
56
- */
57
- test_suite_base (const char* name);
58
-
59
- // The rule of five.
60
- test_suite_base (const test_suite_base&) = delete;
61
- test_suite_base (test_suite_base&&) = delete;
62
- test_suite_base&
63
- operator= (const test_suite_base&)
64
- = delete;
65
- test_suite_base&
66
- operator= (test_suite_base&&)
67
- = delete;
68
-
69
- virtual ~test_suite_base ();
70
-
71
- /**
72
- * @brief Run the sequence of test cases in the suite.
73
- * @par Parameters
74
- * None.
75
- * @par Returns
76
- * Nothing.
77
- */
78
- virtual void
79
- run (void);
80
-
81
- /**
82
- * @brief Mark the beginning of a named test case.
83
- * @param [in] name The test case name.
84
- * @par Returns
85
- * Nothing.
86
- */
87
- void
88
- begin_test_case (const char* name);
89
-
90
- /**
91
- * @brief Mark the end of a test case.
92
- * @par Parameters
93
- * None.
94
- * @par Returns
95
- * Nothing.
96
- */
97
- void
98
- end_test_case (void);
99
-
100
- /**
101
- * @brief Get the suite name.
102
- * @par Parameters
103
- * None.
104
- * @return A pointer to the null terminated test suite name.
105
- */
106
- [[nodiscard]] constexpr const char*
107
- name ()
108
- {
109
- return name_;
110
- }
111
-
112
- /**
113
- * @brief Count one more passed test conditions.
114
- * @par Parameters
115
- * None.
116
- * @par Returns
117
- * Nothing.
118
- */
119
- void
120
- increment_successful (void);
121
-
122
- /**
123
- * @brief Count one more failed test conditions.
124
- * @par Parameters
125
- * None.
126
- * @par Returns
127
- * Nothing.
128
- */
129
- void
130
- increment_failed (void);
131
-
132
- /**
133
- * @brief Get the number of conditions that passed.
134
- * @par Parameters
135
- * None.
136
- * @return An integer with the number checks that passed.
137
- */
138
- [[nodiscard]] constexpr int
139
- successful_checks (void)
140
- {
141
- return successful_checks_;
142
- }
143
-
144
- /**
145
- * @brief Get the number of conditions that failed.
146
- * @par Parameters
147
- * None.
148
- * @return An integer with the number checks that failed.
149
- */
150
- [[nodiscard]] constexpr int
151
- failed_checks (void)
152
- {
153
- return failed_checks_;
154
- }
155
-
156
- /**
157
- * @brief Get the number of test cases.
158
- * @par Parameters
159
- * None.
160
- * @return An integer with the number of test cases.
161
- */
162
- [[nodiscard]] constexpr int
163
- test_cases (void)
164
- {
165
- return test_cases_;
166
- }
167
-
168
- /**
169
- * @brief Begin the execution of the test suite.
170
- * @par Parameters
171
- * None.
172
- * @par Returns
173
- * Nothing.
174
- */
175
- void
176
- begin_test_suite (void);
177
-
178
- /**
179
- * @brief Mark the end of the test suite.
180
- * @par Parameters
181
- * None.
182
- * @par Returns
183
- * Nothing.
184
- */
185
- void
186
- end_test_suite (void);
187
-
188
- /**
189
- * @brief Get the test suite result.
190
- * @par Parameters
191
- * None.
192
- * @return True if the test suite was successful.
193
- */
194
- [[nodiscard]] constexpr bool
195
- was_successful (void)
196
- {
197
- // Also fail if none passed.
198
- return (failed_checks_ == 0 && successful_checks_ != 0);
199
- }
200
-
201
- /**
202
- * @brief If all counter are null, it is unused.
203
- * @par Parameters
204
- * None.
205
- * @return True if the test suite is not used.
206
- */
207
- [[nodiscard]] constexpr bool
208
- unused (void)
209
- {
210
- return (failed_checks_ == 0 && successful_checks_ == 0
211
- && test_cases_ == 0);
212
- }
213
-
214
- protected:
215
- /**
216
- * @brief The test suite name.
217
- */
218
- const char* name_;
219
-
220
- /**
221
- * @brief The current test case name.
222
- */
223
- const char* test_case_name_;
224
-
225
- /**
226
- * @brief Count of test conditions that passed.
227
- */
228
- int successful_checks_ = 0;
229
-
230
- /**
231
- * @brief Count of test conditions that failed.
232
- */
233
- int failed_checks_ = 0;
234
-
235
- /**
236
- * @brief Count of test cases in the test suite.
237
- */
238
- int test_cases_ = 0;
239
-
240
- public:
241
- bool process_deferred_begin = true;
242
- struct
243
- {
244
- int successful_checks;
245
- int failed_checks;
246
- } current_test_case{};
247
- };
248
-
249
- /**
250
- * @ingroup micro-test-plus-test-suites
251
- * @brief Test suites are classes that represent a named group of
252
- * test cases which self register to the runner.
253
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
254
- */
255
- class test_suite : public test_suite_base
256
- {
257
- public:
258
- /**
259
- * @brief Construct a test suite.
260
- * @tparam Callable_T The type of an object that can be called.
261
- * @tparam Args_T The type of the callable arguments.
262
- * @param [in] name The test case name or description.
263
- * A short string used in the report.
264
- * @param [in] callable A generic callable object,
265
- * invoked to perform the test. Usually a lambda.
266
- * @param [in] arguments A possibly empty list of arguments to be
267
- * passed to the callable.
268
- */
269
- template <typename Callable_T, typename... Args_T>
270
- test_suite (const char* name, Callable_T&& callable,
271
- Args_T&&... arguments);
272
-
273
- // The rule of five.
274
- test_suite (const test_suite&) = delete;
275
- test_suite (test_suite&&) = delete;
276
- test_suite&
277
- operator= (const test_suite&)
278
- = delete;
279
- test_suite&
280
- operator= (test_suite&&)
281
- = delete;
282
-
283
- virtual ~test_suite () override;
284
-
285
- virtual void
286
- run (void) override;
287
-
288
- protected:
289
- std::function<void (void)> callable_;
290
- };
291
-
292
- // --------------------------------------------------------------------------
293
- } // namespace micro_os_plus::micro_test_plus
294
-
295
- #if defined(__GNUC__)
296
- #pragma GCC diagnostic pop
297
- #endif
298
-
299
- // ----------------------------------------------------------------------------
300
-
301
- #endif // __cplusplus
302
-
303
- // ----------------------------------------------------------------------------
304
-
305
- #endif // MICRO_TEST_PLUS_TEST_SUITE_H_
306
-
307
- // ----------------------------------------------------------------------------
@@ -1,390 +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_TYPE_TRAITS_H_
18
- #define MICRO_TEST_PLUS_TYPE_TRAITS_H_
19
-
20
- // ----------------------------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- #include "math.h"
27
-
28
- // ----------------------------------------------------------------------------
29
-
30
- #if defined(__GNUC__)
31
- #pragma GCC diagnostic push
32
- #if defined(__clang__)
33
- #pragma clang diagnostic ignored "-Wc++98-compat"
34
- #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
35
- #endif
36
- #endif
37
-
38
- namespace micro_os_plus::micro_test_plus
39
- {
40
- // --------------------------------------------------------------------------
41
-
42
- /**
43
- * @brief Local type traits. Some may have standard equivalents, but
44
- * better keep them locally.
45
- */
46
- namespace type_traits
47
- {
48
- /**
49
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
50
- */
51
- template <class...>
52
- struct list
53
- {
54
- };
55
-
56
- /**
57
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
58
- */
59
- template <class T, class...>
60
- struct identity
61
- {
62
- using type = T;
63
- };
64
-
65
- #if defined(__DOXYGEN__)
66
- // error: Detected potential recursive class relation between class
67
- // micro_os_plus::micro_test_plus::type_traits::function_traits and base
68
- // class micro_os_plus::micro_test_plus::type_traits::function_traits<
69
- // decltype(&T::operator())>!
70
- // https://github.com/doxygen/doxygen/issues/9915
71
- #else
72
- template <class T>
73
- struct function_traits : function_traits<decltype (&T::operator())>
74
- {
75
- };
76
- #endif
77
-
78
- /**
79
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
80
- */
81
- template <class R, class... Args_T>
82
- struct function_traits<R (*) (Args_T...)>
83
- {
84
- using result_type = R;
85
- using args = list<Args_T...>;
86
- };
87
-
88
- /**
89
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
90
- */
91
- template <class R, class... Args_T>
92
- struct function_traits<R (Args_T...)>
93
- {
94
- using result_type = R;
95
- using args = list<Args_T...>;
96
- };
97
-
98
- /**
99
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
100
- */
101
- template <class R, class T, class... Args_T>
102
- struct function_traits<R (T::*) (Args_T...)>
103
- {
104
- using result_type = R;
105
- using args = list<Args_T...>;
106
- };
107
-
108
- /**
109
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
110
- */
111
- template <class R, class T, class... Args_T>
112
- struct function_traits<R (T::*) (Args_T...) const>
113
- {
114
- using result_type = R;
115
- using args = list<Args_T...>;
116
- };
117
-
118
- template <class T>
119
- T&&
120
- declval ();
121
- template <class... Ts, class Expr_T>
122
- constexpr auto
123
- is_valid (Expr_T expr) -> decltype (expr (declval<Ts...> ()), bool ())
124
- {
125
- return true;
126
- }
127
-
128
- template <class...>
129
- constexpr auto
130
- is_valid (...) -> bool
131
- {
132
- return false;
133
- }
134
-
135
- template <class T>
136
- static constexpr auto is_container_v = is_valid<T> (
137
- [] (auto t) -> decltype (t.begin (), t.end (), void ()) {});
138
-
139
- template <class T>
140
- static constexpr auto has_npos_v
141
- = is_valid<T> ([] (auto t) -> decltype (void (t.npos)) {});
142
-
143
- template <class T>
144
- static constexpr auto has_value_v
145
- = is_valid<T> ([] (auto t) -> decltype (void (t.value)) {});
146
-
147
- template <class T>
148
- static constexpr auto has_epsilon_v
149
- = is_valid<T> ([] (auto t) -> decltype (void (t.epsilon)) {});
150
-
151
- template <class T>
152
- inline constexpr auto is_floating_point_v = false;
153
- template <>
154
- inline constexpr auto is_floating_point_v<float> = true;
155
- template <>
156
- inline constexpr auto is_floating_point_v<double> = true;
157
- template <>
158
- inline constexpr auto is_floating_point_v<long double> = true;
159
-
160
- #if defined(__clang__) or defined(_MSC_VER)
161
- template <class From, class To>
162
- static constexpr auto is_convertible_v = __is_convertible_to (From, To);
163
- #else
164
- template <class From, class To>
165
- constexpr auto
166
- is_convertible (int) -> decltype (bool (To (declval<From> ())))
167
- {
168
- return true;
169
- }
170
- template <class...>
171
- constexpr auto
172
- is_convertible (...)
173
- {
174
- return false;
175
- }
176
- template <class From, class To>
177
- constexpr auto is_convertible_v = is_convertible<From, To> (0);
178
- #endif
179
-
180
- /**
181
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
182
- */
183
- template <bool>
184
- struct requires_
185
- {
186
- };
187
-
188
- /**
189
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
190
- */
191
- template <>
192
- struct requires_<true>
193
- {
194
- using type = int;
195
- };
196
-
197
- template <bool Cond>
198
- using requires_t = typename requires_<Cond>::type;
199
-
200
- /**
201
- * @brief Empty base class of all operators.
202
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
203
- */
204
- struct op
205
- {
206
- };
207
-
208
- /**
209
- * @brief A generic integral constant.
210
- * It has a getter and a '-' operator to return the negative value.
211
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
212
- */
213
- template <auto N>
214
- struct integral_constant : op
215
- {
216
- using value_type = decltype (N);
217
- static constexpr auto value = N;
218
-
219
- [[nodiscard]] constexpr auto
220
- operator- () const
221
- {
222
- return integral_constant<-N>{};
223
- }
224
-
225
- [[nodiscard]] constexpr explicit
226
- operator value_type () const
227
- {
228
- return N;
229
- }
230
-
231
- [[nodiscard]] constexpr auto
232
- get () const
233
- {
234
- return N;
235
- }
236
- };
237
-
238
- /**
239
- * @brief A generic floating point constant, with custom size
240
- * and precision.
241
- * It has a getter and a '-' operator to return the negative value.
242
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
243
- */
244
- template <class T, auto N, auto D, auto Size, auto P = 1>
245
- struct floating_point_constant : op
246
- {
247
- using value_type = T;
248
-
249
- static constexpr auto epsilon = T (1) / math::pow (T (10), Size - 1);
250
- static constexpr auto value
251
- = T (P) * (T (N) + (T (D) / math::pow (T (10), Size)));
252
-
253
- [[nodiscard]] constexpr auto
254
- operator- () const
255
- {
256
- return floating_point_constant<T, N, D, Size, -1>{};
257
- }
258
-
259
- [[nodiscard]] constexpr explicit
260
- operator value_type () const
261
- {
262
- return value;
263
- }
264
-
265
- [[nodiscard]] constexpr auto
266
- get () const
267
- {
268
- return value;
269
- }
270
- };
271
-
272
- /**
273
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
274
- */
275
- template <class T>
276
- struct genuine_integral_value : op
277
- {
278
- using value_type = T;
279
-
280
- constexpr genuine_integral_value (const T& _value) : value_{ _value }
281
- {
282
- }
283
-
284
- [[nodiscard]] constexpr explicit
285
- operator T () const
286
- {
287
- return value_;
288
- }
289
-
290
- [[nodiscard]] constexpr decltype (auto)
291
- get () const
292
- {
293
- return value_;
294
- }
295
-
296
- T value_{};
297
- };
298
-
299
- template <class T>
300
- inline constexpr auto is_op_v = __is_base_of (type_traits::op, T);
301
-
302
- /**
303
- * @brief Class defining a generic value, accessible via a getter.
304
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
305
- */
306
- template <class T, class = int>
307
- struct value : type_traits::op
308
- {
309
- using value_type = T;
310
-
311
- constexpr value (const T& _value) : value_{ _value }
312
- {
313
- }
314
-
315
- [[nodiscard]] constexpr explicit
316
- operator T () const
317
- {
318
- return value_;
319
- }
320
-
321
- [[nodiscard]] constexpr decltype (auto)
322
- get () const
323
- {
324
- return value_;
325
- }
326
-
327
- T value_{};
328
- };
329
-
330
- /**
331
- * @brief A generic value used to define floating points, which,
332
- * in addition to the actual value, has an epsilon, to use the
333
- * desired precision during comparisons.
334
- * If missing, the default is 1 / (10^decimals).
335
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
336
- */
337
- template <class T>
338
- struct value<T,
339
- type_traits::requires_t<type_traits::is_floating_point_v<T>>>
340
- : type_traits::op
341
- {
342
- using value_type = T;
343
- static inline auto epsilon = T{}; // Why static?
344
-
345
- constexpr value (const T& _value, const T precision) : value_{ _value }
346
- {
347
- epsilon = precision;
348
- }
349
-
350
- constexpr /*explicit(false)*/ value (const T& val)
351
- : value{ val,
352
- T (1)
353
- / math::pow (T (10),
354
- math::den_size<unsigned long long> (val)) }
355
- {
356
- }
357
-
358
- [[nodiscard]] constexpr explicit
359
- operator T () const
360
- {
361
- return value_;
362
- }
363
-
364
- [[nodiscard]] constexpr decltype (auto)
365
- get () const
366
- {
367
- return value_;
368
- }
369
-
370
- T value_{};
371
- };
372
-
373
- } // namespace type_traits
374
-
375
- // --------------------------------------------------------------------------
376
- } // namespace micro_os_plus::micro_test_plus
377
-
378
- #if defined(__GNUC__)
379
- #pragma GCC diagnostic pop
380
- #endif
381
-
382
- // ----------------------------------------------------------------------------
383
-
384
- #endif // __cplusplus
385
-
386
- // ----------------------------------------------------------------------------
387
-
388
- #endif // MICRO_TEST_PLUS_TYPE_TRAITS_H_
389
-
390
- // ----------------------------------------------------------------------------