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
{
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 ),
lineInfo( _lineInfo ),
capturedExpression( _capturedExpression )

View File

@ -95,7 +95,6 @@ inline bool isTrue( bool value ){ return value; }
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, 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 ) \

View File

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

View File

@ -35,7 +35,6 @@ namespace Catch {
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 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 std::string getCurrentTestName() const = 0;

View File

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