| 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/engine/environment.hpp> | ||
| 12 | #include <tts/tools/source_location.hpp> | ||
| 13 | |||
| 14 | namespace tts::_ | ||
| 15 | { | ||
| 16 | //==================================================================================================================== | ||
| 17 | // Reporting functions. Inline rather than outlined under TTS_MAIN: a translation unit that writes | ||
| 18 | // its own main and uses the checks has to link without the driver. | ||
| 19 | //==================================================================================================================== | ||
| 20 | // Shared by report_fail/report_fatal - the only place the failing type shows up outside verbose. | ||
| 21 | 59 | inline void report_type_hint(::tts::text const& type) | |
| 22 | { | ||
| 23 |
6/6✓ Branch 1 taken 57 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 53 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 55 times.
|
59 | if(!::tts::is_verbose() && !type.is_empty()) |
| 24 |
1/1✓ Branch 3 taken 4 times.
|
4 | ::tts::output().writeln("> With <T = %s>", type.data()); |
| 25 | 59 | } | |
| 26 | |||
| 27 | 17 | inline void report_pass(char const* location, char const* message) | |
| 28 | { | ||
| 29 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 9 times.
|
17 | if(::tts::is_detailed()) |
| 30 | { | ||
| 31 | 8 | ::tts::output().writeln(" [+] %s : %s", location, message); | |
| 32 | } | ||
| 33 | 17 | } | |
| 34 | |||
| 35 | 55 | inline void report_fail(char const* location, char const* message, ::tts::text const& type) | |
| 36 | { | ||
| 37 | 55 | report_type_hint(type); | |
| 38 | |||
| 39 |
1/1✓ Branch 4 taken 55 times.
|
55 | ::tts::output().assertion_failed(::tts::text {location}, ::tts::text {message}, false); |
| 40 | |||
| 41 |
2/2✓ Branch 1 taken 53 times.
✓ Branch 2 taken 2 times.
|
55 | if(!::tts::is_quiet()) |
| 42 | { | ||
| 43 | 53 | ::tts::output().writeln(" [X] %s : ** FAILURE ** : %s", location, message); | |
| 44 | } | ||
| 45 | 55 | } | |
| 46 | |||
| 47 | 4 | inline void report_fatal(char const* location, char const* message, ::tts::text const& type) | |
| 48 | { | ||
| 49 | 4 | report_type_hint(type); | |
| 50 | |||
| 51 |
1/1✓ Branch 4 taken 4 times.
|
4 | ::tts::output().assertion_failed(::tts::text {location}, ::tts::text {message}, true); |
| 52 | |||
| 53 | 4 | ::tts::output().writeln(" [@] %s : @@ FATAL @@ : %s", location, message); | |
| 54 | 4 | } | |
| 55 | } | ||
| 56 | |||
| 57 | //====================================================================================================================== | ||
| 58 | /** | ||
| 59 | @name Informations Reporting | ||
| 60 | @{ | ||
| 61 | **/ | ||
| 62 | //====================================================================================================================== | ||
| 63 | |||
| 64 | //====================================================================================================================== | ||
| 65 | /** | ||
| 66 | @def TTS_PASS | ||
| 67 | @brief Force a passing test and display a message. | ||
| 68 | @ingroup test-basic | ||
| 69 | |||
| 70 | @param ... A format string and potential arguments to display as additional informations | ||
| 71 | |||
| 72 | @groupheader{Example} | ||
| 73 | @snippet doc/pass_fail.cpp snippet1 | ||
| 74 | **/ | ||
| 75 | //====================================================================================================================== | ||
| 76 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 77 | #define TTS_PASS(...) | ||
| 78 | #else | ||
| 79 | #define TTS_PASS(...) \ | ||
| 80 | do \ | ||
| 81 | { \ | ||
| 82 | ::tts::global_runtime.pass(); \ | ||
| 83 | ::tts::_::report_pass(::tts::_::source_location::current().data(), \ | ||
| 84 | ::tts::text {__VA_ARGS__}.data()); \ | ||
| 85 | } while(0) /**/ | ||
| 86 | /**/ | ||
| 87 | #endif | ||
| 88 | |||
| 89 | //====================================================================================================================== | ||
| 90 | /** | ||
| 91 | @def TTS_FAIL | ||
| 92 | @brief Force a failing test and display a message. | ||
| 93 | @ingroup test-basic | ||
| 94 | |||
| 95 | @param ... A format string and potential arguments to display as additional informations | ||
| 96 | |||
| 97 | @groupheader{Example} | ||
| 98 | @snippet doc/pass_fail.cpp snippet2 | ||
| 99 | **/ | ||
| 100 | //====================================================================================================================== | ||
| 101 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 102 | #define TTS_FAIL(...) | ||
| 103 | #else | ||
| 104 | #define TTS_FAIL(...) \ | ||
| 105 | do \ | ||
| 106 | { \ | ||
| 107 | ::tts::global_runtime.fail(); \ | ||
| 108 | if(!::tts::global_runtime.fail_status) ::tts::global_runtime.fail_status = true; \ | ||
| 109 | ::tts::_::report_fail(::tts::_::source_location::current().data(), \ | ||
| 110 | ::tts::text {__VA_ARGS__}.data(), \ | ||
| 111 | ::tts::_::current_type); \ | ||
| 112 | } while(0) /**/ | ||
| 113 | #endif | ||
| 114 | |||
| 115 | //====================================================================================================================== | ||
| 116 | /** | ||
| 117 | @def TTS_FATAL | ||
| 118 | @brief Force a failing test, display a message and halt the test suite. | ||
| 119 | @ingroup test-basic | ||
| 120 | |||
| 121 | @param ... A format string and potential arguments to display as additional informations | ||
| 122 | |||
| 123 | @groupheader{Example} | ||
| 124 | @snippet doc/pass_fail.cpp snippet3 | ||
| 125 | **/ | ||
| 126 | //====================================================================================================================== | ||
| 127 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 128 | #define TTS_FATAL(...) | ||
| 129 | #else | ||
| 130 | #define TTS_FATAL(...) \ | ||
| 131 | do \ | ||
| 132 | { \ | ||
| 133 | ::tts::global_runtime.fail(); \ | ||
| 134 | if(!::tts::global_runtime.fail_status) ::tts::global_runtime.fail_status = true; \ | ||
| 135 | ::tts::_::report_fatal(::tts::_::source_location::current().data(), \ | ||
| 136 | ::tts::text {__VA_ARGS__}.data(), \ | ||
| 137 | ::tts::_::current_type); \ | ||
| 138 | ::tts::fatal_error_status = true; \ | ||
| 139 | [[maybe_unused]] ::tts::_::logger _local_tts_fail_hard {}; \ | ||
| 140 | } while(0) /**/ | ||
| 141 | #endif | ||
| 142 | |||
| 143 | //====================================================================================================================== | ||
| 144 | /** | ||
| 145 | @} | ||
| 146 | **/ | ||
| 147 | //====================================================================================================================== | ||
| 148 |