Completed IStreamingInterface abstraction with TestRunInfo and GroupInfo

This commit is contained in:
Phil Nash 2012-12-01 23:49:57 +00:00
parent b56aaf4c36
commit 2632dca81d
3 changed files with 27 additions and 18 deletions

View File

@ -43,6 +43,15 @@ namespace Catch
bool shouldRedirectStdOut; bool shouldRedirectStdOut;
}; };
struct TestRunInfo {
TestRunInfo( std::string const& _name ) : name( _name ) {}
std::string name;
};
struct GroupInfo {
GroupInfo( std::string const& _name ) : name( _name ) {}
std::string name;
};
struct SectionInfo { struct SectionInfo {
SectionInfo( std::string const& _name, SectionInfo( std::string const& _name,
std::string const& _description, std::string const& _description,
@ -109,31 +118,31 @@ namespace Catch
}; };
struct TestGroupStats : SharedImpl<> { struct TestGroupStats : SharedImpl<> {
TestGroupStats( std::string const& _groupName, TestGroupStats( GroupInfo const& _groupInfo,
Totals const& _totals, Totals const& _totals,
bool _aborting ) bool _aborting )
: groupName( _groupName ), : groupInfo( _groupInfo ),
totals( _totals ), totals( _totals ),
aborting( _aborting ) aborting( _aborting )
{} {}
virtual ~TestGroupStats(); virtual ~TestGroupStats();
std::string groupName; GroupInfo groupInfo;
Totals totals; Totals totals;
bool aborting; bool aborting;
}; };
struct TestRunStats : SharedImpl<> { struct TestRunStats : SharedImpl<> {
TestRunStats( std::string const& _runName, TestRunStats( TestRunInfo const& _runInfo,
Totals const& _totals, Totals const& _totals,
bool _aborting ) bool _aborting )
: runName( _runName ), : runInfo( _runInfo ),
totals( _totals ), totals( _totals ),
aborting( _aborting ) aborting( _aborting )
{} {}
virtual ~TestRunStats(); virtual ~TestRunStats();
std::string runName; TestRunInfo runInfo;
Totals totals; Totals totals;
bool aborting; bool aborting;
}; };
@ -143,8 +152,8 @@ namespace Catch
virtual ~IStreamingReporter(); virtual ~IStreamingReporter();
virtual ReporterPreferences getPreferences() const = 0; virtual ReporterPreferences getPreferences() const = 0;
virtual void testRunStarting( std::string const& runName ) = 0; virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
virtual void testGroupStarting( std::string const& groupName ) = 0; virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
@ -199,11 +208,11 @@ namespace Catch
return prefs; return prefs;
} }
virtual void testRunStarting( std::string const& ) { virtual void testRunStarting( TestRunInfo const& ) {
m_legacyReporter->StartTesting(); m_legacyReporter->StartTesting();
} }
virtual void testGroupStarting( std::string const& groupName ) { virtual void testGroupStarting( GroupInfo const& groupInfo ) {
m_legacyReporter->StartGroup( groupName ); m_legacyReporter->StartGroup( groupInfo.name );
} }
virtual void testCaseStarting( TestCaseInfo const& testInfo ) { virtual void testCaseStarting( TestCaseInfo const& testInfo ) {
m_legacyReporter->StartTestCase( testInfo ); m_legacyReporter->StartTestCase( testInfo );
@ -235,7 +244,7 @@ namespace Catch
virtual void testGroupEnded( Ptr<TestGroupStats const> const& testGroupStats ) { virtual void testGroupEnded( Ptr<TestGroupStats const> 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->groupInfo.name, testGroupStats->totals );
} }
virtual void testRunEnded( Ptr<TestRunStats const> const& testRunStats ) { virtual void testRunEnded( Ptr<TestRunStats const> const& testRunStats ) {
m_legacyReporter->EndTesting( testRunStats->totals ); m_legacyReporter->EndTesting( testRunStats->totals );

View File

@ -68,11 +68,11 @@ namespace Catch {
m_context.setRunner( this ); m_context.setRunner( this );
m_context.setConfig( &m_config ); m_context.setConfig( &m_config );
m_context.setResultCapture( this ); m_context.setResultCapture( this );
m_reporter->testRunStarting( "" ); // !TBD - name m_reporter->testRunStarting( TestRunInfo( "" ) ); // !TBD - name
} }
virtual ~Runner() { virtual ~Runner() {
m_reporter->testRunEnded( new TestRunStats( "", m_totals, aborting() ) ); // !TBD - name m_reporter->testRunEnded( new TestRunStats( TestRunInfo( "" ), 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 );
@ -80,10 +80,10 @@ namespace Catch {
} }
void testGroupStarting( std::string const& testSpec ) { void testGroupStarting( std::string const& testSpec ) {
m_reporter->testGroupStarting( testSpec ); m_reporter->testGroupStarting( GroupInfo( testSpec ) );
} }
void testGroupEnded( std::string const& testSpec, Totals const& totals ) { void testGroupEnded( std::string const& testSpec, Totals const& totals ) {
m_reporter->testGroupEnded( new TestGroupStats( testSpec, totals, aborting() ) ); m_reporter->testGroupEnded( new TestGroupStats( GroupInfo( testSpec ), totals, aborting() ) );
} }
Totals runMatching( const std::string& testSpec ) { Totals runMatching( const std::string& testSpec ) {

View File

@ -35,8 +35,8 @@ namespace Catch {
return ReporterPreferences(); return ReporterPreferences();
} }
virtual void testRunStarting( std::string const& ) {} virtual void testRunStarting( TestRunInfo const& ) {}
virtual void testGroupStarting( std::string const& ) {} virtual void testGroupStarting( GroupInfo const& ) {}
virtual void testCaseStarting( TestCaseInfo const& ) {} virtual void testCaseStarting( TestCaseInfo const& ) {}
virtual void sectionStarting( SectionInfo const& ) {} virtual void sectionStarting( SectionInfo const& ) {}
virtual void assertionStarting( AssertionInfo const& ) {} virtual void assertionStarting( AssertionInfo const& ) {}