From 5e5698b792611a5c1ef1719003cfd794e5957b84 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sat, 25 Feb 2012 09:39:13 +0000 Subject: [PATCH] Test Case counts reported separately from assertions Test case passed/ failures are counted as well as individual assertions. The basic reporter now reports them seperately --- include/internal/catch_runner_impl.hpp | 5 ++ include/reporters/catch_reporter_basic.hpp | 72 ++++++++++++++-------- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index e9ff4b4b..45bd9e4a 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -387,6 +387,11 @@ 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 ); } diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp index 98c8e6eb..50df2770 100644 --- a/include/reporters/catch_reporter_basic.hpp +++ b/include/reporters/catch_reporter_basic.hpp @@ -18,6 +18,25 @@ namespace Catch { + struct pluralise + { + pluralise( std::size_t count, const std::string& label ) + : m_count( count ), + m_label( label ) + {} + + friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) + { + os << pluraliser.m_count << " " << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << "s"; + return os; + } + + std::size_t m_count; + std::string m_label; + }; + class BasicReporter : public IReporter { struct SpanInfo @@ -59,49 +78,50 @@ namespace Catch } private: - + /////////////////////////////////////////////////////////////////////////// void ReportCounts ( - const Counts& assertions + const std::string& label, + const Counts& counts ) { - if( assertions.failed + assertions.passed == 0 ) - m_config.stream() << "No tests ran"; - else if( assertions.failed == 0 ) + if( counts.failed > 0 ) { - if( assertions.passed == 1 ) - m_config.stream() << "1 test succeeded"; + if( counts.passed > 0 ) + m_config.stream() << counts.failed << " of " << counts.total() << " " << label << "s failed"; else - m_config.stream() << "All " << assertions.passed << " tests succeeded"; - } - else if( assertions.passed == 0 ) - { - if( assertions.failed == 1 ) - m_config.stream() << "1 test failed"; - else - m_config.stream() << "All " << assertions.failed << " tests failed"; + { + if( counts.failed > 1 ) + m_config.stream() << "All "; + m_config.stream() << pluralise( counts.failed, label ) << " failed"; + } } else { - m_config.stream() << assertions.passed << " test"; - if( assertions.passed > 1 ) - m_config.stream() << "s"; - - m_config.stream() << " passed but " << assertions.failed << " test"; - if( assertions.failed > 1 ) - m_config.stream() << "s"; - m_config.stream() << " failed"; + if( counts.passed > 1 ) + m_config.stream() << "All "; + m_config.stream() << pluralise( counts.passed, label ) << " passed"; } } - + /////////////////////////////////////////////////////////////////////////// void ReportCounts ( const Totals& totals ) { - ReportCounts( totals.assertions ); + if( totals.assertions.total() == 0 ) + { + m_config.stream() << "No tests ran"; + return; + } + ReportCounts( "test case", totals.testCases ); + if( totals.testCases.failed > 0 ) + { + m_config.stream() << ". "; + ReportCounts( "assertion", totals.assertions ); + } } private: // IReporter @@ -188,7 +208,7 @@ namespace Catch if( sectionSpan.emitted && !sectionSpan.name.empty() ) { m_config.stream() << "[End of section: '" << sectionName << "'. "; - ReportCounts( assertions); + ReportCounts( "assertion", assertions); m_config.stream() << "]\n" << std::endl; } m_sectionSpans.pop_back();