15 namespace Generators {
25 std::shared_ptr<GeneratorTracker> tracker;
29 assert( childTracker );
30 assert( childTracker->isGeneratorTracker() );
31 tracker = std::static_pointer_cast<GeneratorTracker>( childTracker );
34 tracker = std::make_shared<GeneratorTracker>(
nameAndLocation, ctx, ¤tTracker );
71 : m_runInfo(_config->
name()),
74 m_reporter(
std::move(reporter)),
76 m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions )
81 m_reporter->testRunStarting(m_runInfo);
89 m_reporter->testGroupStarting(
GroupInfo(testSpec, groupIndex, groupsCount));
97 Totals prevTotals = m_totals;
99 std::string redirectedCout;
100 std::string redirectedCerr;
104 m_reporter->testCaseStarting(testInfo);
106 m_activeTestCase = &testCase;
111 static_cast<SectionTracker&
>(rootTracker).addInitialFilters(m_config->getSectionsToRun());
115 runCurrentTest(redirectedCout, redirectedCerr);
131 m_activeTestCase =
nullptr;
132 m_testCaseTracker =
nullptr;
148 m_lastAssertionPassed =
true;
149 }
else if (!result.isOk()) {
150 m_lastAssertionPassed =
false;
157 m_lastAssertionPassed =
true;
162 static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
165 m_messageScopes.clear();
168 resetAssertionInfo();
169 m_lastResult = result;
171 void RunContext::resetAssertionInfo() {
173 m_lastAssertionInfo.
capturedExpression =
"{Unknown expression after the reported line}"_sr;
178 if (!sectionTracker.
isOpen())
180 m_activeSections.push_back(§ionTracker);
184 m_reporter->sectionStarting(sectionInfo);
191 using namespace Generators;
193 assert( tracker.isOpen() );
194 m_lastAssertionInfo.lineInfo = lineInfo;
198 bool RunContext::testForMissingAssertions(
Counts& assertions) {
199 if (assertions.
total() != 0)
201 if (!m_config->warnAboutMissingAssertions())
212 bool missingAssertions = testForMissingAssertions(assertions);
214 if (!m_activeSections.empty()) {
215 m_activeSections.back()->close();
216 m_activeSections.pop_back();
221 m_messageScopes.clear();
225 if (m_unfinishedSections.empty())
226 m_activeSections.back()->fail();
228 m_activeSections.back()->close();
229 m_activeSections.pop_back();
231 m_unfinishedSections.push_back(endInfo);
234 m_reporter->benchmarkStarting( info );
237 m_reporter->benchmarkEnded( stats );
241 m_messages.push_back(message);
245 m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end());
249 m_messageScopes.emplace_back( builder );
253 return m_activeTestCase
259 return &(*m_lastResult);
263 m_shouldReportUnexpected =
false;
268 m_reporter->fatalErrorEncountered(message);
276 assertionEnded(result);
278 handleUnfinishedSections();
282 SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
286 SectionStats testCaseSectionStats(testCaseSection, assertions, 0,
false);
287 m_reporter->sectionEnded(testCaseSectionStats);
301 m_reporter->testRunEnded(
TestRunStats(m_runInfo, m_totals,
false));
305 return m_lastAssertionPassed;
309 m_lastAssertionPassed =
true;
311 resetAssertionInfo();
312 m_messageScopes.clear();
316 return m_totals.
assertions.
failed >=
static_cast<std::size_t
>(m_config->abortAfter());
319 void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) {
321 SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
322 m_reporter->sectionStarting(testCaseSection);
325 m_shouldReportUnexpected =
true;
332 if (m_reporter->getPreferences().shouldRedirectStdOut) {
333#if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
334 RedirectedStreams redirectedStreams(redirectedCout, redirectedCerr);
337 invokeActiveTestCase();
339 OutputRedirect
r(redirectedCout, redirectedCerr);
341 invokeActiveTestCase();
345 invokeActiveTestCase();
347 duration = timer.getElapsedSeconds();
353 if( m_shouldReportUnexpected ) {
354 AssertionReaction dummyReaction;
358 Counts assertions = m_totals.
assertions - prevAssertions;
359 bool missingAssertions = testForMissingAssertions(assertions);
361 m_testCaseTracker->
close();
362 handleUnfinishedSections();
364 m_messageScopes.clear();
366 SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions);
367 m_reporter->sectionEnded(testCaseSectionStats);
370 void RunContext::invokeActiveTestCase() {
371 FatalConditionHandler fatalConditionHandler;
372 m_activeTestCase->
invoke();
373 fatalConditionHandler.reset();
376 void RunContext::handleUnfinishedSections() {
379 for (
auto it = m_unfinishedSections.rbegin(),
380 itEnd = m_unfinishedSections.rend();
384 m_unfinishedSections.clear();
392 m_reporter->assertionStarting( info );
394 bool negated =
isFalseTest( info.resultDisposition );
395 bool result = expr.
getResult() != negated;
398 if (!m_includeSuccessfulResults) {
407 populateReaction( reaction );
410 void RunContext::reportExpr(
416 m_lastAssertionInfo = info;
422 assertionEnded( assertionResult );
431 m_reporter->assertionStarting( info );
433 m_lastAssertionInfo = info;
436 data.message = message;
438 assertionEnded( assertionResult );
439 if( !assertionResult.isOk() )
440 populateReaction( reaction );
451 std::string
const& message,
454 m_lastAssertionInfo = info;
457 data.message = message;
459 assertionEnded( assertionResult );
460 populateReaction( reaction );
471 m_lastAssertionInfo = info;
474 data.message =
"Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
476 assertionEnded( assertionResult );
483 m_lastAssertionInfo = info;
487 assertionEnded( assertionResult );
489 if( !assertionResult.isOk() )
490 populateReaction( reaction );
#define CATCH_CATCH_ANON(type)
#define CATCH_INTERNAL_ERROR(msg)
AssertionResultData m_resultData
void handleIncomplete(AssertionInfo const &info) override
IConfigPtr config() const
void benchmarkStarting(BenchmarkInfo const &info) override
auto acquireGeneratorTracker(SourceLineInfo const &lineInfo) -> IGeneratorTracker &override
RunContext(RunContext const &)=delete
void popScopedMessage(MessageInfo const &message) override
void benchmarkEnded(BenchmarkStats const &stats) override
void sectionEnded(SectionEndInfo const &endInfo) override
Totals runTest(TestCase const &testCase)
void emplaceUnscopedMessage(MessageBuilder const &builder) override
std::string getCurrentTestName() const override
void handleExpr(AssertionInfo const &info, ITransientExpression const &expr, AssertionReaction &reaction) override
void sectionEndedEarly(SectionEndInfo const &endInfo) override
void testGroupEnded(std::string const &testSpec, Totals const &totals, std::size_t groupIndex, std::size_t groupsCount)
IStreamingReporter & reporter() const
void exceptionEarlyReported() override
void assertionPassed() override
bool lastAssertionPassed() override
void pushScopedMessage(MessageInfo const &message) override
void handleNonExpr(AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction) override
const AssertionResult * getLastResult() const override
void handleFatalErrorCondition(StringRef message) override
void handleMessage(AssertionInfo const &info, ResultWas::OfType resultType, StringRef const &message, AssertionReaction &reaction) override
bool sectionStarted(SectionInfo const §ionInfo, Counts &assertions) override
bool aborting() const final
void handleUnexpectedExceptionNotThrown(AssertionInfo const &info, AssertionReaction &reaction) override
void testGroupStarting(std::string const &testSpec, std::size_t groupIndex, std::size_t groupsCount)
void handleUnexpectedInflightException(AssertionInfo const &info, std::string const &message, AssertionReaction &reaction) override
TestCaseInfo const & getTestCaseInfo() const
static SectionTracker & acquire(TrackerContext &ctx, NameAndLocation const &nameAndLocation)
NameAndLocation const & nameAndLocation() const override
TrackerBase(NameAndLocation const &nameAndLocation, TrackerContext &ctx, ITracker *parent)
ITracker & currentTracker()
bool completedCycle() const
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
std::unique_ptr< GeneratorUntypedBase > GeneratorBasePtr
std::shared_ptr< ITracker > ITrackerPtr
void seedRng(IConfig const &config)
std::unique_ptr< IStreamingReporter > IStreamingReporterPtr
IContext & getCurrentContext()
IMutableContext & getCurrentMutableContext()
bool isFalseTest(int flags)
std::shared_ptr< IConfig const > IConfigPtr
std::string translateActiveException()
IResultCapture & getResultCapture()
ResultDisposition::Flags resultDisposition
StringRef capturedExpression
LazyExpression lazyExpression
std::size_t total() const
static GeneratorTracker & acquire(TrackerContext &ctx, TestCaseTracking::NameAndLocation const &nameAndLocation)
GeneratorBasePtr m_generator
bool isGeneratorTracker() const override
void setGenerator(GeneratorBasePtr &&generator) override
auto getGenerator() const -> GeneratorBasePtr const &override
GeneratorTracker(TestCaseTracking::NameAndLocation const &nameAndLocation, TrackerContext &ctx, ITracker *parent)
auto hasGenerator() const -> bool override
virtual void setResultCapture(IResultCapture *resultCapture)=0
virtual void setConfig(IConfigPtr const &config)=0
virtual void setRunner(IRunner *runner)=0
auto getResult() const -> bool
virtual bool hasChildren() const =0
virtual ITrackerPtr findChild(NameAndLocation const &nameAndLocation)=0
virtual bool isOpen() const =0
virtual bool isSectionTracker() const =0
virtual bool isSuccessfullyCompleted() const =0
virtual void addChild(ITrackerPtr const &child)=0
Totals delta(Totals const &prevTotals) const