Reporter "stats" objects passed in by Ptr

This commit is contained in:
Phil Nash 2012-11-30 18:54:06 +00:00
parent f4774d9642
commit 7f04b56738
4 changed files with 70 additions and 81 deletions

View File

@ -49,7 +49,12 @@ namespace Catch {
IReporterRegistry::~IReporterRegistry() {} IReporterRegistry::~IReporterRegistry() {}
IStreamingReporter::~IStreamingReporter() {} IStreamingReporter::~IStreamingReporter() {}
LegacyReporterAdapter::~LegacyReporterAdapter() {} LegacyReporterAdapter::~LegacyReporterAdapter() {}
AssertionStats::~AssertionStats() {}
SectionStats::~SectionStats() {}
TestCaseStats::~TestCaseStats() {}
TestGroupStats::~TestGroupStats() {}
TestRunStats::~TestRunStats() {}
BasicReporter::~BasicReporter() {} BasicReporter::~BasicReporter() {}
IRunner::~IRunner() {} IRunner::~IRunner() {}
IMutableContext::~IMutableContext() {} IMutableContext::~IMutableContext() {}

View File

@ -57,19 +57,19 @@ namespace Catch
SourceLineInfo lineInfo; SourceLineInfo lineInfo;
}; };
struct AssertionStats { struct AssertionStats : SharedImpl<> {
AssertionStats( AssertionResult const& _assertionResult, AssertionStats( AssertionResult const& _assertionResult,
Totals const& _totals ) Totals const& _totals )
: assertionResult( _assertionResult ), : assertionResult( _assertionResult ),
totals( _totals ) totals( _totals )
{} {}
virtual ~AssertionStats();
// AssertionInfo assertionInfo; // !TBD: needed? It's in the result
AssertionResult assertionResult; AssertionResult assertionResult;
Totals totals; Totals totals;
}; };
struct SectionStats { struct SectionStats : SharedImpl<> {
SectionStats( SectionInfo const& _sectionInfo, SectionStats( SectionInfo const& _sectionInfo,
Counts const& _assertions, Counts const& _assertions,
bool _missingAssertions ) bool _missingAssertions )
@ -77,13 +77,14 @@ namespace Catch
assertions( _assertions ), assertions( _assertions ),
missingAssertions( _missingAssertions ) missingAssertions( _missingAssertions )
{} {}
virtual ~SectionStats();
SectionInfo sectionInfo; SectionInfo sectionInfo;
Counts assertions; Counts assertions;
bool missingAssertions; bool missingAssertions;
}; };
struct TestCaseStats { struct TestCaseStats : SharedImpl<> {
TestCaseStats( TestCaseInfo const& _testInfo, TestCaseStats( TestCaseInfo const& _testInfo,
Totals const& _totals, Totals const& _totals,
std::string const& _stdOut, std::string const& _stdOut,
@ -97,6 +98,7 @@ namespace Catch
missingAssertions( _missingAssertions ), missingAssertions( _missingAssertions ),
aborting( _aborting ) aborting( _aborting )
{} {}
virtual ~TestCaseStats();
TestCaseInfo testInfo; TestCaseInfo testInfo;
Totals totals; Totals totals;
@ -106,7 +108,7 @@ namespace Catch
bool aborting; bool aborting;
}; };
struct TestGroupStats { struct TestGroupStats : SharedImpl<> {
TestGroupStats( std::string const& _groupName, TestGroupStats( std::string const& _groupName,
Totals const& _totals, Totals const& _totals,
bool _aborting ) bool _aborting )
@ -114,13 +116,14 @@ namespace Catch
totals( _totals ), totals( _totals ),
aborting( _aborting ) aborting( _aborting )
{} {}
virtual ~TestGroupStats();
std::string groupName; std::string groupName;
Totals totals; Totals totals;
bool aborting; bool aborting;
}; };
struct TestRunStats { struct TestRunStats : SharedImpl<> {
TestRunStats( std::string const& _runName, TestRunStats( std::string const& _runName,
Totals const& _totals, Totals const& _totals,
bool _aborting ) bool _aborting )
@ -128,6 +131,7 @@ namespace Catch
totals( _totals ), totals( _totals ),
aborting( _aborting ) aborting( _aborting )
{} {}
virtual ~TestRunStats();
std::string runName; std::string runName;
Totals totals; Totals totals;
@ -147,11 +151,11 @@ namespace Catch
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
virtual void assertionEnded( AssertionStats const& assertionStats ) = 0; virtual void assertionEnded( Ptr<AssertionStats const> const& assertionStats ) = 0;
virtual void sectionEnded( SectionStats const& sectionStats ) = 0; virtual void sectionEnded( Ptr<SectionStats const> const& sectionStats ) = 0;
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; virtual void testCaseEnded( Ptr<TestCaseStats const> const& testCaseStats ) = 0;
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; virtual void testGroupEnded( Ptr<TestGroupStats const> const& testGroupStats ) = 0;
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; virtual void testRunEnded( Ptr<TestRunStats const> 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
@ -160,34 +164,23 @@ namespace Catch
// as it goes // as it goes
// Deprecated
struct IReporter : IShared { struct IReporter : IShared {
virtual ~IReporter(); virtual ~IReporter();
virtual bool shouldRedirectStdout() const = 0; virtual bool shouldRedirectStdout() const = 0;
virtual void StartTesting() = 0; virtual void StartTesting() = 0;
virtual void EndTesting( Totals const& totals ) = 0; virtual void EndTesting( Totals const& totals ) = 0;
virtual void StartGroup( std::string const& groupName ) = 0; virtual void StartGroup( std::string const& groupName ) = 0;
virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0; virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0; virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
// TestCaseResult
virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0; virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
// SectionInfo
virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0; virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
// Section Result
virtual void EndSection( std::string const& sectionName, const Counts& assertions ) = 0; virtual void EndSection( std::string const& sectionName, const Counts& assertions ) = 0;
// - merge into SectionResult ?
virtual void NoAssertionsInSection( std::string const& sectionName ) = 0; virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
virtual void NoAssertionsInTestCase( std::string const& testName ) = 0; virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
// - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
virtual void Aborted() = 0; virtual void Aborted() = 0;
// AssertionReslt
virtual void Result( const AssertionResult& result ) = 0; virtual void Result( const AssertionResult& result ) = 0;
}; };
@ -222,26 +215,30 @@ namespace Catch
// Not on legacy interface // Not on legacy interface
} }
virtual void assertionEnded( AssertionStats const& assertionStats ) { virtual void assertionEnded( Ptr<AssertionStats const> const& assertionStats ) {
m_legacyReporter->Result( assertionStats.assertionResult ); m_legacyReporter->Result( assertionStats->assertionResult );
} }
virtual void sectionEnded( SectionStats const& sectionStats ) { virtual void sectionEnded( Ptr<SectionStats const> const& sectionStats ) {
if( sectionStats.missingAssertions ) if( sectionStats->missingAssertions )
m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); m_legacyReporter->NoAssertionsInSection( sectionStats->sectionInfo.name );
m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); m_legacyReporter->EndSection( sectionStats->sectionInfo.name, sectionStats->assertions );
} }
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { virtual void testCaseEnded( Ptr<TestCaseStats const> 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 testGroupEnded( TestGroupStats 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->groupName, testGroupStats->totals );
} }
virtual void testRunEnded( TestRunStats const& testRunStats ) { virtual void testRunEnded( Ptr<TestRunStats const> const& testRunStats ) {
m_legacyReporter->EndTesting( testRunStats.totals ); m_legacyReporter->EndTesting( testRunStats->totals );
} }
private: private:

View File

@ -23,7 +23,7 @@ namespace Catch {
if( m_p ) if( m_p )
m_p->addRef(); m_p->addRef();
} }
Ptr( const Ptr& other ) : m_p( other.m_p ){ Ptr( Ptr const& other ) : m_p( other.m_p ){
if( m_p ) if( m_p )
m_p->addRef(); m_p->addRef();
} }
@ -36,33 +36,17 @@ namespace Catch {
swap( temp ); swap( temp );
return *this; return *this;
} }
Ptr& operator = ( const Ptr& other ){ Ptr& operator = ( Ptr const& other ){
Ptr temp( other ); Ptr temp( other );
swap( temp ); swap( temp );
return *this; return *this;
} }
void swap( Ptr& other ){ void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
std::swap( m_p, other.m_p ); T* get() { return m_p; }
} const T* get() const{ return m_p; }
T& operator*() const { return *m_p; }
T* get(){ T* operator->() const { return m_p; }
return m_p; bool operator !() const { return m_p == NULL; }
}
const T* get() const{
return m_p;
}
T& operator*() const {
return *m_p;
}
T* operator->() const {
return m_p;
}
bool operator !() const {
return m_p == NULL;
}
private: private:
T* m_p; T* m_p;
@ -70,24 +54,24 @@ namespace Catch {
struct IShared : NonCopyable { struct IShared : NonCopyable {
virtual ~IShared(); virtual ~IShared();
virtual void addRef() = 0; virtual void addRef() const = 0;
virtual void release() = 0; virtual void release() const = 0;
}; };
template<typename T> template<typename T = IShared>
struct SharedImpl : T { struct SharedImpl : T {
SharedImpl() : m_rc( 0 ){} SharedImpl() : m_rc( 0 ){}
virtual void addRef(){ virtual void addRef() const {
++m_rc; ++m_rc;
} }
virtual void release(){ virtual void release() const {
if( --m_rc == 0 ) if( --m_rc == 0 )
delete this; delete this;
} }
int m_rc; mutable unsigned int m_rc;
}; };
} // end namespace Catch } // end namespace Catch

View File

@ -72,7 +72,7 @@ namespace Catch {
} }
virtual ~Runner() { virtual ~Runner() {
m_reporter.testRunEnded( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name m_reporter.testRunEnded( new 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 );
@ -83,7 +83,7 @@ namespace Catch {
m_reporter.testGroupStarting( testSpec ); m_reporter.testGroupStarting( testSpec );
} }
void testGroupEnded( std::string const& testSpec, Totals const& totals ) { void testGroupEnded( std::string const& testSpec, Totals const& totals ) {
m_reporter.testGroupEnded( TestGroupStats( testSpec, totals, aborting() ) ); m_reporter.testGroupEnded( new TestGroupStats( testSpec, totals, aborting() ) );
} }
Totals runMatching( const std::string& testSpec ) { Totals runMatching( const std::string& testSpec ) {
@ -134,8 +134,12 @@ namespace Catch {
m_totals.testCases += deltaTotals.testCases; m_totals.testCases += deltaTotals.testCases;
TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() ); m_reporter.testCaseEnded( new TestCaseStats( testInfo,
m_reporter.testCaseEnded( stats ); deltaTotals,
redirectedCout,
redirectedCerr,
missingAssertions,
aborting() ) );
delete m_runningTest; delete m_runningTest;
@ -166,13 +170,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 )
m_reporter.assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); m_reporter.assertionEnded( new 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 )
m_reporter.assertionEnded( AssertionStats( *it, m_totals ) ); m_reporter.assertionEnded( new AssertionStats( *it, m_totals ) );
} }
m_assertionResults.clear(); m_assertionResults.clear();
} }
@ -183,7 +187,7 @@ namespace Catch {
m_totals.assertions.info++; m_totals.assertions.info++;
} }
else else
m_reporter.assertionEnded( AssertionStats( result, m_totals ) ); m_reporter.assertionEnded( new 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 );
@ -223,8 +227,7 @@ namespace Catch {
} }
m_runningTest->endSection( info.name ); m_runningTest->endSection( info.name );
SectionStats stats( info, assertions, missingAssertions ); m_reporter.sectionEnded( new SectionStats( info, assertions, missingAssertions ) );
m_reporter.sectionEnded( stats );
} }
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) { virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {