@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,765 +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_DETAIL_H_
17
- #define MICRO_TEST_PLUS_DETAIL_H_
18
-
19
- // ----------------------------------------------------------------------------
20
-
21
- #ifdef __cplusplus
22
-
23
- // ----------------------------------------------------------------------------
24
-
25
- #include <stdio.h>
26
-
27
- // ----------------------------------------------------------------------------
28
-
29
- #if defined(__GNUC__)
30
- #pragma GCC diagnostic push
31
- #pragma GCC diagnostic ignored "-Wpadded"
32
- #pragma GCC diagnostic ignored "-Waggregate-return"
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 Namespace with implementation details, not part of the public API.
44
- */
45
- namespace detail
46
- {
47
- /**
48
- * @brief An object used to pass assertion parameters to the evaluator.
49
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
50
- */
51
- template <class Expr_T>
52
- struct assertion
53
- {
54
- Expr_T expr{};
55
- reflection::source_location location{};
56
- };
57
-
58
- // ------------------------------------------------------------------------
59
-
60
- /**
61
- * @brief Generic getter implementation. If the type has
62
- * a get() method, call it. It is recommended for custom types
63
- * to define a get() method.
64
- */
65
- template <class T>
66
- [[nodiscard]] constexpr auto
67
- get_impl (const T& t, int) -> decltype (t.get ())
68
- {
69
- return t.get ();
70
- }
71
-
72
- /**
73
- * @brief Variadic getter implementation that returns the
74
- * first argument and discards the rest.
75
- */
76
- template <class T>
77
- [[nodiscard]] constexpr auto
78
- get_impl (const T& t, ...) -> decltype (auto)
79
- {
80
- return t;
81
- }
82
-
83
- /**
84
- * @brief Generic getter, calling the getter implementation.
85
- */
86
- template <class T>
87
- [[nodiscard]] constexpr auto
88
- get (const T& t)
89
- {
90
- // Call the variadic function, basically to force it return `t`.
91
- return get_impl (t, 0);
92
- }
93
-
94
- // ------------------------------------------------------------------------
95
-
96
- /**
97
- * @brief Equality comparator.
98
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
99
- */
100
- template <class Lhs_T, class Rhs_T>
101
- struct eq_ : type_traits::op
102
- {
103
- constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
104
- : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
105
- // This lambda is called in the constructor to
106
- // evaluate the comparison.
107
- using std::operator==;
108
- using std::operator<;
109
-
110
- #if defined(__GNUC__)
111
- #pragma GCC diagnostic push
112
- #pragma GCC diagnostic ignored "-Wfloat-equal"
113
- #pragma GCC diagnostic ignored "-Wconversion"
114
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
115
- #pragma GCC diagnostic ignored "-Wsign-compare"
116
- #if defined(__clang__)
117
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
118
- #pragma clang diagnostic ignored "-Wpedantic"
119
- #endif
120
- #endif
121
- if constexpr (type_traits::has_value_v<Lhs_T>
122
- and type_traits::has_value_v<Rhs_T>)
123
- {
124
- // If both types have values (like numeric constants),
125
- // compare them directly.
126
- return Lhs_T::value == Rhs_T::value;
127
- }
128
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>
129
- and type_traits::has_epsilon_v<Rhs_T>)
130
- {
131
- // If both values have precision, compare them using
132
- // the smalles precision.
133
- return math::abs (get (lhs) - get (rhs))
134
- < math::min_value (Lhs_T::epsilon, Rhs_T::epsilon);
135
- }
136
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
137
- {
138
- // If only the left operand has precision, use it.
139
- return math::abs (get (lhs) - get (rhs)) < Lhs_T::epsilon;
140
- }
141
- else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
142
- {
143
- // If only the right operand has precision, use it.
144
- return math::abs (get (lhs) - get (rhs)) < Rhs_T::epsilon;
145
- }
146
- else
147
- {
148
- // Call the generic getters, which might
149
- // either call the type get() or return the value.
150
- return get (lhs) == get (rhs);
151
- }
152
- #if defined(__GNUC__)
153
- #pragma GCC diagnostic pop
154
- #endif
155
- }() }
156
- {
157
- }
158
-
159
- [[nodiscard]] constexpr
160
- operator bool () const
161
- {
162
- return value_;
163
- }
164
-
165
- [[nodiscard]] constexpr auto
166
- lhs () const
167
- {
168
- return get (lhs_);
169
- }
170
-
171
- [[nodiscard]] constexpr auto
172
- rhs () const
173
- {
174
- return get (rhs_);
175
- }
176
-
177
- const Lhs_T lhs_{};
178
- const Rhs_T rhs_{};
179
- const bool value_{};
180
- };
181
-
182
- /**
183
- * @brief Non-equality comparator.
184
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
185
- */
186
- template <class Lhs_T, class Rhs_T>
187
- struct ne_ : type_traits::op
188
- {
189
- constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
190
- : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
191
- using std::operator==;
192
- using std::operator!=;
193
- using std::operator>;
194
-
195
- #if defined(__GNUC__)
196
- #pragma GCC diagnostic push
197
- #pragma GCC diagnostic ignored "-Wfloat-equal"
198
- #pragma GCC diagnostic ignored "-Wconversion"
199
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
200
- #pragma GCC diagnostic ignored "-Wsign-compare"
201
- #if defined(__clang__)
202
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
203
- #pragma clang diagnostic ignored "-Wpedantic"
204
- #endif
205
- #endif
206
- if constexpr (type_traits::has_value_v<Lhs_T>
207
- and type_traits::has_value_v<Rhs_T>)
208
- {
209
- return Lhs_T::value != Rhs_T::value;
210
- }
211
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>
212
- and type_traits::has_epsilon_v<Rhs_T>)
213
- {
214
- return math::abs (get (lhs_) - get (rhs_))
215
- > math::min_value (Lhs_T::epsilon, Rhs_T::epsilon);
216
- }
217
- else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
218
- {
219
- return math::abs (get (lhs_) - get (rhs_)) > Lhs_T::epsilon;
220
- }
221
- else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
222
- {
223
- return math::abs (get (lhs_) - get (rhs_)) > Rhs_T::epsilon;
224
- }
225
- else
226
- {
227
- return get (lhs_) != get (rhs_);
228
- }
229
- #if defined(__GNUC__)
230
- #pragma GCC diagnostic pop
231
- #endif
232
- }() }
233
- {
234
- }
235
-
236
- [[nodiscard]] constexpr
237
- operator bool () const
238
- {
239
- return value_;
240
- }
241
- [[nodiscard]] constexpr auto
242
- lhs () const
243
- {
244
- return get (lhs_);
245
- }
246
- [[nodiscard]] constexpr auto
247
- rhs () const
248
- {
249
- return get (rhs_);
250
- }
251
-
252
- const Lhs_T lhs_{};
253
- const Rhs_T rhs_{};
254
- const bool value_{};
255
- };
256
-
257
- /**
258
- * @brief Greater than comparator.
259
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
260
- */
261
- template <class Lhs_T, class Rhs_T>
262
- struct gt_ : type_traits::op
263
- {
264
- constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
265
- : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
266
- using std::operator>;
267
-
268
- #if defined(__GNUC__)
269
- #pragma GCC diagnostic push
270
- #pragma GCC diagnostic ignored "-Wconversion"
271
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
272
- #pragma GCC diagnostic ignored "-Wsign-compare"
273
- #if defined(__clang__)
274
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
275
- #pragma clang diagnostic ignored "-Wpedantic"
276
- #endif
277
- #endif
278
- if constexpr (type_traits::has_value_v<Lhs_T>
279
- and type_traits::has_value_v<Rhs_T>)
280
- {
281
- return Lhs_T::value > Rhs_T::value;
282
- }
283
- else
284
- {
285
- return get (lhs_) > get (rhs_);
286
- }
287
- #if defined(__GNUC__)
288
- #pragma GCC diagnostic pop
289
- #endif
290
- }() }
291
- {
292
- }
293
-
294
- [[nodiscard]] constexpr
295
- operator bool () const
296
- {
297
- return value_;
298
- }
299
- [[nodiscard]] constexpr auto
300
- lhs () const
301
- {
302
- return get (lhs_);
303
- }
304
- [[nodiscard]] constexpr auto
305
- rhs () const
306
- {
307
- return get (rhs_);
308
- }
309
-
310
- const Lhs_T lhs_{};
311
- const Rhs_T rhs_{};
312
- const bool value_{};
313
- };
314
-
315
- /**
316
- * @brief Greater than or equal comparator.
317
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
318
- */
319
- template <class Lhs_T, class Rhs_T>
320
- struct ge_ : type_traits::op
321
- {
322
- constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
323
- : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
324
- using std::operator>=;
325
-
326
- #if defined(__GNUC__)
327
- #pragma GCC diagnostic push
328
- #pragma GCC diagnostic ignored "-Wconversion"
329
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
330
- #pragma GCC diagnostic ignored "-Wsign-compare"
331
- #if defined(__clang__)
332
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
333
- #pragma clang diagnostic ignored "-Wpedantic"
334
- #endif
335
- #endif
336
- if constexpr (type_traits::has_value_v<Lhs_T>
337
- and type_traits::has_value_v<Rhs_T>)
338
- {
339
- return Lhs_T::value >= Rhs_T::value;
340
- }
341
- else
342
- {
343
- return get (lhs_) >= get (rhs_);
344
- }
345
- #if defined(__GNUC__)
346
- #pragma GCC diagnostic pop
347
- #endif
348
- }() }
349
- {
350
- }
351
-
352
- [[nodiscard]] constexpr
353
- operator bool () const
354
- {
355
- return value_;
356
- }
357
- [[nodiscard]] constexpr auto
358
- lhs () const
359
- {
360
- return get (lhs_);
361
- }
362
- [[nodiscard]] constexpr auto
363
- rhs () const
364
- {
365
- return get (rhs_);
366
- }
367
-
368
- const Lhs_T lhs_{};
369
- const Rhs_T rhs_{};
370
- const bool value_{};
371
- };
372
-
373
- /**
374
- * @brief Less than comparator.
375
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
376
- */
377
- template <class Lhs_T, class Rhs_T>
378
- struct lt_ : type_traits::op
379
- {
380
- constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
381
- : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
382
- using std::operator<;
383
-
384
- #if defined(__GNUC__)
385
- #pragma GCC diagnostic push
386
- #pragma GCC diagnostic ignored "-Wconversion"
387
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
388
- #pragma GCC diagnostic ignored "-Wsign-compare"
389
- #if defined(__clang__)
390
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
391
- #pragma clang diagnostic ignored "-Wpedantic"
392
- #endif
393
- #endif
394
- if constexpr (type_traits::has_value_v<Lhs_T>
395
- and type_traits::has_value_v<Rhs_T>)
396
- {
397
- return Lhs_T::value < Rhs_T::value;
398
- }
399
- else
400
- {
401
- return get (lhs_) < get (rhs_);
402
- }
403
- #if defined(__GNUC__)
404
- #pragma GCC diagnostic pop
405
- #endif
406
- }() }
407
- {
408
- }
409
-
410
- [[nodiscard]] constexpr
411
- operator bool () const
412
- {
413
- return value_;
414
- }
415
- [[nodiscard]] constexpr auto
416
- lhs () const
417
- {
418
- return get (lhs_);
419
- }
420
- [[nodiscard]] constexpr auto
421
- rhs () const
422
- {
423
- return get (rhs_);
424
- }
425
-
426
- private:
427
- const Lhs_T lhs_{};
428
- const Rhs_T rhs_{};
429
- const bool value_{};
430
- };
431
-
432
- /**
433
- * @brief Less than or equal comparator.
434
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
435
- */
436
- template <class Lhs_T, class Rhs_T>
437
- struct le_ : type_traits::op
438
- {
439
- constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
440
- : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
441
- using std::operator<=;
442
-
443
- #if defined(__GNUC__)
444
- #pragma GCC diagnostic push
445
- #pragma GCC diagnostic ignored "-Wconversion"
446
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
447
- #pragma GCC diagnostic ignored "-Wsign-compare"
448
- #if defined(__clang__)
449
- #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
450
- #pragma clang diagnostic ignored "-Wpedantic"
451
- #endif
452
- #endif
453
- if constexpr (type_traits::has_value_v<Lhs_T>
454
- and type_traits::has_value_v<Rhs_T>)
455
- {
456
- return Lhs_T::value <= Rhs_T::value;
457
- }
458
- else
459
- {
460
- return get (lhs_) <= get (rhs_);
461
- }
462
- #if defined(__GNUC__)
463
- #pragma GCC diagnostic pop
464
- #endif
465
- }() }
466
- {
467
- }
468
-
469
- [[nodiscard]] constexpr
470
- operator bool () const
471
- {
472
- return value_;
473
- }
474
-
475
- [[nodiscard]] constexpr auto
476
- lhs () const
477
- {
478
- return get (lhs_);
479
- }
480
-
481
- [[nodiscard]] constexpr auto
482
- rhs () const
483
- {
484
- return get (rhs_);
485
- }
486
-
487
- const Lhs_T lhs_{};
488
- const Rhs_T rhs_{};
489
- const bool value_{};
490
- };
491
-
492
- /**
493
- * @brief Logical and operator.
494
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
495
- */
496
- template <class Lhs_T, class Rhs_T>
497
- struct and_ : type_traits::op
498
- {
499
- constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
500
- : lhs_{ lhs }, rhs_{ rhs },
501
- value_{ static_cast<bool> (lhs) and static_cast<bool> (rhs) }
502
- {
503
- }
504
-
505
- [[nodiscard]] constexpr
506
- operator bool () const
507
- {
508
- return value_;
509
- }
510
-
511
- [[nodiscard]] constexpr auto
512
- lhs () const
513
- {
514
- return get (lhs_);
515
- }
516
-
517
- [[nodiscard]] constexpr auto
518
- rhs () const
519
- {
520
- return get (rhs_);
521
- }
522
-
523
- const Lhs_T lhs_{};
524
- const Rhs_T rhs_{};
525
- const bool value_{};
526
- };
527
-
528
- /**
529
- * @brief Logical or operator.
530
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
531
- */
532
- template <class Lhs_T, class Rhs_T>
533
- struct or_ : type_traits::op
534
- {
535
- constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
536
- : lhs_{ lhs }, rhs_{ rhs },
537
- value_{ static_cast<bool> (lhs) or static_cast<bool> (rhs) }
538
- {
539
- }
540
-
541
- [[nodiscard]] constexpr
542
- operator bool () const
543
- {
544
- return value_;
545
- }
546
-
547
- [[nodiscard]] constexpr auto
548
- lhs () const
549
- {
550
- return get (lhs_);
551
- }
552
-
553
- [[nodiscard]] constexpr auto
554
- rhs () const
555
- {
556
- return get (rhs_);
557
- }
558
-
559
- const Lhs_T lhs_{};
560
- const Rhs_T rhs_{};
561
- const bool value_{};
562
- };
563
-
564
- /**
565
- * @brief Logical not operator.
566
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
567
- */
568
- template <class T>
569
- struct not_ : type_traits::op
570
- {
571
- explicit constexpr not_ (const T& t = {})
572
- : t_{ t }, value_{ not static_cast<bool> (t) }
573
- {
574
- }
575
-
576
- [[nodiscard]] constexpr
577
- operator bool () const
578
- {
579
- return value_;
580
- }
581
-
582
- [[nodiscard]] constexpr auto
583
- value () const
584
- {
585
- return get (t_);
586
- }
587
-
588
- const T t_{};
589
- const bool value_{};
590
- };
591
-
592
- #if defined(__cpp_exceptions)
593
- /**
594
- * @brief Operator to check if the expression throws a specific exception.
595
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
596
- */
597
- template <class Callable_T, class Exception_T = void>
598
- struct throws_ : type_traits::op
599
- {
600
- constexpr explicit throws_ (const Callable_T& func)
601
- : value_{ [&func] {
602
- try
603
- {
604
- func ();
605
- }
606
- catch (const Exception_T&)
607
- {
608
- return true;
609
- }
610
- catch (...)
611
- {
612
- return false;
613
- }
614
- return false;
615
- }() }
616
- {
617
- }
618
-
619
- [[nodiscard]] constexpr
620
- operator bool () const
621
- {
622
- return value_;
623
- }
624
-
625
- const bool value_{};
626
- };
627
-
628
- /**
629
- * @brief Operator to check if the expression throws any exception.
630
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
631
- */
632
- template <class Callable_T>
633
- struct throws_<Callable_T, void> : type_traits::op
634
- {
635
- constexpr explicit throws_ (const Callable_T& func)
636
- : value_{ [&func] {
637
- try
638
- {
639
- func ();
640
- }
641
- catch (...)
642
- {
643
- return true;
644
- }
645
- return false;
646
- }() }
647
- {
648
- }
649
-
650
- [[nodiscard]] constexpr
651
- operator bool () const
652
- {
653
- return value_;
654
- }
655
-
656
- const bool value_{};
657
- };
658
-
659
- /**
660
- * @brief Operator to check if the expression does not throw any exception.
661
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
662
- */
663
- template <class Callable_T>
664
- struct nothrow_ : type_traits::op
665
- {
666
- constexpr explicit nothrow_ (const Callable_T& func)
667
- : value_{ [&func] {
668
- try
669
- {
670
- func ();
671
- }
672
- catch (...)
673
- {
674
- return false;
675
- }
676
- return true;
677
- }() }
678
- {
679
- }
680
-
681
- [[nodiscard]] constexpr
682
- operator bool () const
683
- {
684
- return value_;
685
- }
686
-
687
- const bool value_{};
688
- };
689
- #endif
690
-
691
- // ------------------------------------------------------------------------
692
-
693
- /**
694
- * @brief Base class for a deferred reporter, that collects the
695
- * messages into a string.
696
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
697
- */
698
- class deferred_reporter_base
699
- {
700
- public:
701
- deferred_reporter_base (bool value,
702
- const reflection::source_location location);
703
-
704
- ~deferred_reporter_base ();
705
-
706
- template <class T>
707
- auto&
708
- operator<< (const T& msg);
709
-
710
- [[nodiscard]] constexpr bool
711
- value () const
712
- {
713
- return value_;
714
- }
715
-
716
- protected:
717
- bool value_{};
718
- bool abort_ = false;
719
- const reflection::source_location location_{};
720
-
721
- /**
722
- * @brief String to collect the expectation message passed via
723
- * `operator<<()`.
724
- */
725
- std::string message_{};
726
- };
727
-
728
- /**
729
- * @brief Class template for a deferred reporter specific
730
- * to an expression.
731
- * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
732
- */
733
- template <class Expr_T>
734
- class deferred_reporter : public deferred_reporter_base
735
- {
736
- public:
737
- constexpr explicit deferred_reporter (
738
- const Expr_T& expr, bool abort,
739
- const reflection::source_location& location);
740
-
741
- ~deferred_reporter ();
742
-
743
- protected:
744
- const Expr_T expr_{};
745
- };
746
-
747
- // ----------------------------------------------------------------------
748
- } // namespace detail
749
-
750
- // --------------------------------------------------------------------------
751
- } // namespace micro_os_plus::micro_test_plus
752
-
753
- #if defined(__GNUC__)
754
- #pragma GCC diagnostic pop
755
- #endif
756
-
757
- // ----------------------------------------------------------------------------
758
-
759
- #endif // __cplusplus
760
-
761
- // ----------------------------------------------------------------------------
762
-
763
- #endif // MICRO_TEST_PLUS_DETAIL_H_
764
-
765
- // ----------------------------------------------------------------------------