Testing: add --fail-fast for sequential runs

This commit is contained in:
faumaray committed 2026-12-04 01:15:29 +03:00
1 parent 28e253b49c
commit 4c0ebc76be
2 files changed
+15 -1

No files matched your search

+1
View File
@@ -96,6 +96,7 @@ namespace Void::Testing
bool shuffle{false};
bool show_help{false};
bool allow_empty{false};
bool fail_fast{false};
unsigned repeat{1};
unsigned random_seed{0};
unsigned parallel_threads{0}; // 0 = sequential
+14 -1
View File
@@ -199,6 +199,8 @@ namespace Void::Testing
config.no_color = true;
} else if (arg == "--allow-empty") {
config.allow_empty = true;
} else if (arg == "--fail-fast") {
config.fail_fast = true;
} else if (arg == "--shuffle") {
config.shuffle = true;
std::random_device rd;
@@ -546,6 +548,8 @@ namespace Void::Testing
<< Void::Testing::Detail::Color::apply(dim, "Disable colored console output") << "\n"
<< " " << opt("--allow-empty")
<< Void::Testing::Detail::Color::apply(dim, "Do not fail when selection matches zero tests") << "\n"
<< " " << opt("--fail-fast")
<< Void::Testing::Detail::Color::apply(dim, "Stop after the first failing test (sequential runs)") << "\n"
<< " " << opt("--help")
<< Void::Testing::Detail::Color::apply(dim, "Show this help message") << "\n"
<< "\n"
@@ -811,9 +815,13 @@ namespace Void::Testing
#endif
}
for (unsigned rep = 0; rep < config.repeat; ++rep) {
bool stop_run = false;
for (unsigned rep = 0; rep < config.repeat && !stop_run; ++rep) {
std::string current_suite;
for (auto& test : tests) {
if (stop_run) {
break;
}
auto& suite = suite_results[suite_index[test.suite]];
// Emit suite header only when the suite name changes.
if (test.suite != current_suite) {
@@ -834,6 +842,11 @@ namespace Void::Testing
}
reporter->on_test_start(test);
auto result = execute_test(test);
if (config.fail_fast &&
(result.state == TestState::Failed ||
result.state == TestState::Crashed)) {
stop_run = true;
}
reporter->on_test_end(result);
log_result(result, std::format("{}.{}", result.suite,
result.name));