From 8fbd8e0f9eb74b0dbac1a42560279199d5178987 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 16 Jul 2012 08:58:28 +0100 Subject: [PATCH] Moved use of reporter into runner (our of Main, directly) --- include/catch_runner.hpp | 12 +++-------- include/internal/catch_runner_impl.hpp | 11 ++++++++-- projects/SelfTest/MiscTests.cpp | 30 ++++++++++++++------------ projects/SelfTest/catch_self_test.cpp | 2 +- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index 0e087206..2c66e179 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -47,13 +47,11 @@ namespace Catch { // Scope here for the Runner so it can use the context before it is cleaned-up { - Runner runner( config ); + Runner runner( config, config.getReporter() ); // Run test specs specified on the command line - or default to all if( !config.testsSpecified() ) { - config.getReporter()->StartGroup( "" ); runner.runAll(); - config.getReporter()->EndGroup( "", runner.getTotals() ); } else { // !TBD We should get all the testcases upfront, report any missing, @@ -61,13 +59,9 @@ namespace Catch { std::vector::const_iterator it = config.getTestSpecs().begin(); std::vector::const_iterator itEnd = config.getTestSpecs().end(); for(; it != itEnd; ++it ) { - Totals prevTotals = runner.getTotals(); - config.getReporter()->StartGroup( *it ); if( runner.runMatching( *it ) == 0 ) { - // Use reporter? - // std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl; + std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl; } - config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals ); } } result = static_cast( runner.getTotals().assertions.failed ); @@ -85,7 +79,7 @@ namespace Catch { << "\t-s, --success\n" << "\t-b, --break\n" << "\t-n, --name \n" - << "\t-a, --abort [#]\n\n" + << "\t-a, --abort [#]\n" << "\t-nt, --nothrow\n\n" << "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl; } diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index bcca0392..44ccab83 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -55,11 +55,11 @@ namespace Catch { public: - explicit Runner( Config& config ) + explicit Runner( Config& config, const Ptr& reporter ) : m_context( getCurrentMutableContext() ), m_runningTest( NULL ), m_config( config ), - m_reporter( config.getReporter() ), + m_reporter( reporter ), m_prevRunner( &m_context.getRunner() ), m_prevResultCapture( &m_context.getResultCapture() ), m_prevConfig( m_context.getConfig() ) @@ -79,6 +79,7 @@ namespace Catch { } virtual void runAll( bool runHiddenTests = false ) { + m_reporter->StartGroup( "" ); const std::vector& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); for( std::size_t i=0; i < allTests.size(); ++i ) { if( runHiddenTests || !allTests[i].isHidden() ) { @@ -89,9 +90,14 @@ namespace Catch { runTest( allTests[i] ); } } + m_reporter->EndGroup( "", getTotals() ); } virtual std::size_t runMatching( const std::string& rawTestSpec ) { + + Totals prevTotals = getTotals(); + m_reporter->StartGroup( rawTestSpec ); + TestSpec testSpec( rawTestSpec ); const std::vector& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); @@ -106,6 +112,7 @@ namespace Catch { testsRun++; } } + m_reporter->EndGroup( rawTestSpec, getTotals() - prevTotals ); return testsRun; } diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index a00e7958..cacc3f31 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -96,25 +96,27 @@ TEST_CASE( "Sections/nested3", "nested SECTION tests" ) runner.runMatching( "./Sections/nested/a/b", "mock" ); CHECK( runner.getLog() == - "\\[tc] ./Sections/nested/a/b\n" + "\\[g] ./Sections/nested/a/b\n" + " \\[tc] ./Sections/nested/a/b\n" - " \\ [s] c\n" - " \\ [s] d (leaf)\n" - " / [s] d (leaf)\n" - " / [s] c\n" + " \\ [s] c\n" + " \\ [s] d (leaf)\n" + " / [s] d (leaf)\n" + " / [s] c\n" - " \\ [s] c\n" - " \\ [s] e (leaf)\n" - " / [s] e (leaf)\n" - " / [s] c\n" + " \\ [s] c\n" + " \\ [s] e (leaf)\n" + " / [s] e (leaf)\n" + " / [s] c\n" - " \\ [s] c\n" - " / [s] c\n" + " \\ [s] c\n" + " / [s] c\n" - " \\ [s] f (leaf)\n" - " / [s] f (leaf)\n" + " \\ [s] f (leaf)\n" + " / [s] f (leaf)\n" - "/[tc] ./Sections/nested/a/b\n" ); + " /[tc] ./Sections/nested/a/b\n" + "/[g] ./Sections/nested/a/b\n" ); } diff --git a/projects/SelfTest/catch_self_test.cpp b/projects/SelfTest/catch_self_test.cpp index 951cda4b..8910f13a 100644 --- a/projects/SelfTest/catch_self_test.cpp +++ b/projects/SelfTest/catch_self_test.cpp @@ -27,7 +27,7 @@ namespace Catch{ // Scoped because Runner doesn't report EndTesting until its destructor { - Runner runner( config ); + Runner runner( config, config.getReporter() ); result = runner.runMatching( rawTestSpec ); m_totals = runner.getTotals(); }