From f4774d96425baa6c2cc52f93724f33c62d48df98 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 30 Nov 2012 09:13:27 +0000 Subject: [PATCH] Reference to legacy reporter adapter localised to one place --- include/catch_runner.hpp | 6 ++-- include/internal/catch_runner_impl.hpp | 40 ++++++++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index c836f155..74f28aa1 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -45,12 +45,10 @@ namespace Catch { std::vector::const_iterator it = filterGroups.begin(); std::vector::const_iterator itEnd = filterGroups.end(); - LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_configWrapper.stream(), m_config ) ); - for(; it != itEnd && !context.aborting(); ++it ) { - reporter.testGroupStarting( it->getName() ); + context.testGroupStarting( it->getName() ); totals += runTestsForGroup( context, *it ); - reporter.testGroupEnded( TestGroupStats( it->getName(), totals, context.aborting() ) ); + context.testGroupEnded( it->getName(), totals ); } return totals; } diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index d4abaf7d..66fb52d6 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -60,7 +60,7 @@ namespace Catch { : m_context( getCurrentMutableContext() ), m_runningTest( NULL ), m_config( config ), - m_reporter( reporter ), + m_reporter( reporter, ReporterConfig( m_config.stream(), m_config.data() ) ), m_prevRunner( &m_context.getRunner() ), m_prevResultCapture( &m_context.getResultCapture() ), m_prevConfig( m_context.getConfig() ) @@ -68,33 +68,38 @@ namespace Catch { m_context.setRunner( this ); m_context.setConfig( &m_config ); m_context.setResultCapture( this ); - LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunStarting( "" ); // !TBD - name + m_reporter.testRunStarting( "" ); // !TBD - name } virtual ~Runner() { - LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnded( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name + m_reporter.testRunEnded( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name m_context.setRunner( m_prevRunner ); m_context.setConfig( NULL ); m_context.setResultCapture( m_prevResultCapture ); m_context.setConfig( m_prevConfig ); } + void testGroupStarting( std::string const& testSpec ) { + m_reporter.testGroupStarting( testSpec ); + } + void testGroupEnded( std::string const& testSpec, Totals const& totals ) { + m_reporter.testGroupEnded( TestGroupStats( testSpec, totals, aborting() ) ); + } + Totals runMatching( const std::string& testSpec ) { std::vector matchingTests = getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec ); Totals totals; - - LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ); - reporter.testGroupStarting( testSpec ); + testGroupStarting( testSpec ); std::vector::const_iterator it = matchingTests.begin(); std::vector::const_iterator itEnd = matchingTests.end(); for(; it != itEnd; ++it ) totals += runTest( *it ); - reporter.testGroupEnded( TestGroupStats( testSpec, totals, aborting() ) ); + testGroupEnded( testSpec, totals ); return totals; } @@ -106,8 +111,7 @@ namespace Catch { TestCaseInfo testInfo = testCase.getTestCaseInfo(); - LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ); - reporter.testCaseStarting( testInfo ); + m_reporter.testCaseStarting( testInfo ); m_runningTest = new RunningTest( testCase ); @@ -131,7 +135,7 @@ namespace Catch { m_totals.testCases += deltaTotals.testCases; TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() ); - reporter.testCaseEnded( stats ); + m_reporter.testCaseEnded( stats ); delete m_runningTest; @@ -152,7 +156,6 @@ namespace Catch { } virtual void testEnded( const AssertionResult& result ) { - LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ); if( result.getResultType() == ResultWas::Ok ) { m_totals.assertions.passed++; } @@ -163,13 +166,13 @@ namespace Catch { std::vector::const_iterator it = m_scopedInfos.begin(); std::vector::const_iterator itEnd = m_scopedInfos.end(); for(; it != itEnd; ++it ) - reporter.assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); + m_reporter.assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); } { std::vector::const_iterator it = m_assertionResults.begin(); std::vector::const_iterator itEnd = m_assertionResults.end(); for(; it != itEnd; ++it ) - reporter.assertionEnded( AssertionStats( *it, m_totals ) ); + m_reporter.assertionEnded( AssertionStats( *it, m_totals ) ); } m_assertionResults.clear(); } @@ -180,7 +183,7 @@ namespace Catch { m_totals.assertions.info++; } else - reporter.assertionEnded( AssertionStats( result, m_totals ) ); + m_reporter.assertionEnded( AssertionStats( result, m_totals ) ); // Reset AssertionInfo m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after this line}" , m_lastAssertionInfo.resultDisposition ); @@ -200,7 +203,7 @@ namespace Catch { m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; - LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionStarting( sectionInfo ); + m_reporter.sectionStarting( sectionInfo ); assertions = m_totals.assertions; @@ -221,7 +224,7 @@ namespace Catch { m_runningTest->endSection( info.name ); SectionStats stats( info, assertions, missingAssertions ); - LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionEnded( stats ); + m_reporter.sectionEnded( stats ); } virtual void pushScopedInfo( ScopedInfo* scopedInfo ) { @@ -275,8 +278,7 @@ namespace Catch { try { m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCase().getTestCaseInfo().lineInfo, "", ResultDisposition::Normal ); m_runningTest->reset(); - LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ); - if( reporter.getPreferences().shouldRedirectStdOut ) { + if( m_reporter.getPreferences().shouldRedirectStdOut ) { StreamRedirect coutRedir( std::cout, redirectedCout ); StreamRedirect cerrRedir( std::cerr, redirectedCerr ); m_runningTest->getTestCase().invoke(); @@ -304,7 +306,7 @@ namespace Catch { const Config& m_config; Totals m_totals; - Ptr m_reporter; + LegacyReporterAdapter m_reporter; std::vector m_scopedInfos; std::vector m_assertionResults; IRunner* m_prevRunner;