From ad6701d222764aeb751e4dab78d37d521eb82702 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 30 Nov 2012 08:58:46 +0000 Subject: [PATCH] SectionInfo now goes via new streaming reporter interface --- include/catch_runner.hpp | 2 +- include/internal/catch_interfaces_capture.h | 11 +++-- include/internal/catch_interfaces_reporter.h | 43 ++++++++++++++------ include/internal/catch_runner_impl.hpp | 37 ++++++++--------- include/internal/catch_section.hpp | 7 ++-- 5 files changed, 59 insertions(+), 41 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index 13d085b5..c836f155 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -50,7 +50,7 @@ namespace Catch { for(; it != itEnd && !context.aborting(); ++it ) { reporter.testGroupStarting( it->getName() ); totals += runTestsForGroup( context, *it ); - reporter.testGroupEnding( TestGroupStats( it->getName(), totals, context.aborting() ) ); + reporter.testGroupEnded( TestGroupStats( it->getName(), totals, context.aborting() ) ); } return totals; } diff --git a/include/internal/catch_interfaces_capture.h b/include/internal/catch_interfaces_capture.h index 3f01bd0b..08147055 100644 --- a/include/internal/catch_interfaces_capture.h +++ b/include/internal/catch_interfaces_capture.h @@ -20,22 +20,21 @@ namespace Catch { class ExpressionResultBuilder; class AssertionResult; struct AssertionInfo; + struct SectionInfo; struct IResultCapture { virtual ~IResultCapture(); - virtual void testEnded( const AssertionResult& result ) = 0; - virtual bool sectionStarted( const std::string& name, - const std::string& description, - const SourceLineInfo& lineInfo, + virtual void testEnded( AssertionResult const& result ) = 0; + virtual bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) = 0; - virtual void sectionEnded( const std::string& name, const Counts& assertions ) = 0; + virtual void sectionEnded( SectionInfo const& name, Counts const& assertions ) = 0; virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0; virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0; virtual bool shouldDebugBreak() const = 0; - virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0; + virtual ResultAction::Value acceptExpression( ExpressionResultBuilder const& assertionResult, AssertionInfo const& assertionInfo ) = 0; virtual std::string getCurrentTestName() const = 0; virtual const AssertionResult* getLastResult() const = 0; diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index b5fdabef..da7b67ce 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -49,12 +49,12 @@ namespace Catch SourceLineInfo const& _lineInfo ) : name( _name ), description( _description ), - sourceLineInfo( _lineInfo ) + lineInfo( _lineInfo ) {} std::string name; std::string description; - SourceLineInfo sourceLineInfo; + SourceLineInfo lineInfo; }; struct AssertionStats { @@ -70,8 +70,17 @@ namespace Catch }; struct SectionStats { + SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + bool _missingAssertions ) + : sectionInfo( _sectionInfo ), + assertions( _assertions ), + missingAssertions( _missingAssertions ) + {} + SectionInfo sectionInfo; - Totals totals; + Counts assertions; + bool missingAssertions; }; struct TestCaseStats { @@ -133,14 +142,16 @@ namespace Catch virtual void testRunStarting( std::string const& runName ) = 0; virtual void testGroupStarting( std::string const& groupName ) = 0; - // !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; + virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; + virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; - virtual void assertionEnding( AssertionStats const& assertionStats ) = 0; - virtual void testCaseEnding( TestCaseStats const& testCaseStats ) = 0; - virtual void testGroupEnding( TestGroupStats const& testGroupStats ) = 0; - virtual void testRunEnding( TestRunStats const& testRunStats ) = 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; }; // !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 @@ -204,24 +215,32 @@ namespace Catch virtual void testCaseStarting( TestCaseInfo const& testInfo ) { m_legacyReporter->StartTestCase( testInfo ); } + virtual void sectionStarting( SectionInfo const& sectionInfo ) { + m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); + } virtual void assertionStarting( AssertionInfo const& ) { // Not on legacy interface } - virtual void assertionEnding( AssertionStats const& assertionStats ) { + virtual void assertionEnded( AssertionStats const& assertionStats ) { m_legacyReporter->Result( assertionStats.assertionResult ); } - virtual void testCaseEnding( TestCaseStats const& testCaseStats ) { + 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 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 testGroupEnding( TestGroupStats const& testGroupStats ) { + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { if( testGroupStats.aborting ) m_legacyReporter->Aborted(); m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals ); } - virtual void testRunEnding( TestRunStats const& testRunStats ) { + virtual void testRunEnded( TestRunStats const& testRunStats ) { m_legacyReporter->EndTesting( testRunStats.totals ); } diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index e307a164..d4abaf7d 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -72,7 +72,7 @@ namespace Catch { } virtual ~Runner() { - LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnding( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name + LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnded( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name m_context.setRunner( m_prevRunner ); m_context.setConfig( NULL ); m_context.setResultCapture( m_prevResultCapture ); @@ -94,7 +94,7 @@ namespace Catch { for(; it != itEnd; ++it ) totals += runTest( *it ); - reporter.testGroupEnding( TestGroupStats( testSpec, totals, aborting() ) ); + reporter.testGroupEnded( TestGroupStats( testSpec, totals, aborting() ) ); return totals; } @@ -131,7 +131,7 @@ namespace Catch { m_totals.testCases += deltaTotals.testCases; TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() ); - reporter.testCaseEnding( stats ); + reporter.testCaseEnded( stats ); delete m_runningTest; @@ -163,13 +163,13 @@ namespace Catch { std::vector::const_iterator it = m_scopedInfos.begin(); std::vector::const_iterator itEnd = m_scopedInfos.end(); for(; it != itEnd; ++it ) - reporter.assertionEnding( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) ); + 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.assertionEnding( AssertionStats( *it, m_totals ) ); + reporter.assertionEnded( AssertionStats( *it, m_totals ) ); } m_assertionResults.clear(); } @@ -180,49 +180,48 @@ namespace Catch { m_totals.assertions.info++; } else - reporter.assertionEnding( AssertionStats( result, m_totals ) ); + reporter.assertionEnded( AssertionStats( result, m_totals ) ); // Reset AssertionInfo m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after this line}" , m_lastAssertionInfo.resultDisposition ); } virtual bool sectionStarted ( - const std::string& name, - const std::string& description, - const SourceLineInfo& lineInfo, + SectionInfo const& sectionInfo, Counts& assertions ) { std::ostringstream oss; - oss << name << "@" << lineInfo; + oss << sectionInfo.name << "@" << sectionInfo.lineInfo; if( !m_runningTest->addSection( oss.str() ) ) return false; - m_lastAssertionInfo.lineInfo = lineInfo; + m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; - // !TBD: ------------ - std::string className = m_runningTest->getTestCase().getTestCaseInfo().className; - TestCaseInfo sectionInfo( name, className, description, std::set(), false, lineInfo ); + LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionStarting( sectionInfo ); - m_reporter->StartSection( name, description ); assertions = m_totals.assertions; return true; } - virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) { + virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions ) { Counts assertions = m_totals.assertions - prevAssertions; + bool missingAssertions = false; if( assertions.total() == 0 && ( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) && !m_runningTest->isBranchSection() ) { - m_reporter->NoAssertionsInSection( name ); m_totals.assertions.failed++; assertions.failed++; + missingAssertions = true; + } - m_runningTest->endSection( name ); - m_reporter->EndSection( name, assertions ); + m_runningTest->endSection( info.name ); + + SectionStats stats( info, assertions, missingAssertions ); + LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionEnded( stats ); } virtual void pushScopedInfo( ScopedInfo* scopedInfo ) { diff --git a/include/internal/catch_section.hpp b/include/internal/catch_section.hpp index 38bea0d2..e6a6d254 100644 --- a/include/internal/catch_section.hpp +++ b/include/internal/catch_section.hpp @@ -20,13 +20,13 @@ namespace Catch { Section( const std::string& name, const std::string& description, const SourceLineInfo& lineInfo ) - : m_name( name ), - m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) ) + : m_info( name, description, lineInfo ), + m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( m_info, m_assertions ) ) {} ~Section() { if( m_sectionIncluded ) - getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions ); + getCurrentContext().getResultCapture().sectionEnded( m_info, m_assertions ); } // This indicates whether the section should be executed or not @@ -35,6 +35,7 @@ namespace Catch { } private: + SectionInfo m_info; std::string m_name; Counts m_assertions;