mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Reporter "stats" objects passed in by Ptr
This commit is contained in:
parent
f4774d9642
commit
7f04b56738
@ -49,7 +49,12 @@ namespace Catch {
|
||||
IReporterRegistry::~IReporterRegistry() {}
|
||||
IStreamingReporter::~IStreamingReporter() {}
|
||||
LegacyReporterAdapter::~LegacyReporterAdapter() {}
|
||||
|
||||
AssertionStats::~AssertionStats() {}
|
||||
SectionStats::~SectionStats() {}
|
||||
TestCaseStats::~TestCaseStats() {}
|
||||
TestGroupStats::~TestGroupStats() {}
|
||||
TestRunStats::~TestRunStats() {}
|
||||
|
||||
BasicReporter::~BasicReporter() {}
|
||||
IRunner::~IRunner() {}
|
||||
IMutableContext::~IMutableContext() {}
|
||||
|
@ -57,19 +57,19 @@ namespace Catch
|
||||
SourceLineInfo lineInfo;
|
||||
};
|
||||
|
||||
struct AssertionStats {
|
||||
struct AssertionStats : SharedImpl<> {
|
||||
AssertionStats( AssertionResult const& _assertionResult,
|
||||
Totals const& _totals )
|
||||
: assertionResult( _assertionResult ),
|
||||
totals( _totals )
|
||||
{}
|
||||
virtual ~AssertionStats();
|
||||
|
||||
// AssertionInfo assertionInfo; // !TBD: needed? It's in the result
|
||||
AssertionResult assertionResult;
|
||||
Totals totals;
|
||||
};
|
||||
|
||||
struct SectionStats {
|
||||
struct SectionStats : SharedImpl<> {
|
||||
SectionStats( SectionInfo const& _sectionInfo,
|
||||
Counts const& _assertions,
|
||||
bool _missingAssertions )
|
||||
@ -77,13 +77,14 @@ namespace Catch
|
||||
assertions( _assertions ),
|
||||
missingAssertions( _missingAssertions )
|
||||
{}
|
||||
|
||||
virtual ~SectionStats();
|
||||
|
||||
SectionInfo sectionInfo;
|
||||
Counts assertions;
|
||||
bool missingAssertions;
|
||||
};
|
||||
|
||||
struct TestCaseStats {
|
||||
struct TestCaseStats : SharedImpl<> {
|
||||
TestCaseStats( TestCaseInfo const& _testInfo,
|
||||
Totals const& _totals,
|
||||
std::string const& _stdOut,
|
||||
@ -97,6 +98,7 @@ namespace Catch
|
||||
missingAssertions( _missingAssertions ),
|
||||
aborting( _aborting )
|
||||
{}
|
||||
virtual ~TestCaseStats();
|
||||
|
||||
TestCaseInfo testInfo;
|
||||
Totals totals;
|
||||
@ -106,7 +108,7 @@ namespace Catch
|
||||
bool aborting;
|
||||
};
|
||||
|
||||
struct TestGroupStats {
|
||||
struct TestGroupStats : SharedImpl<> {
|
||||
TestGroupStats( std::string const& _groupName,
|
||||
Totals const& _totals,
|
||||
bool _aborting )
|
||||
@ -114,13 +116,14 @@ namespace Catch
|
||||
totals( _totals ),
|
||||
aborting( _aborting )
|
||||
{}
|
||||
virtual ~TestGroupStats();
|
||||
|
||||
std::string groupName;
|
||||
Totals totals;
|
||||
bool aborting;
|
||||
};
|
||||
|
||||
struct TestRunStats {
|
||||
struct TestRunStats : SharedImpl<> {
|
||||
TestRunStats( std::string const& _runName,
|
||||
Totals const& _totals,
|
||||
bool _aborting )
|
||||
@ -128,6 +131,7 @@ namespace Catch
|
||||
totals( _totals ),
|
||||
aborting( _aborting )
|
||||
{}
|
||||
virtual ~TestRunStats();
|
||||
|
||||
std::string runName;
|
||||
Totals totals;
|
||||
@ -147,11 +151,11 @@ namespace Catch
|
||||
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
||||
|
||||
virtual void assertionEnded( AssertionStats const& assertionStats ) = 0;
|
||||
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
|
||||
virtual void assertionEnded( Ptr<AssertionStats const> const& assertionStats ) = 0;
|
||||
virtual void sectionEnded( Ptr<SectionStats const> const& sectionStats ) = 0;
|
||||
virtual void testCaseEnded( Ptr<TestCaseStats const> const& testCaseStats ) = 0;
|
||||
virtual void testGroupEnded( Ptr<TestGroupStats const> const& testGroupStats ) = 0;
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& testRunStats ) = 0;
|
||||
};
|
||||
// !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
|
||||
@ -160,34 +164,23 @@ namespace Catch
|
||||
// as it goes
|
||||
|
||||
|
||||
// Deprecated
|
||||
struct IReporter : IShared {
|
||||
virtual ~IReporter();
|
||||
|
||||
virtual bool shouldRedirectStdout() const = 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 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;
|
||||
// TestCaseResult
|
||||
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;
|
||||
// Section Result
|
||||
virtual void EndSection( std::string const& sectionName, const Counts& assertions ) = 0;
|
||||
|
||||
// - merge into SectionResult ?
|
||||
virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
|
||||
virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
|
||||
|
||||
// - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
|
||||
virtual void Aborted() = 0;
|
||||
|
||||
// AssertionReslt
|
||||
virtual void Result( const AssertionResult& result ) = 0;
|
||||
};
|
||||
|
||||
@ -222,26 +215,30 @@ namespace Catch
|
||||
// Not on legacy interface
|
||||
}
|
||||
|
||||
virtual void assertionEnded( AssertionStats const& assertionStats ) {
|
||||
m_legacyReporter->Result( assertionStats.assertionResult );
|
||||
virtual void assertionEnded( Ptr<AssertionStats const> const& assertionStats ) {
|
||||
m_legacyReporter->Result( assertionStats->assertionResult );
|
||||
}
|
||||
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 sectionEnded( Ptr<SectionStats const> 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 )
|
||||
m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name );
|
||||
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
|
||||
virtual void testCaseEnded( Ptr<TestCaseStats const> const& testCaseStats ) {
|
||||
if( testCaseStats->missingAssertions )
|
||||
m_legacyReporter->NoAssertionsInTestCase( testCaseStats->testInfo.name );
|
||||
m_legacyReporter->EndTestCase
|
||||
( testCaseStats->testInfo,
|
||||
testCaseStats->totals,
|
||||
testCaseStats->stdOut,
|
||||
testCaseStats->stdErr );
|
||||
}
|
||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) {
|
||||
if( testGroupStats.aborting )
|
||||
virtual void testGroupEnded( Ptr<TestGroupStats const> const& testGroupStats ) {
|
||||
if( testGroupStats->aborting )
|
||||
m_legacyReporter->Aborted();
|
||||
m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals );
|
||||
m_legacyReporter->EndGroup( testGroupStats->groupName, testGroupStats->totals );
|
||||
}
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats ) {
|
||||
m_legacyReporter->EndTesting( testRunStats.totals );
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& testRunStats ) {
|
||||
m_legacyReporter->EndTesting( testRunStats->totals );
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -23,7 +23,7 @@ namespace Catch {
|
||||
if( m_p )
|
||||
m_p->addRef();
|
||||
}
|
||||
Ptr( const Ptr& other ) : m_p( other.m_p ){
|
||||
Ptr( Ptr const& other ) : m_p( other.m_p ){
|
||||
if( m_p )
|
||||
m_p->addRef();
|
||||
}
|
||||
@ -36,33 +36,17 @@ namespace Catch {
|
||||
swap( temp );
|
||||
return *this;
|
||||
}
|
||||
Ptr& operator = ( const Ptr& other ){
|
||||
Ptr& operator = ( Ptr const& other ){
|
||||
Ptr temp( other );
|
||||
swap( temp );
|
||||
return *this;
|
||||
}
|
||||
void swap( Ptr& other ){
|
||||
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* operator->() const {
|
||||
return m_p;
|
||||
}
|
||||
|
||||
bool operator !() const {
|
||||
return m_p == NULL;
|
||||
}
|
||||
void swap( Ptr& other ) { 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* operator->() const { return m_p; }
|
||||
bool operator !() const { return m_p == NULL; }
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
@ -70,24 +54,24 @@ namespace Catch {
|
||||
|
||||
struct IShared : NonCopyable {
|
||||
virtual ~IShared();
|
||||
virtual void addRef() = 0;
|
||||
virtual void release() = 0;
|
||||
virtual void addRef() const = 0;
|
||||
virtual void release() const = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template<typename T = IShared>
|
||||
struct SharedImpl : T {
|
||||
|
||||
SharedImpl() : m_rc( 0 ){}
|
||||
|
||||
virtual void addRef(){
|
||||
virtual void addRef() const {
|
||||
++m_rc;
|
||||
}
|
||||
virtual void release(){
|
||||
virtual void release() const {
|
||||
if( --m_rc == 0 )
|
||||
delete this;
|
||||
}
|
||||
|
||||
int m_rc;
|
||||
mutable unsigned int m_rc;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -72,7 +72,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
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.setConfig( NULL );
|
||||
m_context.setResultCapture( m_prevResultCapture );
|
||||
@ -83,7 +83,7 @@ namespace Catch {
|
||||
m_reporter.testGroupStarting( testSpec );
|
||||
}
|
||||
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 ) {
|
||||
@ -134,8 +134,12 @@ namespace Catch {
|
||||
|
||||
m_totals.testCases += deltaTotals.testCases;
|
||||
|
||||
TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() );
|
||||
m_reporter.testCaseEnded( stats );
|
||||
m_reporter.testCaseEnded( new TestCaseStats( testInfo,
|
||||
deltaTotals,
|
||||
redirectedCout,
|
||||
redirectedCerr,
|
||||
missingAssertions,
|
||||
aborting() ) );
|
||||
|
||||
|
||||
delete m_runningTest;
|
||||
@ -166,13 +170,13 @@ 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.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 itEnd = m_assertionResults.end();
|
||||
for(; it != itEnd; ++it )
|
||||
m_reporter.assertionEnded( AssertionStats( *it, m_totals ) );
|
||||
m_reporter.assertionEnded( new AssertionStats( *it, m_totals ) );
|
||||
}
|
||||
m_assertionResults.clear();
|
||||
}
|
||||
@ -183,7 +187,7 @@ namespace Catch {
|
||||
m_totals.assertions.info++;
|
||||
}
|
||||
else
|
||||
m_reporter.assertionEnded( AssertionStats( result, m_totals ) );
|
||||
m_reporter.assertionEnded( new AssertionStats( result, m_totals ) );
|
||||
|
||||
// Reset AssertionInfo
|
||||
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 );
|
||||
|
||||
SectionStats stats( info, assertions, missingAssertions );
|
||||
m_reporter.sectionEnded( stats );
|
||||
m_reporter.sectionEnded( new SectionStats( info, assertions, missingAssertions ) );
|
||||
}
|
||||
|
||||
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
|
||||
|
Loading…
Reference in New Issue
Block a user