micro-test-plus 5.0.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
detail.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * 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 be
9 * 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// ----------------------------------------------------------------------------
17
41
42#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_DETAIL_H_
43#define MICRO_OS_PLUS_MICRO_TEST_PLUS_DETAIL_H_
44
45// ----------------------------------------------------------------------------
46
47#if defined(__cplusplus)
48
49// ----------------------------------------------------------------------------
50
51#if __has_include("micro-os-plus/project-config.h")
52#include "micro-os-plus/project-config.h"
53#endif // __has_include("micro-os-plus/project-config.h")
54
55#if __has_include("micro-os-plus/micro-test-plus-defines.h")
56#include "micro-os-plus/micro-test-plus-defines.h"
57#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
58
59#include "type-traits.h"
60#include "reflection.h"
61
62#include <cstdio>
63#include <string>
64
65// ----------------------------------------------------------------------------
66
67#if defined(__GNUC__)
68#pragma GCC diagnostic push
69
70#pragma GCC diagnostic ignored "-Wpadded"
71#pragma GCC diagnostic ignored "-Waggregate-return"
72#if defined(__clang__)
73#pragma clang diagnostic ignored "-Wc++98-compat"
74#endif // defined(__clang__)
75#endif // defined(__GNUC__)
76
77// ============================================================================
78
80{
81 class test_node;
82
83 // --------------------------------------------------------------------------
84
108 namespace detail
109 {
110 // ========================================================================
111
125 template <class Expr_T>
127 {
131 Expr_T expr{};
132
137 };
138
139 // ========================================================================
140
149 template <class T>
150 [[nodiscard]] constexpr auto
151 get (const T& t);
152
153 // ========================================================================
154
169 template <class T>
171 {
179 constexpr unary_op_ (const T& t, bool value);
180
188 [[nodiscard]] constexpr
189 operator bool () const;
190
198 [[nodiscard]] constexpr auto
199 operand () const;
200
201 private:
205 const T t_{};
206
210 const bool value_{};
211 };
212
213 // ========================================================================
214
231 template <class Lhs_T, class Rhs_T>
233 {
242 constexpr binary_op_ (const Lhs_T& lhs, const Rhs_T& rhs, bool value);
243
251 [[nodiscard]] constexpr
252 operator bool () const;
253
261 [[nodiscard]] constexpr auto
262 lhs (void) const;
263
271 [[nodiscard]] constexpr auto
272 rhs (void) const;
273
274 private:
281 const Lhs_T lhs_{};
282
289 const Rhs_T rhs_{};
290
294 const bool value_{};
295 };
296
297 // ========================================================================
298
313 template <class Lhs_T, class Rhs_T>
314 struct eq_ : binary_op_<Lhs_T, Rhs_T>
315 {
322 constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
323 };
324
325 // Deduction guide.
326 template <typename Lhs_T, typename Rhs_T>
327 eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
328
329 // ========================================================================
330
345 template <class Lhs_T, class Rhs_T>
346 struct ne_ : binary_op_<Lhs_T, Rhs_T>
347 {
354 constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
355 };
356
357 // Deduction guide.
358 template <typename Lhs_T, typename Rhs_T>
359 ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
360
361 // ========================================================================
362
377 template <class Lhs_T, class Rhs_T>
378 struct gt_ : binary_op_<Lhs_T, Rhs_T>
379 {
386 constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
387 };
388
389 // Deduction guide.
390 template <typename Lhs_T, typename Rhs_T>
391 gt_ (const Lhs_T&, const Rhs_T&) -> gt_<Lhs_T, Rhs_T>;
392
393 // ========================================================================
394
410 template <class Lhs_T, class Rhs_T>
411 struct ge_ : binary_op_<Lhs_T, Rhs_T>
412 {
420 constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
421 };
422
423 // Deduction guide.
424 template <typename Lhs_T, typename Rhs_T>
425 ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
426
427 // ========================================================================
428
443 template <class Lhs_T, class Rhs_T>
444 struct lt_ : binary_op_<Lhs_T, Rhs_T>
445 {
452 constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
453 };
454
455 // Deduction guide.
456 template <typename Lhs_T, typename Rhs_T>
457 lt_ (const Lhs_T&, const Rhs_T&) -> lt_<Lhs_T, Rhs_T>;
458
459 // ========================================================================
460
476 template <class Lhs_T, class Rhs_T>
477 struct le_ : binary_op_<Lhs_T, Rhs_T>
478 {
486 constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
487 };
488
489 // Deduction guide.
490 template <typename Lhs_T, typename Rhs_T>
491 le_ (const Lhs_T&, const Rhs_T&) -> le_<Lhs_T, Rhs_T>;
492
493 // ========================================================================
494
510 template <class Lhs_T, class Rhs_T>
511 struct and_ : binary_op_<Lhs_T, Rhs_T>
512 {
519 constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
520 };
521
522 // Deduction guide.
523 template <typename Lhs_T, typename Rhs_T>
524 and_ (const Lhs_T&, const Rhs_T&) -> and_<Lhs_T, Rhs_T>;
525
526 // ========================================================================
527
543 template <class Lhs_T, class Rhs_T>
544 struct or_ : binary_op_<Lhs_T, Rhs_T>
545 {
552 constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
553 };
554
555 // Deduction guide.
556 template <typename Lhs_T, typename Rhs_T>
557 or_ (const Lhs_T&, const Rhs_T&) -> or_<Lhs_T, Rhs_T>;
558
559 // ========================================================================
560
574 template <class T>
575 struct not_ : unary_op_<T>
576 {
582 explicit constexpr not_ (const T& t = {});
583 };
584
585 // Deduction guide.
586 template <typename T>
587 not_ (const T&) -> not_<T>;
588
589 // ========================================================================
590
591#if defined(__cpp_exceptions)
592
607 {
614 constexpr explicit callable_op_ (bool value);
615
623 [[nodiscard]] constexpr
624 operator bool () const;
625
626 private:
630 const bool value_{};
631 };
632
633 // ========================================================================
634
652 template <class Callable_T, class Exception_T = void>
654 {
661 constexpr explicit throws_ (const Callable_T& func);
662 };
663
664 // ========================================================================
665
681 template <class Callable_T>
682 struct throws_<Callable_T, void> : callable_op_
683 {
690 constexpr explicit throws_ (const Callable_T& func);
691 };
692
693 // ========================================================================
694
709 template <class Callable_T>
711 {
718 constexpr explicit nothrow_ (const Callable_T& func);
719 };
720
721#endif // defined(__cpp_exceptions)
722
723 // ========================================================================
724
736 template <class T>
737 requires std::is_arithmetic_v<T>
738 void
739 append_number_ (std::string& buffer, T v);
740
741 // ------------------------------------------------------------------------
742 } // namespace detail
743
744 // --------------------------------------------------------------------------
745} // namespace micro_os_plus::micro_test_plus
746
747#if defined(__GNUC__)
748#pragma GCC diagnostic pop
749#endif // defined(__GNUC__)
750
751// ----------------------------------------------------------------------------
752
753#endif // defined(__cplusplus)
754
755// ============================================================================
756// Templates, inlines & constexpr implementations.
757
759
760// ----------------------------------------------------------------------------
761
762#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_DETAIL_H_
763
764// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:150
C++ header file with inline implementations for the µTest++ internal detail namespace.
Internal implementation details for the µTest++ framework.
le_(const Lhs_T &, const Rhs_T &) -> le_< Lhs_T, Rhs_T >
or_(const Lhs_T &, const Rhs_T &) -> or_< Lhs_T, Rhs_T >
eq_(const Lhs_T &, const Rhs_T &) -> eq_< Lhs_T, Rhs_T >
ne_(const Lhs_T &, const Rhs_T &) -> ne_< Lhs_T, Rhs_T >
gt_(const Lhs_T &, const Rhs_T &) -> gt_< Lhs_T, Rhs_T >
and_(const Lhs_T &, const Rhs_T &) -> and_< Lhs_T, Rhs_T >
void append_number_(std::string &buffer, T v)
Appends the string representation of a numeric value to a buffer, using std::to_chars for allocation-...
constexpr auto get(const T &t)
Generic getter function template for value retrieval.
lt_(const Lhs_T &, const Rhs_T &) -> lt_< Lhs_T, Rhs_T >
ge_(const Lhs_T &, const Rhs_T &) -> ge_< Lhs_T, Rhs_T >
Primary namespace for the µTest++ testing framework.
C++ header file with declarations for the µTest++ reflection utilities.
Logical AND comparator struct template.
Definition detail.h:512
constexpr and_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a logical AND comparator for the given operands.
Assertion struct template for parameter passing to the evaluator.
Definition detail.h:127
Expr_T expr
The expression under evaluation.
Definition detail.h:131
reflection::source_location location
The source location associated with the assertion.
Definition detail.h:136
const bool value_
Stores the result of the comparison.
Definition detail.h:294
constexpr auto lhs(void) const
Retrieves the left-hand operand.
constexpr binary_op_(const Lhs_T &lhs, const Rhs_T &rhs, bool value)
Constructs a binary comparator with the given operands and pre-computed result.
const Rhs_T rhs_
Stores the right-hand operand.
Definition detail.h:289
const Lhs_T lhs_
Stores the left-hand operand.
Definition detail.h:281
constexpr auto rhs(void) const
Retrieves the right-hand operand.
constexpr callable_op_(bool value)
Constructs a callable operator with the pre-computed boolean result.
const bool value_
Stores the result of the callable invocation.
Definition detail.h:630
Equality comparator struct template.
Definition detail.h:315
constexpr eq_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs an equality comparator for the given operands.
Greater than or equal comparator struct template.
Definition detail.h:412
constexpr ge_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a greater than or equal comparator for the given operands.
Greater than comparator struct template.
Definition detail.h:379
constexpr gt_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a greater than comparator for the given operands.
Less than or equal comparator struct template.
Definition detail.h:478
constexpr le_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a less than or equal comparator for the given operands.
Less than comparator struct template.
Definition detail.h:445
constexpr lt_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a less than comparator for the given operands.
Non-equality comparator struct template.
Definition detail.h:347
constexpr ne_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a non-equality comparator for the given operands.
Logical NOT comparator struct template.
Definition detail.h:576
constexpr not_(const T &t={})
Constructs a logical NOT comparator for the given operand.
constexpr nothrow_(const Callable_T &func)
Constructs a nothrow checking operator for the given callable.
Logical OR comparator struct template.
Definition detail.h:545
constexpr or_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
Constructs a logical OR comparator for the given operands.
constexpr throws_(const Callable_T &func)
Constructs an exception checking operator for the given callable.
constexpr throws_(const Callable_T &func)
Constructs an exception checking operator for the given callable.
constexpr auto operand() const
Retrieves the wrapped operand expression.
constexpr unary_op_(const T &t, bool value)
Constructs a unary comparator with the given operand and pre-computed result.
const bool value_
Stores the result of the operation.
Definition detail.h:210
Empty base struct for all operator types.
C++ header file with declarations for the µTest++ type trait utilities and metaprogramming support.