diff options
| author | Phil Nash | 2015-07-02 23:02:35 +0100 |
|---|---|---|
| committer | Phil Nash | 2015-07-02 23:02:35 +0100 |
| commit | d87e551efabb32bb08cd9abff51bb0c47fe6081c (patch) | |
| tree | ac3bf95b57236f442b23d81524d7de4269b30880 /include | |
| parent | b971fe785b2b346c2c66f84a5c9ee0681e3ee7d3 (diff) | |
| download | catch3-d87e551efabb32bb08cd9abff51bb0c47fe6081c.tar.gz | |
reseeds rng before each test case and provides access to seed through Catch::rngSeed() function
Diffstat (limited to 'include')
| -rw-r--r-- | include/catch_runner.hpp | 2 | ||||
| -rw-r--r-- | include/internal/catch_common.h | 5 | ||||
| -rw-r--r-- | include/internal/catch_common.hpp | 8 | ||||
| -rw-r--r-- | include/internal/catch_runner_impl.hpp | 2 | ||||
| -rw-r--r-- | include/internal/catch_test_case_registry_impl.hpp | 2 |
5 files changed, 18 insertions, 1 deletions
diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index 3a674148..18754483 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -198,7 +198,7 @@ namespace Catch { if( m_configData.filenamesAsTags ) applyFilenamesAsTags(); - std::srand( m_configData.rngSeed ); + seedRng( *m_config ); Runner runner( m_config ); diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index 9f07e47c..cec7eba5 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -22,6 +22,8 @@ #include "catch_compiler_capabilities.h" namespace Catch { + + struct IConfig; class NonCopyable { #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS @@ -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 diff --git a/include/internal/catch_common.hpp b/include/internal/catch_common.hpp index 8a42d0a0..69a64ad1 100644 --- a/include/internal/catch_common.hpp +++ b/include/internal/catch_common.hpp @@ -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 << ")"; diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 98f3dfd1..073f78d3 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -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 ) { diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp index 21165a30..b25ed9a2 100644 --- a/include/internal/catch_test_case_registry_impl.hpp +++ b/include/internal/catch_test_case_registry_impl.hpp @@ -90,6 +90,8 @@ namespace Catch { break; case RunTests::InRandomOrder: { + seedRng( config ); + RandomNumberGenerator rng; std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); } |