@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,357 +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_H_
18
- #define MICRO_TEST_PLUS_TEST_REPORTER_H_
19
-
20
- // ----------------------------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- // #include <functional>
27
- #include <string_view>
28
- #include <string>
29
-
30
- #include "type-traits.h"
31
- #include "test-suite.h"
32
- #include "detail.h"
33
-
34
- // ----------------------------------------------------------------------------
35
-
36
- #if defined(__GNUC__)
37
- #pragma GCC diagnostic push
38
- #pragma GCC diagnostic ignored "-Wpadded"
39
- #pragma GCC diagnostic ignored "-Waggregate-return"
40
- #if defined(__clang__)
41
- #pragma clang diagnostic ignored "-Wc++98-compat"
42
- #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
43
- #endif
44
- #endif
45
-
46
- namespace micro_os_plus::micro_test_plus
47
- {
48
- // --------------------------------------------------------------------------
49
-
50
- /**
51
- * @brief Colours used to highlight pass vs. fail.
52
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
53
- */
54
- struct colors
55
- {
56
- const char* none = "\033[0m";
57
- const char* pass = "\033[32m";
58
- const char* fail = "\033[31m";
59
- };
60
-
61
- /**
62
- * @brief The verbosity levels.
63
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
64
- */
65
- enum class verbosity
66
- {
67
- silent = 0, // Nothing, only return the exit code
68
- quiet = 1, // Test suites results
69
- normal = 2, // Test suites results and failed test cases
70
- verbose = 3 // All, including passed checks
71
- };
72
-
73
- typedef verbosity verbosity_t;
74
-
75
- class test_reporter;
76
-
77
- test_reporter&
78
- endl (test_reporter& stream);
79
-
80
- // Requires events::assertion_* for and detailed operators.
81
-
82
- /**
83
- * @brief Reporter to display the test results. For failed
84
- * tests it prints the actual values of the operands, with their types.
85
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
86
- */
87
- class test_reporter
88
- {
89
- public:
90
- test_reporter () = default;
91
-
92
- [[nodiscard]] inline auto
93
- color (const bool cond)
94
- {
95
- return cond ? colors_.pass : colors_.fail;
96
- }
97
-
98
- test_reporter&
99
- operator<< (std::string_view sv);
100
-
101
- test_reporter&
102
- operator<< (char c);
103
-
104
- test_reporter&
105
- operator<< (const char* s);
106
-
107
- test_reporter&
108
- operator<< (char* s);
109
-
110
- test_reporter&
111
- operator<< (bool v);
112
-
113
- test_reporter& operator<< (std::nullptr_t);
114
-
115
- test_reporter&
116
- operator<< (signed char c);
117
-
118
- test_reporter&
119
- operator<< (unsigned char c);
120
-
121
- test_reporter&
122
- operator<< (signed short c);
123
-
124
- test_reporter&
125
- operator<< (unsigned short c);
126
-
127
- test_reporter&
128
- operator<< (signed int v);
129
-
130
- test_reporter&
131
- operator<< (unsigned int v);
132
-
133
- test_reporter&
134
- operator<< (signed long v);
135
-
136
- test_reporter&
137
- operator<< (unsigned long v);
138
-
139
- test_reporter&
140
- operator<< (signed long long v);
141
-
142
- test_reporter&
143
- operator<< (unsigned long long v);
144
-
145
- test_reporter&
146
- operator<< (float v);
147
-
148
- test_reporter&
149
- operator<< (double v);
150
-
151
- test_reporter&
152
- operator<< (long double v);
153
-
154
- /**
155
- * @brief Output operator to display any pointer.
156
- */
157
- template <typename T>
158
- test_reporter&
159
- operator<< (T* v);
160
-
161
- /**
162
- * @brief Output operator to display the endl.
163
- */
164
- test_reporter&
165
- operator<< (test_reporter& (*func) (test_reporter&));
166
-
167
- // ------------------------------------------------------------------------
168
- // Specific operators.
169
-
170
- /**
171
- * @brief Output operator to types with a getter.
172
- */
173
- template <class T>
174
- test_reporter&
175
- operator<< (const T& t);
176
-
177
- /**
178
- * @brief Output operator to display genuine integers,
179
- * without the type suffix.
180
- */
181
- template <class T>
182
- test_reporter&
183
- operator<< (const type_traits::genuine_integral_value<T>& v);
184
-
185
- /**
186
- * @brief Output operator to display containers. Iterate all members.
187
- */
188
- template <class T,
189
- type_traits::requires_t<type_traits::is_container_v<T>
190
- and not type_traits::has_npos_v<T>>
191
- = 0>
192
- test_reporter&
193
- operator<< (T&& t);
194
-
195
- /**
196
- * @brief Output operator to display eq() expressions.
197
- */
198
- template <class Lhs_T, class Rhs_T>
199
- test_reporter&
200
- operator<< (const detail::eq_<Lhs_T, Rhs_T>& op);
201
-
202
- /**
203
- * @brief Output operator to display ne() expressions.
204
- */
205
- template <class Lhs_T, class Rhs_T>
206
- test_reporter&
207
- operator<< (const detail::ne_<Lhs_T, Rhs_T>& op);
208
-
209
- /**
210
- * @brief Output operator to display gt() expressions.
211
- */
212
- template <class Lhs_T, class Rhs_T>
213
- test_reporter&
214
- operator<< (const detail::gt_<Lhs_T, Rhs_T>& op);
215
-
216
- /**
217
- * @brief Output operator to display ge() expressions.
218
- */
219
- template <class Lhs_T, class Rhs_T>
220
- test_reporter&
221
- operator<< (const detail::ge_<Lhs_T, Rhs_T>& op);
222
-
223
- /**
224
- * @brief Output operator to display lt() expressions.
225
- */
226
- template <class Lhs_T, class Rhs_T>
227
- test_reporter&
228
- operator<< (const detail::lt_<Rhs_T, Lhs_T>& op);
229
-
230
- /**
231
- * @brief Output operator to display le() expressions.
232
- */
233
- template <class Lhs_T, class Rhs_T>
234
- test_reporter&
235
- operator<< (const detail::le_<Rhs_T, Lhs_T>& op);
236
-
237
- /**
238
- * @brief Output operator to display and() expressions.
239
- */
240
- template <class Lhs_T, class Rhs_T>
241
- test_reporter&
242
- operator<< (const detail::and_<Lhs_T, Rhs_T>& op);
243
-
244
- /**
245
- * @brief Output operator to display or() expressions.
246
- */
247
- template <class Lhs_T, class Rhs_T>
248
- test_reporter&
249
- operator<< (const detail::or_<Lhs_T, Rhs_T>& op);
250
-
251
- /**
252
- * @brief Output operator to display not() expressions.
253
- */
254
- template <class T>
255
- test_reporter&
256
- operator<< (const detail::not_<T>& op);
257
-
258
- #if defined(__cpp_exceptions)
259
- template <class Expr_T, class Exception_T>
260
- test_reporter&
261
- operator<< (const detail::throws_<Expr_T, Exception_T>& op);
262
-
263
- template <class Expr_T>
264
- test_reporter&
265
- operator<< (const detail::throws_<Expr_T, void>& op);
266
-
267
- template <class Expr_T>
268
- test_reporter&
269
- operator<< (const detail::nothrow_<Expr_T>& op);
270
- #endif
271
-
272
- void
273
- endline (void);
274
-
275
- // ------------------------------------------------------------------------
276
-
277
- /**
278
- * @brief Report a passed condition.
279
- */
280
- template <class Expr_T>
281
- void
282
- pass (Expr_T& expr, std::string& message);
283
-
284
- /**
285
- * @brief Report a failed condition.
286
- */
287
- template <class Expr_T>
288
- void
289
- fail (Expr_T& expr, bool abort, std::string& message,
290
- const reflection::source_location& location);
291
-
292
- void
293
- begin_test_case (const char* name);
294
-
295
- void
296
- end_test_case (const char* name);
297
-
298
- void
299
- begin_test_suite (const char* name);
300
-
301
- void
302
- end_test_suite (test_suite_base& suite);
303
-
304
- /**
305
- * @brief Flush the current buffered content.
306
- */
307
- void
308
- flush (void);
309
-
310
- void
311
- output (void);
312
-
313
- // Used to nicely format the output, without empty lines
314
- // between successful test cases.
315
- bool add_empty_line{ true };
316
-
317
- verbosity_t verbosity{};
318
-
319
- protected:
320
- // The prefix/suffix methods help shorten the code
321
- // generated by the template methods.
322
-
323
- void
324
- output_pass_prefix_ (std::string& message);
325
-
326
- void
327
- output_pass_suffix_ (void);
328
-
329
- void
330
- output_fail_prefix_ (std::string& message,
331
- const reflection::source_location& location);
332
-
333
- void
334
- output_fail_suffix_ (bool abort);
335
-
336
- colors colors_{};
337
- std::string out_{};
338
-
339
- bool is_in_test_case_ = false;
340
- };
341
-
342
- // --------------------------------------------------------------------------
343
- } // namespace micro_os_plus::micro_test_plus
344
-
345
- #if defined(__GNUC__)
346
- #pragma GCC diagnostic pop
347
- #endif
348
-
349
- // ----------------------------------------------------------------------------
350
-
351
- #endif // __cplusplus
352
-
353
- // ----------------------------------------------------------------------------
354
-
355
- #endif // MICRO_TEST_PLUS_TEST_REPORTER_H_
356
-
357
- // ----------------------------------------------------------------------------
@@ -1,133 +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_RUNNER_H_
18
- #define MICRO_TEST_PLUS_TEST_RUNNER_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__)
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
- class test_suite_base;
43
-
44
- // --------------------------------------------------------------------------
45
-
46
- /**
47
- * @brief The test runner. It maintains a list of test suites which
48
- * automatically register themselves in their constructors.
49
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
50
- */
51
- class test_runner
52
- {
53
- public:
54
- test_runner ();
55
-
56
- // The rule of five.
57
- test_runner (const test_runner&) = delete;
58
- test_runner (test_runner&&) = delete;
59
- test_runner&
60
- operator= (const test_runner&)
61
- = delete;
62
- test_runner&
63
- operator= (test_runner&&)
64
- = delete;
65
-
66
- ~test_runner () = default;
67
-
68
- /**
69
- * @brief Pass the main arguments explicitly, if the default
70
- * constructor was used.
71
- */
72
- void
73
- initialize (int argc, char* argv[], const char* name);
74
-
75
- /**
76
- * @brief Return 0 if the all tests were successful, 1 otherwise.
77
- */
78
- int
79
- exit_code (void);
80
-
81
- /**
82
- * @brief Called by test suite constructors to register them
83
- * to the runner.
84
- */
85
- void
86
- register_test_suite (test_suite_base* suite);
87
-
88
- constexpr const char*
89
- name (void)
90
- {
91
- return default_suite_name_;
92
- }
93
-
94
- [[noreturn]] void
95
- abort (void);
96
-
97
- protected:
98
- int argc_ = 0;
99
- char** argv_ = nullptr;
100
-
101
- const char* default_suite_name_ = "Test";
102
-
103
- /**
104
- * @brief Pointer to the default test suite which groups
105
- * the main tests.
106
- */
107
- test_suite_base* default_test_suite_;
108
-
109
- /**
110
- * @brief Pointer to array of registered test suites.
111
- * Statically initialised to zero as BSS, such that
112
- * test suites defined as static objects in different
113
- * compilation units can be automatically executed.
114
- */
115
- std::vector<test_suite_base*>* suites_;
116
- };
117
-
118
- // --------------------------------------------------------------------------
119
- } // namespace micro_os_plus::micro_test_plus
120
-
121
- #if defined(__GNUC__)
122
- #pragma GCC diagnostic pop
123
- #endif
124
-
125
- // ----------------------------------------------------------------------------
126
-
127
- #endif // __cplusplus
128
-
129
- // ----------------------------------------------------------------------------
130
-
131
- #endif // MICRO_TEST_PLUS_TEST_RUNNER_H_
132
-
133
- // ----------------------------------------------------------------------------