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