SectionInfo now goes via new streaming reporter interface

This commit is contained in:
Phil Nash 2012-11-30 08:58:46 +00:00
parent 95df676a27
commit ad6701d222
5 changed files with 59 additions and 41 deletions

View File

@ -50,7 +50,7 @@ namespace Catch {
for(; it != itEnd && !context.aborting(); ++it ) { for(; it != itEnd && !context.aborting(); ++it ) {
reporter.testGroupStarting( it->getName() ); reporter.testGroupStarting( it->getName() );
totals += runTestsForGroup( context, *it ); totals += runTestsForGroup( context, *it );
reporter.testGroupEnding( TestGroupStats( it->getName(), totals, context.aborting() ) ); reporter.testGroupEnded( TestGroupStats( it->getName(), totals, context.aborting() ) );
} }
return totals; return totals;
} }

View File

@ -20,22 +20,21 @@ namespace Catch {
class ExpressionResultBuilder; class ExpressionResultBuilder;
class AssertionResult; class AssertionResult;
struct AssertionInfo; struct AssertionInfo;
struct SectionInfo;
struct IResultCapture { struct IResultCapture {
virtual ~IResultCapture(); virtual ~IResultCapture();
virtual void testEnded( const AssertionResult& result ) = 0; virtual void testEnded( AssertionResult const& result ) = 0;
virtual bool sectionStarted( const std::string& name, virtual bool sectionStarted( SectionInfo const& sectionInfo,
const std::string& description,
const SourceLineInfo& lineInfo,
Counts& assertions ) = 0; Counts& assertions ) = 0;
virtual void sectionEnded( const std::string& name, const Counts& assertions ) = 0; virtual void sectionEnded( SectionInfo const& name, Counts const& assertions ) = 0;
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0;
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
virtual bool shouldDebugBreak() const = 0; virtual bool shouldDebugBreak() const = 0;
virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0; virtual ResultAction::Value acceptExpression( ExpressionResultBuilder const& assertionResult, AssertionInfo const& assertionInfo ) = 0;
virtual std::string getCurrentTestName() const = 0; virtual std::string getCurrentTestName() const = 0;
virtual const AssertionResult* getLastResult() const = 0; virtual const AssertionResult* getLastResult() const = 0;

View File

@ -49,12 +49,12 @@ namespace Catch
SourceLineInfo const& _lineInfo ) SourceLineInfo const& _lineInfo )
: name( _name ), : name( _name ),
description( _description ), description( _description ),
sourceLineInfo( _lineInfo ) lineInfo( _lineInfo )
{} {}
std::string name; std::string name;
std::string description; std::string description;
SourceLineInfo sourceLineInfo; SourceLineInfo lineInfo;
}; };
struct AssertionStats { struct AssertionStats {
@ -70,8 +70,17 @@ namespace Catch
}; };
struct SectionStats { struct SectionStats {
SectionStats( SectionInfo const& _sectionInfo,
Counts const& _assertions,
bool _missingAssertions )
: sectionInfo( _sectionInfo ),
assertions( _assertions ),
missingAssertions( _missingAssertions )
{}
SectionInfo sectionInfo; SectionInfo sectionInfo;
Totals totals; Counts assertions;
bool missingAssertions;
}; };
struct TestCaseStats { struct TestCaseStats {
@ -133,14 +142,16 @@ namespace Catch
virtual void testRunStarting( std::string const& runName ) = 0; virtual void testRunStarting( std::string const& runName ) = 0;
virtual void testGroupStarting( std::string const& groupName ) = 0; virtual void testGroupStarting( std::string const& groupName ) = 0;
// !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
virtual void assertionEnding( AssertionStats const& assertionStats ) = 0; virtual void assertionEnded( AssertionStats const& assertionStats ) = 0;
virtual void testCaseEnding( TestCaseStats const& testCaseStats ) = 0; virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
virtual void testGroupEnding( TestGroupStats const& testGroupStats ) = 0; virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
virtual void testRunEnding( TestRunStats const& testRunStats ) = 0; virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
}; };
// !TBD: Derived helper that implements the streaming interface but holds the stats // !TBD: Derived helper that implements the streaming interface but holds the stats
// - declares a new interface where methods are called at the end of each event // - declares a new interface where methods are called at the end of each event
@ -204,24 +215,32 @@ namespace Catch
virtual void testCaseStarting( TestCaseInfo const& testInfo ) { virtual void testCaseStarting( TestCaseInfo const& testInfo ) {
m_legacyReporter->StartTestCase( testInfo ); m_legacyReporter->StartTestCase( testInfo );
} }
virtual void sectionStarting( SectionInfo const& sectionInfo ) {
m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
}
virtual void assertionStarting( AssertionInfo const& ) { virtual void assertionStarting( AssertionInfo const& ) {
// Not on legacy interface // Not on legacy interface
} }
virtual void assertionEnding( AssertionStats const& assertionStats ) { virtual void assertionEnded( AssertionStats const& assertionStats ) {
m_legacyReporter->Result( assertionStats.assertionResult ); m_legacyReporter->Result( assertionStats.assertionResult );
} }
virtual void testCaseEnding( TestCaseStats const& testCaseStats ) { virtual void sectionEnded( SectionStats const& sectionStats ) {
if( sectionStats.missingAssertions )
m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
}
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) {
if( testCaseStats.missingAssertions ) if( testCaseStats.missingAssertions )
m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name ); m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name );
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr ); m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
} }
virtual void testGroupEnding( TestGroupStats const& testGroupStats ) { virtual void testGroupEnded( TestGroupStats const& testGroupStats ) {
if( testGroupStats.aborting ) if( testGroupStats.aborting )
m_legacyReporter->Aborted(); m_legacyReporter->Aborted();
m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals ); m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals );
} }
virtual void testRunEnding( TestRunStats const& testRunStats ) { virtual void testRunEnded( TestRunStats const& testRunStats ) {
m_legacyReporter->EndTesting( testRunStats.totals ); m_legacyReporter->EndTesting( testRunStats.totals );
} }

View File

@ -72,7 +72,7 @@ namespace Catch {
} }
virtual ~Runner() { virtual ~Runner() {
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnding( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnded( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name
m_context.setRunner( m_prevRunner ); m_context.setRunner( m_prevRunner );
m_context.setConfig( NULL ); m_context.setConfig( NULL );
m_context.setResultCapture( m_prevResultCapture ); m_context.setResultCapture( m_prevResultCapture );
@ -94,7 +94,7 @@ namespace Catch {
for(; it != itEnd; ++it ) for(; it != itEnd; ++it )
totals += runTest( *it ); totals += runTest( *it );
reporter.testGroupEnding( TestGroupStats( testSpec, totals, aborting() ) ); reporter.testGroupEnded( TestGroupStats( testSpec, totals, aborting() ) );
return totals; return totals;
} }
@ -131,7 +131,7 @@ namespace Catch {
m_totals.testCases += deltaTotals.testCases; m_totals.testCases += deltaTotals.testCases;
TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() ); TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() );
reporter.testCaseEnding( stats ); reporter.testCaseEnded( stats );
delete m_runningTest; delete m_runningTest;
@ -163,13 +163,13 @@ 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 )
reporter.assertionEnding( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); reporter.assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) );
} }
{ {
std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin(); std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin();
std::vector<AssertionResult>::const_iterator itEnd = m_assertionResults.end(); std::vector<AssertionResult>::const_iterator itEnd = m_assertionResults.end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it )
reporter.assertionEnding( AssertionStats( *it, m_totals ) ); reporter.assertionEnded( AssertionStats( *it, m_totals ) );
} }
m_assertionResults.clear(); m_assertionResults.clear();
} }
@ -180,49 +180,48 @@ namespace Catch {
m_totals.assertions.info++; m_totals.assertions.info++;
} }
else else
reporter.assertionEnding( AssertionStats( result, m_totals ) ); reporter.assertionEnded( AssertionStats( result, m_totals ) );
// Reset AssertionInfo // Reset AssertionInfo
m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after this line}" , m_lastAssertionInfo.resultDisposition ); m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after this line}" , m_lastAssertionInfo.resultDisposition );
} }
virtual bool sectionStarted ( virtual bool sectionStarted (
const std::string& name, SectionInfo const& sectionInfo,
const std::string& description,
const SourceLineInfo& lineInfo,
Counts& assertions Counts& assertions
) )
{ {
std::ostringstream oss; std::ostringstream oss;
oss << name << "@" << lineInfo; oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
if( !m_runningTest->addSection( oss.str() ) ) if( !m_runningTest->addSection( oss.str() ) )
return false; return false;
m_lastAssertionInfo.lineInfo = lineInfo; m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
// !TBD: ------------ LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionStarting( sectionInfo );
std::string className = m_runningTest->getTestCase().getTestCaseInfo().className;
TestCaseInfo sectionInfo( name, className, description, std::set<std::string>(), false, lineInfo );
m_reporter->StartSection( name, description );
assertions = m_totals.assertions; assertions = m_totals.assertions;
return true; return true;
} }
virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) { virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions ) {
Counts assertions = m_totals.assertions - prevAssertions; Counts assertions = m_totals.assertions - prevAssertions;
bool missingAssertions = false;
if( assertions.total() == 0 && if( assertions.total() == 0 &&
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) && ( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
!m_runningTest->isBranchSection() ) { !m_runningTest->isBranchSection() ) {
m_reporter->NoAssertionsInSection( name );
m_totals.assertions.failed++; m_totals.assertions.failed++;
assertions.failed++; assertions.failed++;
missingAssertions = true;
} }
m_runningTest->endSection( name ); m_runningTest->endSection( info.name );
m_reporter->EndSection( name, assertions );
SectionStats stats( info, assertions, missingAssertions );
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionEnded( stats );
} }
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) { virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {

View File

@ -20,13 +20,13 @@ namespace Catch {
Section( const std::string& name, Section( const std::string& name,
const std::string& description, const std::string& description,
const SourceLineInfo& lineInfo ) const SourceLineInfo& lineInfo )
: m_name( name ), : m_info( name, description, lineInfo ),
m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) ) m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( m_info, m_assertions ) )
{} {}
~Section() { ~Section() {
if( m_sectionIncluded ) if( m_sectionIncluded )
getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions ); getCurrentContext().getResultCapture().sectionEnded( m_info, m_assertions );
} }
// This indicates whether the section should be executed or not // This indicates whether the section should be executed or not
@ -35,6 +35,7 @@ namespace Catch {
} }
private: private:
SectionInfo m_info;
std::string m_name; std::string m_name;
Counts m_assertions; Counts m_assertions;