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 itEnd = filterGroups.end();
LegacyReporterAdapter reporter( m_reporter );
for(; it != itEnd && !context.aborting(); ++it ) {
m_reporter->StartGroup( it->getName() );
reporter.testGroupStarting( it->getName() );
totals += runTestsForGroup( context, *it );
if( context.aborting() )
m_reporter->Aborted();
m_reporter->EndGroup( it->getName(), totals );
reporter.testGroupEnding( TestGroupStats( it->getName(), totals, context.aborting() ) );
}
return totals;
}

View File

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

View File

@@ -51,13 +51,31 @@ namespace Catch
};
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;
Totals totals;
};
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;
std::string stdOut;
std::string stdErr;
@@ -65,12 +83,28 @@ namespace Catch
};
struct TestGroupStats {
TestGroupStats( const std::string& _groupName,
const Totals& _totals,
bool _aborting )
: groupName( _groupName ),
totals( _totals ),
aborting( _aborting )
{}
std::string groupName;
Totals totals;
bool aborting;
};
struct TestRunStats {
TestRunStats( const std::string& _runName,
const Totals& _totals,
bool _aborting )
: runName( _runName ),
totals( _totals ),
aborting( _aborting )
{}
std::string runName;
Totals totals;
bool aborting;
@@ -78,11 +112,12 @@ namespace Catch
// !Work In progress
struct IStreamingReporter : IShared {
virtual ~IStreamingReporter();
virtual void testRunStarting( const std::string& runName ) = 0;
virtual void testGroupStarting( const std::string& groupName ) = 0;
// !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 assertionEnding( const AssertionStats& assertionStats ) = 0;
@@ -127,6 +162,48 @@ namespace Catch
// AssertionReslt
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 {
virtual ~IReporterFactory();

View File

@@ -68,11 +68,11 @@ namespace Catch {
m_context.setRunner( this );
m_context.setConfig( &m_config );
m_context.setResultCapture( this );
m_reporter->StartTesting();
LegacyReporterAdapter( m_reporter ).testRunStarting( "" ); // !TBD - name
}
virtual ~Runner() {
m_reporter->EndTesting( m_totals );
LegacyReporterAdapter( m_reporter ).testRunEnding( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name
m_context.setRunner( m_prevRunner );
m_context.setConfig( NULL );
m_context.setResultCapture( m_prevResultCapture );
@@ -85,15 +85,16 @@ namespace Catch {
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 itEnd = matchingTests.end();
for(; it != itEnd; ++it )
totals += runTest( *it );
// !TBD use std::accumulate?
m_reporter->EndGroup( testSpec, totals );
reporter.testGroupEnding( TestGroupStats( testSpec, totals, aborting() ) );
return totals;
}
@@ -104,8 +105,9 @@ namespace Catch {
std::string redirectedCerr;
TestCaseInfo testInfo = testCase.getTestCaseInfo();
m_reporter->StartTestCase( testInfo );
LegacyReporterAdapter reporter( m_reporter );
reporter.testCaseStarting( testInfo );
m_runningTest = new RunningTest( &testCase );
@@ -126,7 +128,8 @@ namespace Catch {
}
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;
@@ -147,6 +150,7 @@ namespace Catch {
}
virtual void testEnded( const AssertionResult& result ) {
LegacyReporterAdapter reporter( m_reporter );
if( result.getResultType() == ResultWas::Ok ) {
m_totals.assertions.passed++;
}
@@ -157,13 +161,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->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 itEnd = m_assertionResults.end();
for(; it != itEnd; ++it )
m_reporter->Result( *it );
reporter.assertionEnding( AssertionStats( *it, m_totals ) );
}
m_assertionResults.clear();
}
@@ -174,7 +178,7 @@ namespace Catch {
m_totals.assertions.info++;
}
else
m_reporter->Result( result );
reporter.assertionEnding( AssertionStats( result, m_totals ) );
// Reset AssertionInfo
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 );
}
TestCaseInfo::TestCaseInfo( const std::string& _name,
const std::string& _className,
const std::string& _description,
const std::set<std::string>& _tags,
bool _isHidden,
const SourceLineInfo& _lineInfo )
TestCaseInfo::TestCaseInfo( const std::string& _name,
const std::string& _className,
const std::string& _description,
const std::set<std::string>& _tags,
bool _isHidden,
const SourceLineInfo& _lineInfo )
: name( _name ),
className( _className ),
description( _description ),