AssertionInfo captures more info (for test cases and sections)

This commit is contained in:
Phil Nash 2012-11-04 21:09:22 +00:00
parent a4e088c999
commit 81cb69ef18
5 changed files with 21 additions and 30 deletions

View File

@ -16,7 +16,7 @@ namespace Catch {
struct AssertionInfo struct AssertionInfo
{ {
AssertionInfo() {} AssertionInfo() {}
AssertionInfo( const std::string& _macroName, const SourceLineInfo& _lineInfo, const std::string& _capturedExpression, bool _shouldNegate ) AssertionInfo( const std::string& _macroName, const SourceLineInfo& _lineInfo, const std::string& _capturedExpression = "", bool _shouldNegate = false )
: macroName( _macroName ), : macroName( _macroName ),
lineInfo( _lineInfo ), lineInfo( _lineInfo ),
capturedExpression( _capturedExpression ) capturedExpression( _capturedExpression )

View File

@ -95,7 +95,6 @@ inline bool isTrue( bool value ){ return value; }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, shouldNegate ) \ #define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, shouldNegate ) \
Catch::AssertionInfo INTERNAL_CATCH_ASSERTIONINFO_NAME( macroName, CATCH_INTERNAL_LINEINFO, expr, shouldNegate ); Catch::AssertionInfo INTERNAL_CATCH_ASSERTIONINFO_NAME( macroName, CATCH_INTERNAL_LINEINFO, expr, shouldNegate );
// !TBD Catch::getResultCapture().acceptAssertionInfo( INTERNAL_CATCH_ASSERTIONINFO_NAME )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ) \ #define INTERNAL_CATCH_TEST( expr, shouldNegate, stopOnFailure, macroName ) \

View File

@ -94,7 +94,7 @@ namespace Catch {
friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) { friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) {
os << pluraliser.m_count << " " << pluraliser.m_label; os << pluraliser.m_count << " " << pluraliser.m_label;
if( pluraliser.m_count != 1 ) if( pluraliser.m_count != 1 )
os << "s"; os << "s";
return os; return os;
} }
@ -113,10 +113,6 @@ namespace Catch {
: file( other.file ), : file( other.file ),
line( other.line ) line( other.line )
{} {}
void swap( SourceLineInfo& other ){
file.swap( other.file );
std::swap( line, other.line );
}
bool empty() const { bool empty() const {
return file.empty(); return file.empty();
} }

View File

@ -35,7 +35,6 @@ namespace Catch {
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
virtual bool shouldDebugBreak() const = 0; virtual bool shouldDebugBreak() const = 0;
virtual void acceptAssertionInfo( const AssertionInfo& assertionInfo ) = 0;
virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0; virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0;
virtual std::string getCurrentTestName() const = 0; virtual std::string getCurrentTestName() const = 0;

View File

@ -46,7 +46,7 @@ namespace Catch {
std::ostringstream m_oss; std::ostringstream m_oss;
std::string& m_targetString; std::string& m_targetString;
}; };
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
class Runner : public IResultCapture, public IRunner { class Runner : public IResultCapture, public IRunner {
@ -109,7 +109,6 @@ namespace Catch {
do { do {
do { do {
m_assertionInfo.lineInfo = m_runningTest->getTestCaseInfo().getLineInfo();
runCurrentTest( redirectedCout, redirectedCerr ); runCurrentTest( redirectedCout, redirectedCerr );
} }
while( m_runningTest->hasUntestedSections() && !aborting() ); while( m_runningTest->hasUntestedSections() && !aborting() );
@ -131,14 +130,9 @@ namespace Catch {
private: // IResultCapture private: // IResultCapture
virtual void acceptAssertionInfo( const AssertionInfo& assertionInfo ) {
m_assertionInfo = assertionInfo;
}
virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) { virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) {
m_assertionInfo = assertionInfo; m_lastAssertionInfo = assertionInfo;
m_currentResult = assertionResult; return actOnCurrentResult( assertionResult.buildResult( assertionInfo ) );
return actOnCurrentResult();
} }
virtual void testEnded( const AssertionResult& result ) { virtual void testEnded( const AssertionResult& result ) {
@ -152,7 +146,7 @@ namespace Catch {
std::vector<ScopedInfo*>::const_iterator it = m_scopedInfos.begin(); std::vector<ScopedInfo*>::const_iterator it = m_scopedInfos.begin();
std::vector<ScopedInfo*>::const_iterator itEnd = m_scopedInfos.end(); std::vector<ScopedInfo*>::const_iterator itEnd = m_scopedInfos.end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it )
m_reporter->Result( (*it)->buildResult( m_assertionInfo ) ); m_reporter->Result( (*it)->buildResult( m_lastAssertionInfo ) );
} }
{ {
std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin(); std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin();
@ -179,10 +173,14 @@ namespace Catch {
std::ostringstream oss; std::ostringstream oss;
oss << name << "@" << lineInfo; oss << name << "@" << lineInfo;
m_assertionInfoStack.push_back( m_lastAssertionInfo );
m_lastAssertionInfo = AssertionInfo( "SECTION", lineInfo );
if( !m_runningTest->addSection( oss.str() ) ) if( !m_runningTest->addSection( oss.str() ) )
return false; return false;
m_assertionInfo.lineInfo = lineInfo;
m_reporter->StartSection( name, description ); m_reporter->StartSection( name, description );
assertions = m_totals.assertions; assertions = m_totals.assertions;
@ -200,6 +198,8 @@ namespace Catch {
} }
m_runningTest->endSection( name ); m_runningTest->endSection( name );
m_reporter->EndSection( name, assertions ); m_reporter->EndSection( name, assertions );
m_lastAssertionInfo = m_assertionInfoStack.back();
m_assertionInfoStack.pop_back();
} }
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) { virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
@ -233,13 +233,10 @@ namespace Catch {
private: private:
ResultAction::Value actOnCurrentResult() { ResultAction::Value actOnCurrentResult( const AssertionResult& result ) {
m_lastResult = m_currentResult.buildResult( m_assertionInfo ); m_lastResult = result;
testEnded( m_lastResult ); testEnded( m_lastResult );
m_currentResult = ExpressionResultBuilder();
m_assertionInfo = AssertionInfo();
ResultAction::Value action = ResultAction::None; ResultAction::Value action = ResultAction::None;
if( !m_lastResult.ok() ) { if( !m_lastResult.ok() ) {
@ -254,6 +251,7 @@ namespace Catch {
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) { void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
try { try {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCaseInfo().getLineInfo() );
m_runningTest->reset(); m_runningTest->reset();
Counts prevAssertions = m_totals.assertions; Counts prevAssertions = m_totals.assertions;
if( m_reporter->shouldRedirectStdout() ) { if( m_reporter->shouldRedirectStdout() ) {
@ -277,10 +275,9 @@ namespace Catch {
// This just means the test was aborted due to failure // This just means the test was aborted due to failure
} }
catch(...) { catch(...) {
m_currentResult ExpressionResultBuilder exResult( ResultWas::ThrewException );
.setResultType( ResultWas::ThrewException ) exResult << translateActiveException();
<< translateActiveException(); actOnCurrentResult( exResult.buildResult( m_lastAssertionInfo ) );
actOnCurrentResult();
} }
m_assertionResults.clear(); m_assertionResults.clear();
} }
@ -288,7 +285,6 @@ namespace Catch {
private: private:
IMutableContext& m_context; IMutableContext& m_context;
RunningTest* m_runningTest; RunningTest* m_runningTest;
ExpressionResultBuilder m_currentResult;
AssertionResult m_lastResult; AssertionResult m_lastResult;
const Config& m_config; const Config& m_config;
@ -299,7 +295,8 @@ namespace Catch {
IRunner* m_prevRunner; IRunner* m_prevRunner;
IResultCapture* m_prevResultCapture; IResultCapture* m_prevResultCapture;
const IConfig* m_prevConfig; const IConfig* m_prevConfig;
AssertionInfo m_assertionInfo; AssertionInfo m_lastAssertionInfo;
std::vector<AssertionInfo> m_assertionInfoStack;
}; };
} // end namespace Catch } // end namespace Catch