From ab4b36862d94ba9502d7dd7f1292bad428e9ac9c Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 22 May 2012 08:56:11 +0100 Subject: [PATCH] Added a delta method to Totals that tracks new passed/ failures This fixes issue with test group results --- include/internal/catch_runner_impl.hpp | 11 ++++------- include/internal/catch_totals.hpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index fd30d8f..13e6a5a 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -111,7 +111,7 @@ namespace Catch { m_reporter->StartGroup( "test case run" ); m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() ); runCurrentTest( redirectedCout, redirectedCerr ); - m_reporter->EndGroup( "test case run", m_totals - prevTotals ); + m_reporter->EndGroup( "test case run", m_totals.delta( prevTotals ) ); } while( m_runningTest->hasUntestedSections() ); } @@ -120,12 +120,9 @@ namespace Catch { delete m_runningTest; m_runningTest = NULL; - if( m_totals.assertions.failed > prevTotals.assertions.failed ) - ++m_totals.testCases.failed; - else - ++m_totals.testCases.passed; - - m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr ); + Totals deltaTotals = m_totals.delta( prevTotals ); + m_totals.testCases += deltaTotals.testCases; + m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr ); } virtual Totals getTotals() const { diff --git a/include/internal/catch_totals.hpp b/include/internal/catch_totals.hpp index 8c89f73..557288d 100644 --- a/include/internal/catch_totals.hpp +++ b/include/internal/catch_totals.hpp @@ -19,6 +19,11 @@ namespace Catch { diff.failed = failed - other.failed; return diff; } + Counts& operator += ( const Counts& other ) { + passed += other.passed; + failed += other.failed; + return *this; + } std::size_t total() const { return passed + failed; @@ -36,6 +41,15 @@ namespace Catch { diff.testCases = testCases - other.testCases; return diff; } + + Totals delta( const Totals& prevTotals ) const { + Totals diff = *this - prevTotals; + if( diff.assertions.failed > 0 ) + ++diff.testCases.failed; + else + ++diff.testCases.passed; + return diff; + } Counts assertions; Counts testCases;