| 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/text.hpp> | ||
| 12 | |||
| 13 | namespace tts::_ | ||
| 14 | { | ||
| 15 | // Every accepted --sink=name value - also drives the "expected one of: ..." error message | ||
| 16 | // below, so adding a new sink here is the only place that needs updating. | ||
| 17 | inline constexpr char const* sink_names[] = {// NOSONAR - <array> costs compile time | ||
| 18 | "colored", | ||
| 19 | "tap", | ||
| 20 | "diagnostics", | ||
| 21 | "json", | ||
| 22 | "junit"}; | ||
| 23 | inline constexpr std::size_t sink_count = sizeof(sink_names) / sizeof(sink_names[ 0 ]); | ||
| 24 | |||
| 25 | // Validates --sink=name (read from the current tts::arguments()). ok is set to false for an | ||
| 26 | // unknown, non-empty name, in which case the returned text is ready to print as an error. | ||
| 27 | 104 | inline ::tts::text validate_sink_name(::tts::text const& name, bool& ok) | |
| 28 | { | ||
| 29 | 104 | ok = name.is_empty(); | |
| 30 |
2/2✓ Branch 0 taken 520 times.
✓ Branch 1 taken 104 times.
|
624 | for(auto candidate: sink_names) |
| 31 |
6/6✓ Branch 0 taken 11 times.
✓ Branch 1 taken 509 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 509 times.
|
520 | ok = ok || (name == ::tts::text {candidate}); |
| 32 |
2/2✓ Branch 0 taken 103 times.
✓ Branch 1 taken 1 times.
|
104 | if(ok) return {}; |
| 33 | |||
| 34 | 1 | ::tts::text expected; | |
| 35 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 | for(std::size_t i = 0; i < sink_count; ++i) |
| 36 |
3/3✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 5 times.
|
5 | expected += ::tts::text {i ? ", %s" : "%s", sink_names[ i ]}; |
| 37 | |||
| 38 | return ::tts::text { | ||
| 39 | 1 | "Unknown --sink value '%s', expected one of: %s", name.data(), expected.data()}; | |
| 40 | 1 | } | |
| 41 | } | ||
| 42 |