From 4c0ebc76be24fcc0621d9b35938e7ae1e74eb5e9 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 01:15:29 +0300 Subject: [PATCH] Testing: add --fail-fast for sequential runs --- include/Void/Testing/Config.hpp | 1 + src/Testing/Runner.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/Void/Testing/Config.hpp b/include/Void/Testing/Config.hpp index 3f0ce11..1e2a869 100644 --- a/include/Void/Testing/Config.hpp +++ b/include/Void/Testing/Config.hpp @@ -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 diff --git a/src/Testing/Runner.cpp b/src/Testing/Runner.cpp index 94b7f64..ce52ab5 100644 --- a/src/Testing/Runner.cpp +++ b/src/Testing/Runner.cpp @@ -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));