micro-test-plus 4.1.0
µ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_TEST_PLUS_DETAIL_H_
43#define MICRO_TEST_PLUS_DETAIL_H_
44
45// ----------------------------------------------------------------------------
46
47#ifdef __cplusplus
48
49// ----------------------------------------------------------------------------
50
51#include <cstdio>
52#include <string>
53
54#include "type-traits.h"
55#include "reflection.h"
56
57// ----------------------------------------------------------------------------
58
59#if defined(__GNUC__)
60#pragma GCC diagnostic push
61#pragma GCC diagnostic ignored "-Wpadded"
62#pragma GCC diagnostic ignored "-Waggregate-return"
63#if defined(__clang__)
64#pragma clang diagnostic ignored "-Wc++98-compat"
65#endif
66#endif
67
68// ============================================================================
69
71{
72 class test_node;
73
74 // --------------------------------------------------------------------------
75
99 namespace detail
100 {
101 // ========================================================================
102
116 template <class Expr_T>
118 {
122 Expr_T expr{};
123
128 };
129
130 // ========================================================================
131
140 template <class T>
141 [[nodiscard]] constexpr auto
142 get (const T& t);
143
144 // ========================================================================
145
160 template <class T>
162 {
170 constexpr unary_op_ (const T& t, bool value);
171
179 [[nodiscard]] constexpr
180 operator bool () const;
181
189 [[nodiscard]] constexpr auto
190 operand () const;
191
192 private:
196 const T t_{};
197
201 const bool value_{};
202 };
203
204 // ========================================================================
205
222 template <class Lhs_T, class Rhs_T>
224 {
233 constexpr binary_op_ (const Lhs_T& lhs, const Rhs_T& rhs, bool value);
234
242 [[nodiscard]] constexpr
243 operator bool () const;
244
252 [[nodiscard]] constexpr auto
253 lhs (void) const;
254
262 [[nodiscard]] constexpr auto
263 rhs (void) const;
264
265 private:
272 const Lhs_T lhs_{};
273
280 const Rhs_T rhs_{};
281
285 const bool value_{};
286 };
287
288 // ========================================================================
289
304 template <class Lhs_T, class Rhs_T>
305 struct eq_ : binary_op_<Lhs_T, Rhs_T>
306 {
313 constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
314 };
315
316 // Deduction guide.
317 template <typename Lhs_T, typename Rhs_T>
318 eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
319
320 // ========================================================================
321
336 template <class Lhs_T, class Rhs_T>
337 struct ne_ : binary_op_<Lhs_T, Rhs_T>
338 {
345 constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
346 };
347
348 // Deduction guide.
349 template <typename Lhs_T, typename Rhs_T>
350 ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
351
352 // ========================================================================
353
368 template <class Lhs_T, class Rhs_T>
369 struct gt_ : binary_op_<Lhs_T, Rhs_T>
370 {
377 constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
378 };
379
380 // Deduction guide.
381 template <typename Lhs_T, typename Rhs_T>
382 gt_ (const Lhs_T&, const Rhs_T&) -> gt_<Lhs_T, Rhs_T>;
383
384 // ========================================================================
385
401 template <class Lhs_T, class Rhs_T>
402 struct ge_ : binary_op_<Lhs_T, Rhs_T>
403 {
411 constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
412 };
413
414 // Deduction guide.
415 template <typename Lhs_T, typename Rhs_T>
416 ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
417
418 // ========================================================================
419
434 template <class Lhs_T, class Rhs_T>
435 struct lt_ : binary_op_<Lhs_T, Rhs_T>
436 {
443 constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
444 };
445
446 // Deduction guide.
447 template <typename Lhs_T, typename Rhs_T>
448 lt_ (const Lhs_T&, const Rhs_T&) -> lt_<Lhs_T, Rhs_T>;
449
450 // ========================================================================
451
467 template <class Lhs_T, class Rhs_T>
468 struct le_ : binary_op_<Lhs_T, Rhs_T>
469 {
477 constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
478 };
479
480 // Deduction guide.
481 template <typename Lhs_T, typename Rhs_T>
482 le_ (const Lhs_T&, const Rhs_T&) -> le_<Lhs_T, Rhs_T>;
483
484 // ========================================================================
485
501 template <class Lhs_T, class Rhs_T>
502 struct and_ : binary_op_<Lhs_T, Rhs_T>
503 {
510 constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
511 };
512
513 // Deduction guide.
514 template <typename Lhs_T, typename Rhs_T>
515 and_ (const Lhs_T&, const Rhs_T&) -> and_<Lhs_T, Rhs_T>;
516
517 // ========================================================================
518
534 template <class Lhs_T, class Rhs_T>
535 struct or_ : binary_op_<Lhs_T, Rhs_T>
536 {
543 constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {});
544 };
545
546 // Deduction guide.
547 template <typename Lhs_T, typename Rhs_T>
548 or_ (const Lhs_T&, const Rhs_T&) -> or_<Lhs_T, Rhs_T>;
549
550 // ========================================================================
551
565 template <class T>
566 struct not_ : unary_op_<T>
567 {
573 explicit constexpr not_ (const T& t = {});
574 };
575
576 // Deduction guide.
577 template <typename T>
578 not_ (const T&) -> not_<T>;
579
580 // ========================================================================
581
582#if defined(__cpp_exceptions)
583
598 {
605 constexpr explicit callable_op_ (bool value);
606
614 [[nodiscard]] constexpr
615 operator bool () const;
616
617 private:
621 const bool value_{};
622 };
623
624 // ========================================================================
625
643 template <class Callable_T, class Exception_T = void>
645 {
652 constexpr explicit throws_ (const Callable_T& func);
653 };
654
655 // ========================================================================
656
672 template <class Callable_T>
673 struct throws_<Callable_T, void> : callable_op_
674 {
681 constexpr explicit throws_ (const Callable_T& func);
682 };
683
684 // ========================================================================
685
700 template <class Callable_T>
702 {
709 constexpr explicit nothrow_ (const Callable_T& func);
710 };
711
712#endif
713
714 // ========================================================================
715
727 template <class T>
728 requires std::is_arithmetic_v<T>
729 void
730 append_number_ (std::string& buffer, T v);
731
732 // ------------------------------------------------------------------------
733 } // namespace detail
734
735 // --------------------------------------------------------------------------
736} // namespace micro_os_plus::micro_test_plus
737
738#if defined(__GNUC__)
739#pragma GCC diagnostic pop
740#endif
741
742// ----------------------------------------------------------------------------
743
744#endif // __cplusplus
745
746// ============================================================================
747// Templates & constexpr implementations.
748
750
751// ----------------------------------------------------------------------------
752
753#endif // MICRO_TEST_PLUS_DETAIL_H_
754
755// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:138
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:503
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:118
Expr_T expr
The expression under evaluation.
Definition detail.h:122
reflection::source_location location
The source location associated with the assertion.
Definition detail.h:127
const bool value_
Stores the result of the comparison.
Definition detail.h:285
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:280
const Lhs_T lhs_
Stores the left-hand operand.
Definition detail.h:272
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:621
Equality comparator struct template.
Definition detail.h:306
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:403
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:370
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:469
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:436
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:338
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:567
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:536
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:201
Empty base struct for all operator types.
C++ header file with declarations for the µTest++ type trait utilities and metaprogramming support.