mirror of https://github.com/catchorg/Catch2.git
reseeds rng before each test case and provides access to seed through Catch::rngSeed() function
This commit is contained in:
parent
b971fe785b
commit
d87e551efa
|
@ -198,7 +198,7 @@ namespace Catch {
|
|||
if( m_configData.filenamesAsTags )
|
||||
applyFilenamesAsTags();
|
||||
|
||||
std::srand( m_configData.rngSeed );
|
||||
seedRng( *m_config );
|
||||
|
||||
Runner runner( m_config );
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
namespace Catch {
|
||||
|
||||
struct IConfig;
|
||||
|
||||
class NonCopyable {
|
||||
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
||||
NonCopyable( NonCopyable const& ) = delete;
|
||||
|
@ -109,6 +111,9 @@ namespace Catch {
|
|||
|
||||
void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
|
||||
|
||||
void seedRng( IConfig const& config );
|
||||
unsigned int rngSeed();
|
||||
|
||||
// Use this in variadic streaming macros to allow
|
||||
// >> +StreamEndStop
|
||||
// as well as
|
||||
|
|
|
@ -82,6 +82,14 @@ namespace Catch {
|
|||
return line < other.line || ( line == other.line && file < other.file );
|
||||
}
|
||||
|
||||
void seedRng( IConfig const& config ) {
|
||||
if( config.rngSeed() != 0 )
|
||||
std::srand( config.rngSeed() );
|
||||
}
|
||||
unsigned int rngSeed() {
|
||||
return getCurrentContext().getConfig()->rngSeed();
|
||||
}
|
||||
|
||||
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
|
||||
#ifndef __GNUG__
|
||||
os << info.file << "(" << info.line << ")";
|
||||
|
|
|
@ -259,6 +259,8 @@ namespace Catch {
|
|||
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
|
||||
TestCaseTracker::Guard guard( *m_testCaseTracker );
|
||||
|
||||
seedRng( *m_config );
|
||||
|
||||
Timer timer;
|
||||
timer.start();
|
||||
if( m_reporter->getPreferences().shouldRedirectStdOut ) {
|
||||
|
|
|
@ -90,6 +90,8 @@ namespace Catch {
|
|||
break;
|
||||
case RunTests::InRandomOrder:
|
||||
{
|
||||
seedRng( config );
|
||||
|
||||
RandomNumberGenerator rng;
|
||||
std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue