MCPcopy Create free account
hub / github.com/catchorg/Catch2 / runTest

Method runTest

extras/catch_amalgamated.cpp:6179–6271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6177 }
6178
6179 Totals RunContext::runTest(TestCaseHandle const& testCase) {
6180 updateTotalsFromAtomics();
6181 const Totals prevTotals = m_totals;
6182
6183 auto const& testInfo = testCase.getTestCaseInfo();
6184 m_reporter->testCaseStarting(testInfo);
6185 testCase.prepareTestCase();
6186 m_activeTestCase = &testCase;
6187
6188
6189 ITracker& rootTracker = m_trackerContext.startRun();
6190 assert(rootTracker.isSectionTracker());
6191 rootTracker.setFilters( &m_config->getPathFilters(),
6192 m_config->useNewFilterBehaviour() );
6193
6194 // We intentionally only seed the internal RNG once per test case,
6195 // before it is first invoked. The reason for that is a complex
6196 // interplay of generator/section implementation details and the
6197 // Random*Generator types.
6198 //
6199 // The issue boils down to us needing to seed the Random*Generators
6200 // with different seed each, so that they return different sequences
6201 // of random numbers. We do this by giving them a number from the
6202 // shared RNG instance as their seed.
6203 //
6204 // However, this runs into an issue if the reseeding happens each
6205 // time the test case is entered (as opposed to first time only),
6206 // because multiple generators could get the same seed, e.g. in
6207 // ```cpp
6208 // TEST_CASE() {
6209 // auto i = GENERATE(take(10, random(0, 100));
6210 // SECTION("A") {
6211 // auto j = GENERATE(take(10, random(0, 100));
6212 // }
6213 // SECTION("B") {
6214 // auto k = GENERATE(take(10, random(0, 100));
6215 // }
6216 // }
6217 // ```
6218 // `i` and `j` would properly return values from different sequences,
6219 // but `i` and `k` would return the same sequence, because their seed
6220 // would be the same.
6221 // (The reason their seeds would be the same is that the generator
6222 // for k would be initialized when the test case is entered the second
6223 // time, after the shared RNG instance was reset to the same value
6224 // it had when the generator for i was initialized.)
6225 seedRng( *m_config );
6226
6227 uint64_t testRuns = 0;
6228 std::string redirectedCout;
6229 std::string redirectedCerr;
6230 do {
6231 m_trackerContext.startCycle();
6232 m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocationRef(testInfo.name, testInfo.lineInfo));
6233
6234 m_reporter->testCasePartialStarting(testInfo, testRuns);
6235
6236 updateTotalsFromAtomics();

Callers 1

executeMethod · 0.45

Calls 15

seedRngFunction · 0.70
NameAndLocationRefClass · 0.70
TestCaseStatsClass · 0.70
testCaseStartingMethod · 0.45
prepareTestCaseMethod · 0.45
isSectionTrackerMethod · 0.45
setFiltersMethod · 0.45
useNewFilterBehaviourMethod · 0.45
startCycleMethod · 0.45
getStdoutMethod · 0.45
getStderrMethod · 0.45

Tested by

no test coverage detected