mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-04 14:25:40 +02:00
Provide random-device option for --rng-seed and make it default
This commit is contained in:
@@ -72,7 +72,7 @@ namespace Catch {
|
||||
ShowDurations Config::showDurations() const { return m_data.showDurations; }
|
||||
double Config::minDuration() const { return m_data.minDuration; }
|
||||
TestRunOrder Config::runOrder() const { return m_data.runOrder; }
|
||||
unsigned int Config::rngSeed() const { return *m_data.rngSeed; }
|
||||
uint32_t Config::rngSeed() const { return m_data.rngSeed; }
|
||||
UseColour Config::useColour() const { return m_data.useColour; }
|
||||
bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
|
||||
int Config::abortAfter() const { return m_data.abortAfter; }
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/internal/catch_optional.hpp>
|
||||
#include <catch2/internal/catch_random_seed_generation.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -34,7 +35,7 @@ namespace Catch {
|
||||
bool libIdentify = false;
|
||||
|
||||
int abortAfter = -1;
|
||||
Optional<unsigned int> rngSeed;
|
||||
uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
|
||||
|
||||
bool benchmarkNoAnalysis = false;
|
||||
unsigned int benchmarkSamples = 100;
|
||||
@@ -97,7 +98,7 @@ namespace Catch {
|
||||
ShowDurations showDurations() const override;
|
||||
double minDuration() const override;
|
||||
TestRunOrder runOrder() const override;
|
||||
unsigned int rngSeed() const override;
|
||||
uint32_t rngSeed() const override;
|
||||
UseColour useColour() const override;
|
||||
bool shouldDebugBreak() const override;
|
||||
int abortAfter() const override;
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
|
||||
@@ -171,10 +170,6 @@ namespace Catch {
|
||||
if( m_startupExceptions )
|
||||
return 1;
|
||||
|
||||
if (!m_configData.rngSeed) {
|
||||
m_configData.rngSeed = static_cast<unsigned int>(std::time(nullptr));
|
||||
}
|
||||
|
||||
auto result = m_cli.parse( Clara::Args( argc, argv ) );
|
||||
if( !result ) {
|
||||
config();
|
||||
|
@@ -73,7 +73,7 @@ namespace Catch {
|
||||
virtual bool hasTestFilters() const = 0;
|
||||
virtual std::vector<std::string> const& getTestsOrTags() const = 0;
|
||||
virtual TestRunOrder runOrder() const = 0;
|
||||
virtual unsigned int rngSeed() const = 0;
|
||||
virtual uint32_t rngSeed() const = 0;
|
||||
virtual UseColour useColour() const = 0;
|
||||
virtual std::vector<std::string> const& getSectionsToRun() const = 0;
|
||||
virtual Verbosity verbosity() const = 0;
|
||||
|
@@ -15,7 +15,6 @@
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
namespace Catch {
|
||||
@@ -74,7 +73,10 @@ namespace Catch {
|
||||
};
|
||||
auto const setRngSeed = [&]( std::string const& seed ) {
|
||||
if( seed == "time" ) {
|
||||
config.rngSeed = static_cast<unsigned int>(std::time(nullptr));
|
||||
config.rngSeed = generateRandomSeed(GenerateFrom::Time);
|
||||
return ParserResult::ok(ParseResultType::Matched);
|
||||
} else if (seed == "random-device") {
|
||||
config.rngSeed = generateRandomSeed(GenerateFrom::RandomDevice);
|
||||
return ParserResult::ok(ParseResultType::Matched);
|
||||
}
|
||||
|
||||
@@ -211,7 +213,7 @@ namespace Catch {
|
||||
| Opt( setTestOrder, "decl|lex|rand" )
|
||||
["--order"]
|
||||
( "test case order (defaults to decl)" )
|
||||
| Opt( setRngSeed, "'time'|number" )
|
||||
| Opt( setRngSeed, "'time'|'random-device'|number" )
|
||||
["--rng-seed"]
|
||||
( "set a specific seed for random numbers" )
|
||||
| Opt( setColourUsage, "yes|no" )
|
||||
|
Reference in New Issue
Block a user