From 3990c77155a805ed61ea90da6d132a595b45839a Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 01:29:53 +0300 Subject: [PATCH] Testing: add --shard i/n for CI splits --- include/Void/Testing/Config.hpp | 3 +++ src/Testing/Runner.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/Void/Testing/Config.hpp b/include/Void/Testing/Config.hpp index 1e2a869..166f7fd 100644 --- a/include/Void/Testing/Config.hpp +++ b/include/Void/Testing/Config.hpp @@ -97,6 +97,9 @@ namespace Void::Testing bool show_help{false}; bool allow_empty{false}; bool fail_fast{false}; + /// CI sharding: 1-based shard index and shard count (1/1 = no split). + unsigned shard_index{1}; + unsigned shard_count{1}; 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 ce52ab5..c96dc3b 100644 --- a/src/Testing/Runner.cpp +++ b/src/Testing/Runner.cpp @@ -189,6 +189,23 @@ namespace Void::Testing } } } + } else if (arg == "--shard") { + std::string val; + if (need_val(arg, i, val)) { + const auto slash = val.find('/'); + unsigned index = 0; + unsigned count = 0; + if (slash == std::string::npos || + !parse_unsigned_strict(val.substr(0, slash), index) || + !parse_unsigned_strict(val.substr(slash + 1), count) || + count == 0 || index == 0 || index > count) { + config.parse_error = + std::format("Invalid --shard value: {} (expected i/n, 1 <= i <= n)", val); + } else { + config.shard_index = index; + config.shard_count = count; + } + } } else if (arg == "--help") { config.show_help = true; } else if (arg == "--list") { @@ -227,6 +244,7 @@ namespace Void::Testing return {}; } } + std::size_t selected_index = 0; for (const auto& test : tests) { if (!config.suite_filter.empty() && test.suite != config.suite_filter) { @@ -249,6 +267,14 @@ namespace Void::Testing continue; } } + // Deterministic round-robin sharding over the selected order. + if (config.shard_count > 1 && + (selected_index % config.shard_count) != + (config.shard_index - 1)) { + ++selected_index; + continue; + } + ++selected_index; result.push_back(test); } return result; @@ -550,6 +576,8 @@ namespace Void::Testing << 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("--shard /") + << Void::Testing::Detail::Color::apply(dim, "Run only shard i of n (for CI splits)") << "\n" << " " << opt("--help") << Void::Testing::Detail::Color::apply(dim, "Show this help message") << "\n" << "\n"