mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
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:
parent
8baa06c63e
commit
f9d92634f5
@ -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;
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ namespace Catch {
|
||||
IReporter::~IReporter() {}
|
||||
IReporterFactory::~IReporterFactory() {}
|
||||
IReporterRegistry::~IReporterRegistry() {}
|
||||
IStreamingReporter::~IStreamingReporter() {}
|
||||
LegacyReporterAdapter::~LegacyReporterAdapter() {}
|
||||
|
||||
BasicReporter::~BasicReporter() {}
|
||||
IRunner::~IRunner() {}
|
||||
IMutableContext::~IMutableContext() {}
|
||||
|
@ -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;
|
||||
@ -128,6 +163,48 @@ namespace Catch
|
||||
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();
|
||||
virtual IReporter* create( const ReporterConfig& config ) const = 0;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -105,7 +106,8 @@ namespace Catch {
|
||||
|
||||
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 );
|
||||
|
@ -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 ),
|
||||
|
@ -196,12 +196,12 @@
|
||||
[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: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:294: cp != __null succeeded for: 0x7fff57d28028 != 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:291: p != __null succeeded for: 0x7fff5c7c3f58 != 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: 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: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)]
|
||||
|
||||
[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)]
|
||||
|
||||
[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: {?} == {?}
|
||||
[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)]
|
||||
|
||||
[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)]
|
||||
|
||||
[Running: ./succeeding/unimplemented static bool]
|
||||
|
Loading…
Reference in New Issue
Block a user