Fitted new section tracking

This commit is contained in:
Phil Nash 2015-11-02 19:21:46 +00:00
parent 0b523db6b9
commit 52a417df7b
2 changed files with 38 additions and 11 deletions

View File

@ -70,6 +70,7 @@ namespace Catch {
m_context.setConfig( m_config ); m_context.setConfig( m_config );
m_context.setResultCapture( this ); m_context.setResultCapture( this );
m_reporter->testRunStarting( m_runInfo ); m_reporter->testRunStarting( m_runInfo );
m_trackerContext.startRun();
} }
virtual ~RunContext() { virtual ~RunContext() {
@ -94,14 +95,17 @@ namespace Catch {
m_reporter->testCaseStarting( testInfo ); m_reporter->testCaseStarting( testInfo );
m_activeTestCase = &testCase; m_activeTestCase = &testCase;
m_testCaseTracker = TestCaseTracker( testInfo.name );
do { do {
do { do {
m_trackerContext.startCycle();
m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, testInfo.name );
runCurrentTest( redirectedCout, redirectedCerr ); runCurrentTest( redirectedCout, redirectedCerr );
} }
while( !m_testCaseTracker->isCompleted() && !aborting() ); while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
} }
// !TBD: deprecated
while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
Totals deltaTotals = m_totals.delta( prevTotals ); Totals deltaTotals = m_totals.delta( prevTotals );
@ -113,7 +117,7 @@ namespace Catch {
aborting() ) ); aborting() ) );
m_activeTestCase = CATCH_NULL; m_activeTestCase = CATCH_NULL;
m_testCaseTracker.reset(); m_testCaseTracker = CATCH_NULL;
return deltaTotals; return deltaTotals;
} }
@ -149,8 +153,10 @@ namespace Catch {
std::ostringstream oss; std::ostringstream oss;
oss << sectionInfo.name << "@" << sectionInfo.lineInfo; oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
if( !m_testCaseTracker->enterSection( oss.str() ) ) ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, oss.str() );
if( !sectionTracker.isOpen() )
return false; return false;
m_activeSections.push_back( &sectionTracker );
m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
@ -161,9 +167,11 @@ namespace Catch {
return true; return true;
} }
bool testForMissingAssertions( Counts& assertions ) { bool testForMissingAssertions( Counts& assertions ) {
if( assertions.total() != 0 || if( assertions.total() != 0 )
!m_config->warnAboutMissingAssertions() || return false;
m_testCaseTracker->currentSectionHasChildren() ) if( m_config->warnAboutMissingAssertions() )
return false;
if( m_trackerContext.currentTracker().hasChildren() )
return false; return false;
m_totals.assertions.failed++; m_totals.assertions.failed++;
assertions.failed++; assertions.failed++;
@ -174,13 +182,22 @@ namespace Catch {
Counts assertions = m_totals.assertions - endInfo.prevAssertions; Counts assertions = m_totals.assertions - endInfo.prevAssertions;
bool missingAssertions = testForMissingAssertions( assertions ); bool missingAssertions = testForMissingAssertions( assertions );
m_testCaseTracker->leaveSection(); if( !m_activeSections.empty() ) {
m_activeSections.back()->close();
m_activeSections.pop_back();
}
m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) ); m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
m_messages.clear(); m_messages.clear();
} }
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) { virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
if( m_unfinishedSections.empty() )
m_activeSections.back()->fail();
else
m_activeSections.back()->close();
m_activeSections.pop_back();
m_unfinishedSections.push_back( endInfo ); m_unfinishedSections.push_back( endInfo );
} }
@ -249,7 +266,7 @@ namespace Catch {
double duration = 0; double duration = 0;
try { try {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
TestCaseTracker::Guard guard( *m_testCaseTracker ); // TestCaseTracker::Guard guard( *m_testCaseTracker );
seedRng( *m_config ); seedRng( *m_config );
@ -267,10 +284,13 @@ namespace Catch {
} }
catch( TestFailureException& ) { catch( TestFailureException& ) {
// This just means the test was aborted due to failure // This just means the test was aborted due to failure
// m_testCaseTracker->fail();
} }
catch(...) { catch(...) {
makeUnexpectedResultBuilder().useActiveException(); makeUnexpectedResultBuilder().useActiveException();
// m_testCaseTracker->fail();
} }
m_testCaseTracker->close();
handleUnfinishedSections(); handleUnfinishedSections();
m_messages.clear(); m_messages.clear();
@ -316,7 +336,8 @@ namespace Catch {
TestRunInfo m_runInfo; TestRunInfo m_runInfo;
IMutableContext& m_context; IMutableContext& m_context;
TestCase const* m_activeTestCase; TestCase const* m_activeTestCase;
Option<TestCaseTracker> m_testCaseTracker; ITracker* m_testCaseTracker;
ITracker* m_currentSectionTracker;
AssertionResult m_lastResult; AssertionResult m_lastResult;
Ptr<IConfig const> m_config; Ptr<IConfig const> m_config;
@ -325,6 +346,8 @@ namespace Catch {
std::vector<MessageInfo> m_messages; std::vector<MessageInfo> m_messages;
AssertionInfo m_lastAssertionInfo; AssertionInfo m_lastAssertionInfo;
std::vector<SectionEndInfo> m_unfinishedSections; std::vector<SectionEndInfo> m_unfinishedSections;
std::vector<ITracker*> m_activeSections;
TrackerContext m_trackerContext;
}; };
IResultCapture& getResultCapture() { IResultCapture& getResultCapture() {

View File

@ -29,6 +29,7 @@ namespace TestCaseTracking {
virtual bool isComplete() const = 0; // Successfully completed or failed virtual bool isComplete() const = 0; // Successfully completed or failed
virtual bool isSuccessfullyCompleted() const = 0; virtual bool isSuccessfullyCompleted() const = 0;
virtual bool isOpen() const = 0; // Started but not complete virtual bool isOpen() const = 0; // Started but not complete
virtual bool hasChildren() const = 0;
virtual ITracker& parent() = 0; virtual ITracker& parent() = 0;
@ -139,6 +140,9 @@ namespace TestCaseTracking {
virtual bool isOpen() const CATCH_OVERRIDE { virtual bool isOpen() const CATCH_OVERRIDE {
return m_runState != NotStarted && !isComplete(); return m_runState != NotStarted && !isComplete();
} }
virtual bool hasChildren() const CATCH_OVERRIDE {
return !m_children.empty();
}
virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE { virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {