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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-08-18 21:22:28 +0200
committerMartin Hořeňovský2022-08-18 23:23:18 +0200
commitdc001fa935d71b4b77f263fce405c9dbdfcbfe28 (patch)
tree829c8fc1837022b64b56d06e24df95b4ff4f3b0c /src/catch2
parent33e70194d32b8eb487b2f882b94353e0aed662cf (diff)
downloadcatch3-dc001fa935d71b4b77f263fce405c9dbdfcbfe28.tar.gz
Allow easy retrieval of RNG seed by the users
This makes it so that they don't need parallel RNG seed passing infrastructure for randomized data generation (e.g. inputs for benchmarks).
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_all.hpp1
-rw-r--r--src/catch2/catch_get_random_seed.cpp18
-rw-r--r--src/catch2/catch_get_random_seed.hpp18
-rw-r--r--src/catch2/reporters/catch_reporter_compact.cpp3
-rw-r--r--src/catch2/reporters/catch_reporter_console.cpp3
5 files changed, 41 insertions, 2 deletions
diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp
index 5c715e35..94f55223 100644
--- a/src/catch2/catch_all.hpp
+++ b/src/catch2/catch_all.hpp
@@ -27,6 +27,7 @@
#include <catch2/catch_assertion_info.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/catch_config.hpp>
+#include <catch2/catch_get_random_seed.hpp>
#include <catch2/catch_message.hpp>
#include <catch2/catch_section_info.hpp>
#include <catch2/catch_session.hpp>
diff --git a/src/catch2/catch_get_random_seed.cpp b/src/catch2/catch_get_random_seed.cpp
new file mode 100644
index 00000000..12a5b6d8
--- /dev/null
+++ b/src/catch2/catch_get_random_seed.cpp
@@ -0,0 +1,18 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+#include <catch2/catch_get_random_seed.hpp>
+
+#include <catch2/internal/catch_context.hpp>
+#include <catch2/catch_config.hpp>
+
+namespace Catch {
+ std::uint32_t getSeed() {
+ return getCurrentContext().getConfig()->rngSeed();
+ }
+}
diff --git a/src/catch2/catch_get_random_seed.hpp b/src/catch2/catch_get_random_seed.hpp
new file mode 100644
index 00000000..6df3c3a0
--- /dev/null
+++ b/src/catch2/catch_get_random_seed.hpp
@@ -0,0 +1,18 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+#ifndef CATCH_GET_RANDOM_SEED_HPP_INCLUDED
+#define CATCH_GET_RANDOM_SEED_HPP_INCLUDED
+
+#include <cstdint>
+
+namespace Catch {
+ //! Returns Catch2's current RNG seed.
+ std::uint32_t getSeed();
+}
+
+#endif // CATCH_GET_RANDOM_SEED_HPP_INCLUDED
diff --git a/src/catch2/reporters/catch_reporter_compact.cpp b/src/catch2/reporters/catch_reporter_compact.cpp
index 3f036ec5..a09f0483 100644
--- a/src/catch2/reporters/catch_reporter_compact.cpp
+++ b/src/catch2/reporters/catch_reporter_compact.cpp
@@ -7,6 +7,7 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/reporters/catch_reporter_compact.hpp>
+#include <catch2/catch_get_random_seed.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
@@ -261,7 +262,7 @@ private:
<< serializeFilters( m_config->getTestsOrTags() )
<< '\n';
}
- m_stream << "RNG seed: " << m_config->rngSeed() << '\n';
+ m_stream << "RNG seed: " << getSeed() << '\n';
}
void CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) {
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index bb755ed7..88d43b53 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -19,6 +19,7 @@
#include <catch2/internal/catch_console_width.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
+#include <catch2/catch_get_random_seed.hpp>
#include <cstdio>
@@ -500,7 +501,7 @@ void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) {
m_stream << m_colour->guardColour( Colour::BrightYellow ) << "Filters: "
<< serializeFilters( m_config->getTestsOrTags() ) << '\n';
}
- m_stream << "Randomness seeded to: " << m_config->rngSeed() << '\n';
+ m_stream << "Randomness seeded to: " << getSeed() << '\n';
}
void ConsoleReporter::lazyPrint() {