mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Do uncaught_exception checking before calling sectionEnded
- split the uncaught handling (adding to unfinishedSections) into separate method
This commit is contained in:
parent
d234ed1a67
commit
166ca2e819
@ -18,6 +18,7 @@ namespace Catch {
|
|||||||
class AssertionResult;
|
class AssertionResult;
|
||||||
struct AssertionInfo;
|
struct AssertionInfo;
|
||||||
struct SectionInfo;
|
struct SectionInfo;
|
||||||
|
struct SectionEndInfo;
|
||||||
struct MessageInfo;
|
struct MessageInfo;
|
||||||
class ScopedMessageBuilder;
|
class ScopedMessageBuilder;
|
||||||
struct Counts;
|
struct Counts;
|
||||||
@ -29,7 +30,8 @@ namespace Catch {
|
|||||||
virtual void assertionEnded( AssertionResult const& result ) = 0;
|
virtual void assertionEnded( AssertionResult const& result ) = 0;
|
||||||
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
||||||
Counts& assertions ) = 0;
|
Counts& assertions ) = 0;
|
||||||
virtual void sectionEnded( SectionInfo const& name, Counts const& assertions, double _durationInSeconds ) = 0;
|
virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
|
||||||
|
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
|
||||||
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
|
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
|
||||||
virtual void popScopedMessage( MessageInfo const& message ) = 0;
|
virtual void popScopedMessage( MessageInfo const& message ) = 0;
|
||||||
|
|
||||||
|
@ -176,22 +176,21 @@ namespace Catch {
|
|||||||
assertions.failed++;
|
assertions.failed++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions, double _durationInSeconds ) {
|
virtual void sectionEnded( SectionEndInfo const& endInfo ) {
|
||||||
if( std::uncaught_exception() ) {
|
Counts assertions = m_totals.assertions - endInfo.prevAssertions;
|
||||||
m_unfinishedSections.push_back( UnfinishedSections( info, prevAssertions, _durationInSeconds ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Counts assertions = m_totals.assertions - prevAssertions;
|
|
||||||
bool missingAssertions = testForMissingAssertions( assertions );
|
bool missingAssertions = testForMissingAssertions( assertions );
|
||||||
|
|
||||||
m_testCaseTracker->leaveSection();
|
m_testCaseTracker->leaveSection();
|
||||||
|
|
||||||
m_reporter->sectionEnded( SectionStats( info, assertions, _durationInSeconds, missingAssertions ) );
|
m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
|
||||||
m_messages.clear();
|
m_messages.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
|
||||||
|
m_unfinishedSections.push_back( endInfo );
|
||||||
|
}
|
||||||
|
|
||||||
virtual void pushScopedMessage( MessageInfo const& message ) {
|
virtual void pushScopedMessage( MessageInfo const& message ) {
|
||||||
m_messages.push_back( message );
|
m_messages.push_back( message );
|
||||||
}
|
}
|
||||||
@ -309,28 +308,18 @@ namespace Catch {
|
|||||||
m_lastAssertionInfo.capturedExpression.c_str(),
|
m_lastAssertionInfo.capturedExpression.c_str(),
|
||||||
m_lastAssertionInfo.resultDisposition );
|
m_lastAssertionInfo.resultDisposition );
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleUnfinishedSections() {
|
void handleUnfinishedSections() {
|
||||||
// If sections ended prematurely due to an exception we stored their
|
// If sections ended prematurely due to an exception we stored their
|
||||||
// infos here so we can tear them down outside the unwind process.
|
// infos here so we can tear them down outside the unwind process.
|
||||||
for( std::vector<UnfinishedSections>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
|
for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
|
||||||
itEnd = m_unfinishedSections.rend();
|
itEnd = m_unfinishedSections.rend();
|
||||||
it != itEnd;
|
it != itEnd;
|
||||||
++it )
|
++it )
|
||||||
sectionEnded( it->info, it->prevAssertions, it->durationInSeconds );
|
sectionEnded( *it );
|
||||||
m_unfinishedSections.clear();
|
m_unfinishedSections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UnfinishedSections {
|
|
||||||
UnfinishedSections( SectionInfo const& _info, Counts const& _prevAssertions, double _durationInSeconds )
|
|
||||||
: info( _info ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
|
|
||||||
{}
|
|
||||||
|
|
||||||
SectionInfo info;
|
|
||||||
Counts prevAssertions;
|
|
||||||
double durationInSeconds;
|
|
||||||
};
|
|
||||||
|
|
||||||
TestRunInfo m_runInfo;
|
TestRunInfo m_runInfo;
|
||||||
IMutableContext& m_context;
|
IMutableContext& m_context;
|
||||||
TestCase const* m_activeTestCase;
|
TestCase const* m_activeTestCase;
|
||||||
@ -345,7 +334,7 @@ namespace Catch {
|
|||||||
IResultCapture* m_prevResultCapture;
|
IResultCapture* m_prevResultCapture;
|
||||||
Ptr<IConfig const> m_prevConfig;
|
Ptr<IConfig const> m_prevConfig;
|
||||||
AssertionInfo m_lastAssertionInfo;
|
AssertionInfo m_lastAssertionInfo;
|
||||||
std::vector<UnfinishedSections> m_unfinishedSections;
|
std::vector<SectionEndInfo> m_unfinishedSections;
|
||||||
};
|
};
|
||||||
|
|
||||||
IResultCapture& getResultCapture() {
|
IResultCapture& getResultCapture() {
|
||||||
|
@ -32,8 +32,13 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Section::~Section() {
|
Section::~Section() {
|
||||||
if( m_sectionIncluded )
|
if( m_sectionIncluded ) {
|
||||||
getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
||||||
|
if( std::uncaught_exception() )
|
||||||
|
getResultCapture().sectionEndedEarly( endInfo );
|
||||||
|
else
|
||||||
|
getResultCapture().sectionEnded( endInfo );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This indicates whether the section should be executed or not
|
// This indicates whether the section should be executed or not
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
|
#include "catch_totals.hpp"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -22,7 +23,17 @@ namespace Catch {
|
|||||||
std::string description;
|
std::string description;
|
||||||
SourceLineInfo lineInfo;
|
SourceLineInfo lineInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SectionEndInfo {
|
||||||
|
SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
|
||||||
|
: sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
|
||||||
|
{}
|
||||||
|
|
||||||
|
SectionInfo sectionInfo;
|
||||||
|
Counts prevAssertions;
|
||||||
|
double durationInSeconds;
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user