First cut of using new streaming reporter interface - using an adapter to map back to the legacy interface

Doesn't do sections or the query functions (e.g. shouldRedirectStdOut)
This commit is contained in:
Phil Nash 2012-11-25 21:43:36 +00:00
parent 8baa06c63e
commit f9d92634f5
6 changed files with 115 additions and 30 deletions

View File

@ -44,12 +44,13 @@ namespace Catch {
std::vector<TestCaseFilters>::const_iterator it = filterGroups.begin(); std::vector<TestCaseFilters>::const_iterator it = filterGroups.begin();
std::vector<TestCaseFilters>::const_iterator itEnd = filterGroups.end(); std::vector<TestCaseFilters>::const_iterator itEnd = filterGroups.end();
LegacyReporterAdapter reporter( m_reporter );
for(; it != itEnd && !context.aborting(); ++it ) { for(; it != itEnd && !context.aborting(); ++it ) {
m_reporter->StartGroup( it->getName() ); reporter.testGroupStarting( it->getName() );
totals += runTestsForGroup( context, *it ); totals += runTestsForGroup( context, *it );
if( context.aborting() ) reporter.testGroupEnding( TestGroupStats( it->getName(), totals, context.aborting() ) );
m_reporter->Aborted();
m_reporter->EndGroup( it->getName(), totals );
} }
return totals; return totals;
} }

View File

@ -47,6 +47,9 @@ namespace Catch {
IReporter::~IReporter() {} IReporter::~IReporter() {}
IReporterFactory::~IReporterFactory() {} IReporterFactory::~IReporterFactory() {}
IReporterRegistry::~IReporterRegistry() {} IReporterRegistry::~IReporterRegistry() {}
IStreamingReporter::~IStreamingReporter() {}
LegacyReporterAdapter::~LegacyReporterAdapter() {}
BasicReporter::~BasicReporter() {} BasicReporter::~BasicReporter() {}
IRunner::~IRunner() {} IRunner::~IRunner() {}
IMutableContext::~IMutableContext() {} IMutableContext::~IMutableContext() {}

View File

@ -51,13 +51,31 @@ namespace Catch
}; };
struct AssertionStats { struct AssertionStats {
AssertionInfo assertionInfo; AssertionStats( const AssertionResult& _assertionResult,
const Totals& _totals )
: assertionResult( _assertionResult ),
totals( _totals )
{}
// AssertionInfo assertionInfo; // !TBD: needed? It's in the result
AssertionResult assertionResult; AssertionResult assertionResult;
Totals totals; Totals totals;
}; };
struct TestCaseStats { struct TestCaseStats {
TestCase testInfo; TestCaseStats( const TestCaseInfo& _testInfo,
const Totals& _totals,
const std::string& _stdOut,
const std::string& _stdErr,
bool _aborting )
: testInfo( _testInfo ),
totals( _totals ),
stdOut( _stdOut ),
stdErr( _stdErr ),
aborting( _aborting )
{}
TestCaseInfo testInfo;
Totals totals; Totals totals;
std::string stdOut; std::string stdOut;
std::string stdErr; std::string stdErr;
@ -65,12 +83,28 @@ namespace Catch
}; };
struct TestGroupStats { struct TestGroupStats {
TestGroupStats( const std::string& _groupName,
const Totals& _totals,
bool _aborting )
: groupName( _groupName ),
totals( _totals ),
aborting( _aborting )
{}
std::string groupName; std::string groupName;
Totals totals; Totals totals;
bool aborting; bool aborting;
}; };
struct TestRunStats { struct TestRunStats {
TestRunStats( const std::string& _runName,
const Totals& _totals,
bool _aborting )
: runName( _runName ),
totals( _totals ),
aborting( _aborting )
{}
std::string runName; std::string runName;
Totals totals; Totals totals;
bool aborting; bool aborting;
@ -78,11 +112,12 @@ namespace Catch
// !Work In progress // !Work In progress
struct IStreamingReporter : IShared { struct IStreamingReporter : IShared {
virtual ~IStreamingReporter();
virtual void testRunStarting( const std::string& runName ) = 0; virtual void testRunStarting( const std::string& runName ) = 0;
virtual void testGroupStarting( const std::string& groupName ) = 0; virtual void testGroupStarting( const std::string& groupName ) = 0;
// !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer // !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer
virtual void testCaseStarting( const TestCase& testInfo ) = 0; virtual void testCaseStarting( const TestCaseInfo& testInfo ) = 0;
virtual void assertionStarting( const AssertionInfo& assertionInfo ) = 0; virtual void assertionStarting( const AssertionInfo& assertionInfo ) = 0;
virtual void assertionEnding( const AssertionStats& assertionStats ) = 0; virtual void assertionEnding( const AssertionStats& assertionStats ) = 0;
@ -127,6 +162,48 @@ namespace Catch
// AssertionReslt // AssertionReslt
virtual void Result( const AssertionResult& result ) = 0; virtual void Result( const AssertionResult& result ) = 0;
}; };
class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
{
public:
LegacyReporterAdapter( const Ptr<IReporter>& legacyReporter )
: m_legacyReporter( legacyReporter )
{}
virtual ~LegacyReporterAdapter();
virtual void testRunStarting( const std::string& ) {
m_legacyReporter->StartTesting();
}
virtual void testGroupStarting( const std::string& groupName ) {
m_legacyReporter->StartGroup( groupName );
}
virtual void testCaseStarting( const TestCaseInfo& testInfo ) {
m_legacyReporter->StartTestCase( testInfo );
}
virtual void assertionStarting( const AssertionInfo& ) {
// Not on legacy interface
}
virtual void assertionEnding( const AssertionStats& assertionStats ) {
m_legacyReporter->Result( assertionStats.assertionResult );
}
virtual void testCaseEnding( const TestCaseStats& testCaseStats ) {
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
}
virtual void testGroupEnding( const TestGroupStats& testGroupStats ) {
if( testGroupStats.aborting )
m_legacyReporter->Aborted();
m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals );
}
virtual void testRunEnding( const TestRunStats& testRunStats ) {
m_legacyReporter->EndTesting( testRunStats.totals );
}
private:
Ptr<IReporter> m_legacyReporter;
};
struct IReporterFactory { struct IReporterFactory {
virtual ~IReporterFactory(); virtual ~IReporterFactory();

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->StartTesting(); LegacyReporterAdapter( m_reporter ).testRunStarting( "" ); // !TBD - name
} }
virtual ~Runner() { virtual ~Runner() {
m_reporter->EndTesting( m_totals ); LegacyReporterAdapter( m_reporter ).testRunEnding( 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 );
@ -85,15 +85,16 @@ namespace Catch {
Totals totals; Totals totals;
m_reporter->StartGroup( testSpec ); LegacyReporterAdapter reporter( m_reporter );
reporter.testGroupStarting( testSpec );
std::vector<TestCase>::const_iterator it = matchingTests.begin(); std::vector<TestCase>::const_iterator it = matchingTests.begin();
std::vector<TestCase>::const_iterator itEnd = matchingTests.end(); std::vector<TestCase>::const_iterator itEnd = matchingTests.end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it )
totals += runTest( *it ); totals += runTest( *it );
// !TBD use std::accumulate?
m_reporter->EndGroup( testSpec, totals ); reporter.testGroupEnding( TestGroupStats( testSpec, totals, aborting() ) );
return totals; return totals;
} }
@ -104,8 +105,9 @@ namespace Catch {
std::string redirectedCerr; std::string redirectedCerr;
TestCaseInfo testInfo = testCase.getTestCaseInfo(); TestCaseInfo testInfo = testCase.getTestCaseInfo();
m_reporter->StartTestCase( testInfo ); LegacyReporterAdapter reporter( m_reporter );
reporter.testCaseStarting( testInfo );
m_runningTest = new RunningTest( &testCase ); m_runningTest = new RunningTest( &testCase );
@ -126,7 +128,8 @@ namespace Catch {
} }
m_totals.testCases += deltaTotals.testCases; m_totals.testCases += deltaTotals.testCases;
m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr ); TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr , aborting() );
reporter.testCaseEnding( stats );
delete m_runningTest; delete m_runningTest;
@ -147,6 +150,7 @@ namespace Catch {
} }
virtual void testEnded( const AssertionResult& result ) { virtual void testEnded( const AssertionResult& result ) {
LegacyReporterAdapter reporter( m_reporter );
if( result.getResultType() == ResultWas::Ok ) { if( result.getResultType() == ResultWas::Ok ) {
m_totals.assertions.passed++; m_totals.assertions.passed++;
} }
@ -157,13 +161,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->Result( (*it)->buildResult( m_lastAssertionInfo ) ); reporter.assertionEnding( 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->Result( *it ); reporter.assertionEnding( AssertionStats( *it, m_totals ) );
} }
m_assertionResults.clear(); m_assertionResults.clear();
} }
@ -174,7 +178,7 @@ namespace Catch {
m_totals.assertions.info++; m_totals.assertions.info++;
} }
else else
m_reporter->Result( result ); reporter.assertionEnding( 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 );

View File

@ -31,12 +31,12 @@ namespace Catch {
return TestCase( _testCase, info ); return TestCase( _testCase, info );
} }
TestCaseInfo::TestCaseInfo( const std::string& _name, TestCaseInfo::TestCaseInfo( const std::string& _name,
const std::string& _className, const std::string& _className,
const std::string& _description, const std::string& _description,
const std::set<std::string>& _tags, const std::set<std::string>& _tags,
bool _isHidden, bool _isHidden,
const SourceLineInfo& _lineInfo ) const SourceLineInfo& _lineInfo )
: name( _name ), : name( _name ),
className( _className ), className( _className ),
description( _description ), description( _description ),

View File

@ -196,12 +196,12 @@
[Running: ./succeeding/conditions/ptr] [Running: ./succeeding/conditions/ptr]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:285: p == __null succeeded for: __null == 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:285: p == __null succeeded for: __null == 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:286: p == pNULL succeeded for: __null == __null /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:286: p == pNULL succeeded for: __null == __null
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:291: p != __null succeeded for: 0x7fff57d28028 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:291: p != __null succeeded for: 0x7fff5c7c3f58 != 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:294: cp != __null succeeded for: 0x7fff57d28028 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:294: cp != __null succeeded for: 0x7fff5c7c3f58 != 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:297: cpc != __null succeeded for: 0x7fff57d28028 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:297: cpc != __null succeeded for: 0x7fff5c7c3f58 != 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:299: returnsNull() == __null succeeded for: {null string} == 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:299: returnsNull() == __null succeeded for: {null string} == 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:300: returnsConstNull() == __null succeeded for: {null string} == 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:300: returnsConstNull() == __null succeeded for: {null string} == 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:302: __null != p succeeded for: 0 != 0x7fff57d28028 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:302: __null != p succeeded for: 0 != 0x7fff5c7c3f58
[Finished: './succeeding/conditions/ptr' All tests passed (8 assertions in 1 test case)] [Finished: './succeeding/conditions/ptr' All tests passed (8 assertions in 1 test case)]
[Running: ./succeeding/conditions/not] [Running: ./succeeding/conditions/not]
@ -1357,7 +1357,7 @@ No assertions in test case, './inprogress/failing/Tricky/compound lhs'
[Finished: './inprogress/failing/Tricky/compound lhs' 1 test case failed (1 assertion failed)] [Finished: './inprogress/failing/Tricky/compound lhs' 1 test case failed (1 assertion failed)]
[Running: ./failing/Tricky/non streamable type] [Running: ./failing/Tricky/non streamable type]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:95: &o1 == &o2 failed for: 0x7fff57d28808 == 0x7fff57d28800 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:95: &o1 == &o2 failed for: 0x7fff5c7c4738 == 0x7fff5c7c4730
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:96: o1 == o2 failed for: {?} == {?} /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:96: o1 == o2 failed for: {?} == {?}
[Finished: './failing/Tricky/non streamable type' 1 test case failed (All 2 assertions failed)] [Finished: './failing/Tricky/non streamable type' 1 test case failed (All 2 assertions failed)]
@ -1383,7 +1383,7 @@ No assertions in test case, './inprogress/failing/Tricky/compound lhs'
[Finished: './succeeding/enum/bits' All tests passed (1 assertion in 1 test case)] [Finished: './succeeding/enum/bits' All tests passed (1 assertion in 1 test case)]
[Running: ./succeeding/boolean member] [Running: ./succeeding/boolean member]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:239: obj.prop != __null succeeded for: 0x7fff57d28800 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:239: obj.prop != __null succeeded for: 0x7fff5c7c4730 != 0
[Finished: './succeeding/boolean member' All tests passed (1 assertion in 1 test case)] [Finished: './succeeding/boolean member' All tests passed (1 assertion in 1 test case)]
[Running: ./succeeding/unimplemented static bool] [Running: ./succeeding/unimplemented static bool]