Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMatt Rasa2026-07-31 09:37:21 -0400
committerMartin Hořeňovský2026-08-11 00:08:23 +0200
commit0aeb818520028ca05cc2539ed242402ef7a7ae41 (patch)
tree90a9179143b09ae2c41b1ec62bb110f756aa09ad /src/catch2
parent97ec4e8e2e4a86719701746d1cb2426f16292ff8 (diff)
downloadcatch3-0aeb818520028ca05cc2539ed242402ef7a7ae41.tar.gz
Emit warning when using --shard-count (> 1) with --order rand
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_config.cpp2
-rw-r--r--src/catch2/catch_config.hpp2
-rw-r--r--src/catch2/catch_session.cpp13
-rw-r--r--src/catch2/internal/catch_commandline.cpp3
4 files changed, 20 insertions, 0 deletions
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index 86b9b8dd..e71ee353 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -209,6 +209,7 @@ namespace Catch {
double Config::minDuration() const { return m_data.minDuration; }
TestRunOrder Config::runOrder() const { return m_data.runOrder; }
uint32_t Config::rngSeed() const { return m_data.rngSeed; }
+ bool Config::rngSeedWasFixed() const { return m_data.rngSeedWasFixed; }
unsigned int Config::shardCount() const { return m_data.shardCount; }
unsigned int Config::shardIndex() const { return m_data.shardIndex; }
ColourMode Config::defaultColourMode() const { return m_data.defaultColourMode; }
@@ -273,6 +274,7 @@ namespace Catch {
<< bazelRandomSeed << "') as proper seed.\n";
} else {
m_data.rngSeed = *parsedSeed;
+ m_data.rngSeedWasFixed = true;
}
}
}
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index 429c7156..3d0c1e96 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -63,6 +63,7 @@ namespace Catch {
int abortAfter = -1;
uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
+ bool rngSeedWasFixed = false;
unsigned int shardCount = 1;
unsigned int shardIndex = 0;
@@ -134,6 +135,7 @@ namespace Catch {
double minDuration() const override;
TestRunOrder runOrder() const override;
uint32_t rngSeed() const override;
+ bool rngSeedWasFixed() const;
unsigned int shardCount() const override;
unsigned int shardIndex() const override;
ColourMode defaultColourMode() const override;
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index 97def8dc..5e9c5c19 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -348,6 +348,19 @@ namespace Catch {
CATCH_TRY {
config(); // Force config to be constructed
+ if ( m_config->shardCount() > 1 &&
+ m_config->runOrder() == TestRunOrder::Randomized &&
+ !m_config->rngSeedWasFixed() ) {
+ Catch::cerr()
+ << "Warning: using sharding (--shard-count) with random "
+ "order (--order rand, the default) and without a fixed "
+ "numeric --rng-seed does not guarantee disjoint coverage "
+ "between shard invocations. Pass the same numeric "
+ "--rng-seed to every shard, or use --order decl or "
+ "--order lex instead.\n"
+ << std::flush;
+ }
+
// We need to retrieve potential Bazel config with the full Config
// constructor, so we have to create the guard file after it is created.
setUpGuardFile( m_config->getExitGuardFilePath() );
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 4ce42397..22948c27 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -75,9 +75,11 @@ namespace Catch {
auto const setRngSeed = [&]( std::string const& seed ) {
if( seed == "time" ) {
config.rngSeed = generateRandomSeed(GenerateFrom::Time);
+ config.rngSeedWasFixed = false;
return ParserResult::ok(ParseResultType::Matched);
} else if (seed == "random-device") {
config.rngSeed = generateRandomSeed(GenerateFrom::RandomDevice);
+ config.rngSeedWasFixed = false;
return ParserResult::ok(ParseResultType::Matched);
}
@@ -88,6 +90,7 @@ namespace Catch {
return ParserResult::runtimeError( "Could not parse '" + seed + "' as seed" );
}
config.rngSeed = *parsedSeed;
+ config.rngSeedWasFixed = true;
return ParserResult::ok( ParseResultType::Matched );
};
auto const setDefaultColourMode = [&]( std::string const& colourMode ) {