| 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/case.hpp> | ||
| 12 | #include <tts/engine/info.hpp> | ||
| 13 | #include <tts/engine/logger.hpp> | ||
| 14 | |||
| 15 | // What every check macro shares: where it is written, its count and its report. | ||
| 16 | namespace tts::_ | ||
| 17 | { | ||
| 18 | struct check_site | ||
| 19 | { | ||
| 20 | char const* file; | ||
| 21 | int line; | ||
| 22 | bool fatal; | ||
| 23 | char const* lhs = ""; | ||
| 24 | char const* op = ""; | ||
| 25 | char const* rhs = ""; | ||
| 26 | char const* negated = ""; | ||
| 27 | }; | ||
| 28 | |||
| 29 | 1601514 | inline bool check_passed() | |
| 30 | { | ||
| 31 | 1601514 | ::tts::global_runtime.pass(); | |
| 32 | 1601514 | return ::tts::is_detailed(); | |
| 33 | } | ||
| 34 | |||
| 35 | 8 | inline void check_report(check_site const& site, ::tts::text const& message) | |
| 36 | { | ||
| 37 |
1/1✓ Branch 4 taken 8 times.
|
8 | report_pass(source_location::current(site.file, site.line).data(), message.data()); |
| 38 | 8 | } | |
| 39 | |||
| 40 | 47 | inline logger check_failed(check_site const& site, ::tts::text const& message) | |
| 41 | { | ||
| 42 | 47 | ::tts::global_runtime.fail(); | |
| 43 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 22 times.
|
47 | if(!::tts::global_runtime.fail_status) ::tts::global_runtime.fail_status = true; |
| 44 | |||
| 45 | 47 | auto location = source_location::current(site.file, site.line); | |
| 46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if(site.fatal) |
| 47 | { | ||
| 48 | ✗ | report_fatal(location.data(), message.data(), current_type); | |
| 49 | ✗ | ::tts::fatal_error_status = true; | |
| 50 | ✗ | [[maybe_unused]] logger local_tts_fail_hard {}; // throws from its destructor | |
| 51 | ✗ | } | |
| 52 | else | ||
| 53 | { | ||
| 54 |
1/1✓ Branch 3 taken 47 times.
|
47 | report_fail(location.data(), message.data(), current_type); |
| 55 | } | ||
| 56 | |||
| 57 | 94 | return logger {}; | |
| 58 | 47 | } | |
| 59 | } | ||
| 60 | |||
| 61 | // FAILURE is TTS_FAIL or TTS_FATAL: it is pasted onto TTS_IS_FATAL_. | ||
| 62 | #define TTS_CHECK_SITE(FAILURE, LHS, OP, RHS, NEGATED) \ | ||
| 63 | ::tts::_::check_site \ | ||
| 64 | { \ | ||
| 65 | __builtin_FILE(), __builtin_LINE(), TTS_IS_FATAL_##FAILURE, LHS, OP, RHS, NEGATED \ | ||
| 66 | } | ||
| 67 | |||
| 68 | #define TTS_IS_FATAL_TTS_FAIL false | ||
| 69 | #define TTS_IS_FATAL_TTS_FATAL true | ||
| 70 |