Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Catch::RunContext Class Reference

#include <catch_run_context.h>

Inheritance diagram for Catch::RunContext:
Collaboration diagram for Catch::RunContext:

Public Member Functions

 RunContext (RunContext const &)=delete
 
RunContextoperator= (RunContext const &)=delete
 
 RunContext (IConfigPtr const &_config, IStreamingReporterPtr &&reporter)
 
 ~RunContext () override
 
void testGroupStarting (std::string const &testSpec, std::size_t groupIndex, std::size_t groupsCount)
 
void testGroupEnded (std::string const &testSpec, Totals const &totals, std::size_t groupIndex, std::size_t groupsCount)
 
Totals runTest (TestCase const &testCase)
 
IConfigPtr config () const
 
IStreamingReporterreporter () const
 
void handleExpr (AssertionInfo const &info, ITransientExpression const &expr, AssertionReaction &reaction) override
 
void handleMessage (AssertionInfo const &info, ResultWas::OfType resultType, StringRef const &message, AssertionReaction &reaction) override
 
void handleUnexpectedExceptionNotThrown (AssertionInfo const &info, AssertionReaction &reaction) override
 
void handleUnexpectedInflightException (AssertionInfo const &info, std::string const &message, AssertionReaction &reaction) override
 
void handleIncomplete (AssertionInfo const &info) override
 
void handleNonExpr (AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction) override
 
bool sectionStarted (SectionInfo const &sectionInfo, Counts &assertions) override
 
void sectionEnded (SectionEndInfo const &endInfo) override
 
void sectionEndedEarly (SectionEndInfo const &endInfo) override
 
auto acquireGeneratorTracker (SourceLineInfo const &lineInfo) -> IGeneratorTracker &override
 
void benchmarkStarting (BenchmarkInfo const &info) override
 
void benchmarkEnded (BenchmarkStats const &stats) override
 
void pushScopedMessage (MessageInfo const &message) override
 
void popScopedMessage (MessageInfo const &message) override
 
void emplaceUnscopedMessage (MessageBuilder const &builder) override
 
std::string getCurrentTestName () const override
 
const AssertionResultgetLastResult () const override
 
void exceptionEarlyReported () override
 
void handleFatalErrorCondition (StringRef message) override
 
bool lastAssertionPassed () override
 
void assertionPassed () override
 
bool aborting () const final
 
- Public Member Functions inherited from Catch::IResultCapture
virtual ~IResultCapture ()
 
virtual ~IResultCapture ()
 
- Public Member Functions inherited from Catch::IRunner
virtual ~IRunner ()
 
virtual ~IRunner ()
 

Detailed Description

Definition at line 34 of file catch_run_context.h.

Constructor & Destructor Documentation

◆ RunContext() [1/2]

Catch::RunContext::RunContext ( RunContext const & )
delete

◆ RunContext() [2/2]

Catch::RunContext::RunContext ( IConfigPtr const & _config,
IStreamingReporterPtr && reporter )
explicit

Definition at line 70 of file catch_run_context.cpp.

71 : m_runInfo(_config->name()),
72 m_context(getCurrentMutableContext()),
73 m_config(_config),
74 m_reporter(std::move(reporter)),
75 m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal },
76 m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions )
77 {
78 m_context.setRunner(this);
79 m_context.setConfig(m_config);
80 m_context.setResultCapture(this);
81 m_reporter->testRunStarting(m_runInfo);
82 }
IStreamingReporter & reporter() const
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:364
IMutableContext & getCurrentMutableContext()
virtual void setResultCapture(IResultCapture *resultCapture)=0
virtual void setConfig(IConfigPtr const &config)=0
virtual void setRunner(IRunner *runner)=0
Here is the call graph for this function:

◆ ~RunContext()

Catch::RunContext::~RunContext ( )
override

Definition at line 84 of file catch_run_context.cpp.

84 {
85 m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting()));
86 }
bool aborting() const final
Here is the call graph for this function:

Member Function Documentation

◆ aborting()

bool Catch::RunContext::aborting ( ) const
finalvirtual

Implements Catch::IRunner.

Definition at line 315 of file catch_run_context.cpp.

315 {
316 return m_totals.assertions.failed >= static_cast<std::size_t>(m_config->abortAfter());
317 }
std::size_t failed
Counts assertions
Here is the caller graph for this function:

◆ acquireGeneratorTracker()

auto Catch::RunContext::acquireGeneratorTracker ( SourceLineInfo const & lineInfo) -> IGeneratorTracker&
overridevirtual

Implements Catch::IResultCapture.

Definition at line 190 of file catch_run_context.cpp.

190 {
191 using namespace Generators;
192 GeneratorTracker& tracker = GeneratorTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( "generator", lineInfo ) );
193 assert( tracker.isOpen() );
194 m_lastAssertionInfo.lineInfo = lineInfo;
195 return tracker;
196 }

◆ assertionPassed()

void Catch::RunContext::assertionPassed ( )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 308 of file catch_run_context.cpp.

308 {
309 m_lastAssertionPassed = true;
310 ++m_totals.assertions.passed;
311 resetAssertionInfo();
312 m_messageScopes.clear();
313 }
std::size_t passed
Here is the caller graph for this function:

◆ benchmarkEnded()

void Catch::RunContext::benchmarkEnded ( BenchmarkStats const & stats)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 236 of file catch_run_context.cpp.

236 {
237 m_reporter->benchmarkEnded( stats );
238 }

◆ benchmarkStarting()

void Catch::RunContext::benchmarkStarting ( BenchmarkInfo const & info)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 233 of file catch_run_context.cpp.

233 {
234 m_reporter->benchmarkStarting( info );
235 }

◆ config()

IConfigPtr Catch::RunContext::config ( ) const

Definition at line 137 of file catch_run_context.cpp.

137 {
138 return m_config;
139 }

◆ emplaceUnscopedMessage()

void Catch::RunContext::emplaceUnscopedMessage ( MessageBuilder const & builder)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 248 of file catch_run_context.cpp.

248 {
249 m_messageScopes.emplace_back( builder );
250 }

◆ exceptionEarlyReported()

void Catch::RunContext::exceptionEarlyReported ( )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 262 of file catch_run_context.cpp.

262 {
263 m_shouldReportUnexpected = false;
264 }

◆ getCurrentTestName()

std::string Catch::RunContext::getCurrentTestName ( ) const
overridevirtual

Implements Catch::IResultCapture.

Definition at line 252 of file catch_run_context.cpp.

252 {
253 return m_activeTestCase
254 ? m_activeTestCase->getTestCaseInfo().name
255 : std::string();
256 }
TestCaseInfo const & getTestCaseInfo() const
Here is the call graph for this function:

◆ getLastResult()

const AssertionResult * Catch::RunContext::getLastResult ( ) const
overridevirtual

Implements Catch::IResultCapture.

Definition at line 258 of file catch_run_context.cpp.

258 {
259 return &(*m_lastResult);
260 }

◆ handleExpr()

void Catch::RunContext::handleExpr ( AssertionInfo const & info,
ITransientExpression const & expr,
AssertionReaction & reaction )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 387 of file catch_run_context.cpp.

391 {
392 m_reporter->assertionStarting( info );
393
394 bool negated = isFalseTest( info.resultDisposition );
395 bool result = expr.getResult() != negated;
396
397 if( result ) {
398 if (!m_includeSuccessfulResults) {
400 }
401 else {
402 reportExpr(info, ResultWas::Ok, &expr, negated);
403 }
404 }
405 else {
406 reportExpr(info, ResultWas::ExpressionFailed, &expr, negated );
407 populateReaction( reaction );
408 }
409 }
void assertionPassed() override
bool isFalseTest(int flags)
Here is the call graph for this function:

◆ handleFatalErrorCondition()

void Catch::RunContext::handleFatalErrorCondition ( StringRef message)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 266 of file catch_run_context.cpp.

266 {
267 // First notify reporter that bad things happened
268 m_reporter->fatalErrorEncountered(message);
269
270 // Don't rebuild the result -- the stringification itself can cause more fatal errors
271 // Instead, fake a result data.
272 AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } );
273 tempResult.message = message;
274 AssertionResult result(m_lastAssertionInfo, tempResult);
275
276 assertionEnded(result);
277
278 handleUnfinishedSections();
279
280 // Recreate section for test case (as we will lose the one that was in scope)
281 auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
282 SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
283
284 Counts assertions;
285 assertions.failed = 1;
286 SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false);
287 m_reporter->sectionEnded(testCaseSectionStats);
288
289 auto const& testInfo = m_activeTestCase->getTestCaseInfo();
290
291 Totals deltaTotals;
292 deltaTotals.testCases.failed = 1;
293 deltaTotals.assertions.failed = 1;
294 m_reporter->testCaseEnded(TestCaseStats(testInfo,
295 deltaTotals,
296 std::string(),
297 std::string(),
298 false));
299 m_totals.testCases.failed++;
300 testGroupEnded(std::string(), m_totals, 1, 1);
301 m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false));
302 }
void testGroupEnded(std::string const &testSpec, Totals const &totals, std::size_t groupIndex, std::size_t groupsCount)
Here is the call graph for this function:

◆ handleIncomplete()

void Catch::RunContext::handleIncomplete ( AssertionInfo const & info)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 468 of file catch_run_context.cpp.

470 {
471 m_lastAssertionInfo = info;
472
473 AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
474 data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
475 AssertionResult assertionResult{ info, data };
476 assertionEnded( assertionResult );
477 }

◆ handleMessage()

void Catch::RunContext::handleMessage ( AssertionInfo const & info,
ResultWas::OfType resultType,
StringRef const & message,
AssertionReaction & reaction )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 425 of file catch_run_context.cpp.

430 {
431 m_reporter->assertionStarting( info );
432
433 m_lastAssertionInfo = info;
434
435 AssertionResultData data( resultType, LazyExpression( false ) );
436 data.message = message;
437 AssertionResult assertionResult{ m_lastAssertionInfo, data };
438 assertionEnded( assertionResult );
439 if( !assertionResult.isOk() )
440 populateReaction( reaction );
441 }

◆ handleNonExpr()

void Catch::RunContext::handleNonExpr ( AssertionInfo const & info,
ResultWas::OfType resultType,
AssertionReaction & reaction )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 478 of file catch_run_context.cpp.

482 {
483 m_lastAssertionInfo = info;
484
485 AssertionResultData data( resultType, LazyExpression( false ) );
486 AssertionResult assertionResult{ info, data };
487 assertionEnded( assertionResult );
488
489 if( !assertionResult.isOk() )
490 populateReaction( reaction );
491 }
Here is the caller graph for this function:

◆ handleUnexpectedExceptionNotThrown()

void Catch::RunContext::handleUnexpectedExceptionNotThrown ( AssertionInfo const & info,
AssertionReaction & reaction )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 442 of file catch_run_context.cpp.

445 {
447 }
void handleNonExpr(AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction) override
Here is the call graph for this function:

◆ handleUnexpectedInflightException()

void Catch::RunContext::handleUnexpectedInflightException ( AssertionInfo const & info,
std::string const & message,
AssertionReaction & reaction )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 449 of file catch_run_context.cpp.

453 {
454 m_lastAssertionInfo = info;
455
456 AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
457 data.message = message;
458 AssertionResult assertionResult{ info, data };
459 assertionEnded( assertionResult );
460 populateReaction( reaction );
461 }

◆ lastAssertionPassed()

bool Catch::RunContext::lastAssertionPassed ( )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 304 of file catch_run_context.cpp.

304 {
305 return m_lastAssertionPassed;
306 }

◆ operator=()

RunContext & Catch::RunContext::operator= ( RunContext const & )
delete

◆ popScopedMessage()

void Catch::RunContext::popScopedMessage ( MessageInfo const & message)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 244 of file catch_run_context.cpp.

244 {
245 m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end());
246 }

◆ pushScopedMessage()

void Catch::RunContext::pushScopedMessage ( MessageInfo const & message)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 240 of file catch_run_context.cpp.

240 {
241 m_messages.push_back(message);
242 }

◆ reporter()

IStreamingReporter & Catch::RunContext::reporter ( ) const

Definition at line 141 of file catch_run_context.cpp.

141 {
142 return *m_reporter;
143 }

◆ runTest()

Totals Catch::RunContext::runTest ( TestCase const & testCase)

Definition at line 96 of file catch_run_context.cpp.

96 {
97 Totals prevTotals = m_totals;
98
99 std::string redirectedCout;
100 std::string redirectedCerr;
101
102 auto const& testInfo = testCase.getTestCaseInfo();
103
104 m_reporter->testCaseStarting(testInfo);
105
106 m_activeTestCase = &testCase;
107
108
109 ITracker& rootTracker = m_trackerContext.startRun();
110 assert(rootTracker.isSectionTracker());
111 static_cast<SectionTracker&>(rootTracker).addInitialFilters(m_config->getSectionsToRun());
112 do {
113 m_trackerContext.startCycle();
114 m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo));
115 runCurrentTest(redirectedCout, redirectedCerr);
116 } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting());
117
118 Totals deltaTotals = m_totals.delta(prevTotals);
119 if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) {
120 deltaTotals.assertions.failed++;
121 deltaTotals.testCases.passed--;
122 deltaTotals.testCases.failed++;
123 }
124 m_totals.testCases += deltaTotals.testCases;
125 m_reporter->testCaseEnded(TestCaseStats(testInfo,
126 deltaTotals,
127 redirectedCout,
128 redirectedCerr,
129 aborting()));
130
131 m_activeTestCase = nullptr;
132 m_testCaseTracker = nullptr;
133
134 return deltaTotals;
135 }
static SectionTracker & acquire(TrackerContext &ctx, NameAndLocation const &nameAndLocation)
virtual bool isSuccessfullyCompleted() const =0
Totals delta(Totals const &prevTotals) const
Here is the call graph for this function:

◆ sectionEnded()

void Catch::RunContext::sectionEnded ( SectionEndInfo const & endInfo)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 210 of file catch_run_context.cpp.

210 {
211 Counts assertions = m_totals.assertions - endInfo.prevAssertions;
212 bool missingAssertions = testForMissingAssertions(assertions);
213
214 if (!m_activeSections.empty()) {
215 m_activeSections.back()->close();
216 m_activeSections.pop_back();
217 }
218
219 m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions));
220 m_messages.clear();
221 m_messageScopes.clear();
222 }

◆ sectionEndedEarly()

void Catch::RunContext::sectionEndedEarly ( SectionEndInfo const & endInfo)
overridevirtual

Implements Catch::IResultCapture.

Definition at line 224 of file catch_run_context.cpp.

224 {
225 if (m_unfinishedSections.empty())
226 m_activeSections.back()->fail();
227 else
228 m_activeSections.back()->close();
229 m_activeSections.pop_back();
230
231 m_unfinishedSections.push_back(endInfo);
232 }

◆ sectionStarted()

bool Catch::RunContext::sectionStarted ( SectionInfo const & sectionInfo,
Counts & assertions )
overridevirtual

Implements Catch::IResultCapture.

Definition at line 176 of file catch_run_context.cpp.

176 {
177 ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo));
178 if (!sectionTracker.isOpen())
179 return false;
180 m_activeSections.push_back(&sectionTracker);
181
182 m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
183
184 m_reporter->sectionStarting(sectionInfo);
185
186 assertions = m_totals.assertions;
187
188 return true;
189 }
Here is the call graph for this function:

◆ testGroupEnded()

void Catch::RunContext::testGroupEnded ( std::string const & testSpec,
Totals const & totals,
std::size_t groupIndex,
std::size_t groupsCount )

Definition at line 92 of file catch_run_context.cpp.

92 {
93 m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting()));
94 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ testGroupStarting()

void Catch::RunContext::testGroupStarting ( std::string const & testSpec,
std::size_t groupIndex,
std::size_t groupsCount )

Definition at line 88 of file catch_run_context.cpp.

88 {
89 m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount));
90 }

The documentation for this class was generated from the following files: