| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | //! @file | ||
| 3 | /* | ||
| 4 | TTS - Tiny Test System | ||
| 5 | Copyright : TTS Contributors & Maintainers | ||
| 6 | SPDX-License-Identifier: BSL-1.0 | ||
| 7 | */ | ||
| 8 | //====================================================================================================================== | ||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include <tts/tools/preprocessor.hpp> | ||
| 12 | #include <tts/engine/logger.hpp> | ||
| 13 | #include <tts/engine/info.hpp> | ||
| 14 | #include <tts/engine/check.hpp> | ||
| 15 | |||
| 16 | namespace tts::_ | ||
| 17 | { | ||
| 18 | inline logger | ||
| 19 | 1600203 | check_expect(bool value, bool expected, check_site const& site, char const* kind = "Expression") | |
| 20 | { | ||
| 21 |
2/2✓ Branch 0 taken 1600191 times.
✓ Branch 1 taken 12 times.
|
1600203 | if(value == expected) |
| 22 | { | ||
| 23 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1600184 times.
|
1600191 | if(check_passed()) |
| 24 |
1/1✓ Branch 1 taken 7 times.
|
7 | check_report( |
| 25 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
|
14 | site, ::tts::text {"%s: %s evaluates to %s.", kind, site.lhs, expected ? "true" : "false"}); |
| 26 | 1600191 | return logger {false}; | |
| 27 | } | ||
| 28 | |||
| 29 | return check_failed( | ||
| 30 |
3/3✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 12 times.
|
12 | site, ::tts::text {"%s: %s evaluates to %s.", kind, site.lhs, value ? "true" : "false"}); |
| 31 | ✗ | } | |
| 32 | } | ||
| 33 | |||
| 34 | //====================================================================================================================== | ||
| 35 | /** | ||
| 36 | @defgroup test-basic Basic Tests Macros | ||
| 37 | @brief Macros for performing direct true/false checks over predicate-like expressions. | ||
| 38 | @{ | ||
| 39 | **/ | ||
| 40 | //====================================================================================================================== | ||
| 41 | |||
| 42 | //====================================================================================================================== | ||
| 43 | /** | ||
| 44 | @name Predicate Checks | ||
| 45 | @{ | ||
| 46 | **/ | ||
| 47 | //====================================================================================================================== | ||
| 48 | |||
| 49 | //====================================================================================================================== | ||
| 50 | /** | ||
| 51 | @def TTS_EXPECT | ||
| 52 | @brief Check if a given expression evaluates to true | ||
| 53 | |||
| 54 | @param EXPR Expression to evaluate and compare to `true`. | ||
| 55 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 56 | |||
| 57 | @groupheader{Example} | ||
| 58 | @snippet doc/expect.cpp snippet | ||
| 59 | **/ | ||
| 60 | //====================================================================================================================== | ||
| 61 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 62 | #define TTS_EXPECT(EXPR, ...) | ||
| 63 | #else | ||
| 64 | #define TTS_EXPECT(EXPR, ...) TTS_EXPECT_##__VA_ARGS__(EXPR) | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #define TTS_EXPECT_(EXPR) TTS_EXPECT_IMPL((EXPR), TTS_FAIL) | ||
| 68 | #define TTS_EXPECT_REQUIRED(EXPR) TTS_EXPECT_IMPL((EXPR), TTS_FATAL) | ||
| 69 | |||
| 70 | #define TTS_EXPECT_IMPL(EXPR, FAILURE) \ | ||
| 71 | ::tts::_::check_expect( \ | ||
| 72 | static_cast<bool>(EXPR), \ | ||
| 73 | true, \ | ||
| 74 | TTS_CHECK_SITE(FAILURE, TTS_STRING(TTS_REMOVE_PARENS(EXPR)), "", "", "")) /**/ | ||
| 75 | |||
| 76 | //====================================================================================================================== | ||
| 77 | /** | ||
| 78 | @def TTS_EXPECT_NOT | ||
| 79 | @brief Check if a given expression evaluates to false | ||
| 80 | |||
| 81 | @param EXPR Expression to evaluate and compare to `false`. | ||
| 82 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 83 | |||
| 84 | @groupheader{Example} | ||
| 85 | @snippet doc/expect_not.cpp snippet | ||
| 86 | **/ | ||
| 87 | //====================================================================================================================== | ||
| 88 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 89 | #define TTS_EXPECT_NOT(EXPR, ...) | ||
| 90 | #else | ||
| 91 | #define TTS_EXPECT_NOT(EXPR, ...) TTS_EXPECT_NOT_##__VA_ARGS__(EXPR) | ||
| 92 | #endif | ||
| 93 | |||
| 94 | #define TTS_EXPECT_NOT_(EXPR) TTS_EXPECT_NOT_IMPL(EXPR, TTS_FAIL) | ||
| 95 | #define TTS_EXPECT_NOT_REQUIRED(EXPR) TTS_EXPECT_NOT_IMPL(EXPR, TTS_FATAL) | ||
| 96 | |||
| 97 | #define TTS_EXPECT_NOT_IMPL(EXPR, FAILURE) \ | ||
| 98 | ::tts::_::check_expect( \ | ||
| 99 | static_cast<bool>(EXPR), \ | ||
| 100 | false, \ | ||
| 101 | TTS_CHECK_SITE(FAILURE, TTS_STRING(TTS_REMOVE_PARENS(EXPR)), "", "", "")) /**/ | ||
| 102 | |||
| 103 | //====================================================================================================================== | ||
| 104 | /** | ||
| 105 | @def TTS_CONSTEXPR_EXPECT | ||
| 106 | @brief Check if a given expression evaluates to true at compile-time | ||
| 107 | |||
| 108 | @param EXPR Expression to evaluate and compare to `true`. | ||
| 109 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 110 | |||
| 111 | @groupheader{Example} | ||
| 112 | @snippet doc/cexpr_expect.cpp snippet | ||
| 113 | **/ | ||
| 114 | //====================================================================================================================== | ||
| 115 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 116 | #define TTS_CONSTEXPR_EXPECT(EXPR, ...) | ||
| 117 | #else | ||
| 118 | #define TTS_CONSTEXPR_EXPECT(EXPR, ...) TTS_CEXPR_EXPECT_##__VA_ARGS__(EXPR) | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #define TTS_CEXPR_EXPECT_(EXPR) TTS_CEXPR_EXPECT_IMPL(EXPR, TTS_FAIL) | ||
| 122 | #define TTS_CEXPR_EXPECT_REQUIRED(EXPR) TTS_CEXPR_EXPECT_IMPL(EXPR, TTS_FATAL) | ||
| 123 | |||
| 124 | #define TTS_CEXPR_EXPECT_IMPL(EXPR, FAILURE) \ | ||
| 125 | ::tts::_::check_expect(std::bool_constant<static_cast<bool>(EXPR)>::value, \ | ||
| 126 | true, \ | ||
| 127 | TTS_CHECK_SITE(FAILURE, TTS_STRING(TTS_REMOVE_PARENS(EXPR)), "", "", ""), \ | ||
| 128 | "Constant expression") | ||
| 129 | /**/ | ||
| 130 | |||
| 131 | //====================================================================================================================== | ||
| 132 | /** | ||
| 133 | @def TTS_CONSTEXPR_EXPECT_NOT | ||
| 134 | @brief Check if a given expression evaluates to false at compile-time | ||
| 135 | |||
| 136 | @param EXPR Expression to evaluate and compare to `false`. | ||
| 137 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 138 | |||
| 139 | @groupheader{Example} | ||
| 140 | @snippet doc/cexpr_expect_not.cpp snippet | ||
| 141 | **/ | ||
| 142 | //====================================================================================================================== | ||
| 143 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 144 | #define TTS_CONSTEXPR_EXPECT_NOT(EXPR, ...) | ||
| 145 | #else | ||
| 146 | #define TTS_CONSTEXPR_EXPECT_NOT(EXPR, ...) TTS_CEXPR_EXPECT_NOT_##__VA_ARGS__(EXPR) | ||
| 147 | #endif | ||
| 148 | |||
| 149 | #define TTS_CEXPR_EXPECT_NOT_(EXPR) TTS_CEXPR_EXPECT_NOT_IMPL(EXPR, TTS_FAIL) | ||
| 150 | #define TTS_CEXPR_EXPECT_NOT_REQUIRED(EXPR) TTS_CEXPR_EXPECT_NOT_IMPL(EXPR, TTS_FATAL) | ||
| 151 | |||
| 152 | #define TTS_CEXPR_EXPECT_NOT_IMPL(EXPR, FAILURE) \ | ||
| 153 | ::tts::_::check_expect(std::bool_constant<static_cast<bool>(EXPR)>::value, \ | ||
| 154 | false, \ | ||
| 155 | TTS_CHECK_SITE(FAILURE, TTS_STRING(TTS_REMOVE_PARENS(EXPR)), "", "", ""), \ | ||
| 156 | "Constant expression") /**/ | ||
| 157 | |||
| 158 | //====================================================================================================================== | ||
| 159 | /** | ||
| 160 | @} | ||
| 161 | **/ | ||
| 162 | //====================================================================================================================== | ||
| 163 | |||
| 164 | //====================================================================================================================== | ||
| 165 | /** | ||
| 166 | @} | ||
| 167 | **/ | ||
| 168 | //====================================================================================================================== | ||
| 169 |