From a67d833091a0b9d8c5db7ce59d10c6ec1298cc89 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 13 Aug 2012 19:27:03 +0100 Subject: [PATCH] More things using ConfigData --- include/catch_runner.hpp | 79 +++++++++++++++++++-------------- include/internal/catch_list.hpp | 8 ++-- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index b66fec31..ca63aa0d 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -25,60 +25,73 @@ namespace Catch { INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter ) INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) - - inline int Main( Config& config ) { - - std::string reporterName = config.data().reporter.empty() - ? "basic" - : config.data().reporter; - - ReporterConfig reporterConfig( config.getName(), config.stream(), config.includeSuccessfulResults() ); - - Ptr reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig ); - if( !reporter ) - { - std::cerr << "No reporter registered with name: '" << reporterName << "'" << std::endl; - return (std::numeric_limits::max)(); - } + inline int resolveStream( Config& configWrapper ) { + const ConfigData& config = configWrapper.data(); - if( !config.data().stream.empty() ) { - if( config.data().stream[0] == '%' ) - config.useStream( config.data().stream.substr( 1 ) ); + if( !config.stream.empty() ) { + if( config.stream[0] == '%' ) + configWrapper.useStream( config.stream.substr( 1 ) ); else - config.setFilename( config.data().stream ); + configWrapper.setFilename( config.stream ); } - - // Handle list request - if( config.listWhat() != List::None ) - return List( config ); - // Open output file, if specified std::ofstream ofs; - if( !config.getFilename().empty() ) { - ofs.open( config.getFilename().c_str() ); + if( !config.outputFilename.empty() ) { + ofs.open( config.outputFilename.c_str() ); if( ofs.fail() ) { - std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl; + std::cerr << "Unable to open file: '" << config.outputFilename << "'" << std::endl; return (std::numeric_limits::max)(); } - config.setStreamBuf( ofs.rdbuf() ); + configWrapper.setStreamBuf( ofs.rdbuf() ); } + return 0; + } + + inline Ptr makeReporter( Config& configWrapper ) { + const ConfigData& config = configWrapper.data(); + + std::string reporterName = config.reporter.empty() + ? "basic" + : config.reporter; - int result = 0; + ReporterConfig reporterConfig( config.name, configWrapper.stream(), config.includeWhichResults == Include::SuccessfulResults ); + + Ptr reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig ); + if( !reporter ) + std::cerr << "No reporter registered with name: '" << reporterName << "'" << std::endl; + return reporter; + } + + inline int Main( Config& configWrapper ) { + + int result = resolveStream( configWrapper ); + if( result != 0 ) + return result; + + Ptr reporter = makeReporter( configWrapper ); + if( !reporter ) + return (std::numeric_limits::max)(); + + const ConfigData& config = configWrapper.data(); + + // Handle list request + if( config.listSpec != List::None ) + return List( config ); // Scope here for the Runner so it can use the context before it is cleaned-up { - Runner runner( config, reporter ); + Runner runner( configWrapper, reporter ); // Run test specs specified on the command line - or default to all - if( !config.testsSpecified() ) { + if( config.testSpecs.empty() ) { runner.runAll(); } else { // !TBD We should get all the testcases upfront, report any missing, // then just run them - std::vector::const_iterator it = config.getTestSpecs().begin(); - std::vector::const_iterator itEnd = config.getTestSpecs().end(); + std::vector::const_iterator it = config.testSpecs.begin(); + std::vector::const_iterator itEnd = config.testSpecs.end(); for(; it != itEnd; ++it ) { if( runner.runMatching( *it ) == 0 ) { std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl; diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp index 614ab1f7..747939bc 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.hpp @@ -12,9 +12,9 @@ #include namespace Catch { - inline int List( Config& config ) { + inline int List( const ConfigData& config ) { - if( config.listWhat() & List::Reports ) { + if( config.listSpec & List::Reports ) { std::cout << "Available reports:\n"; IReporterRegistry::FactoryMap::const_iterator it = getRegistryHub().getReporterRegistry().getFactories().begin(); IReporterRegistry::FactoryMap::const_iterator itEnd = getRegistryHub().getReporterRegistry().getFactories().end(); @@ -25,7 +25,7 @@ namespace Catch { std::cout << std::endl; } - if( config.listWhat() & List::Tests ) { + if( config.listSpec & List::Tests ) { std::cout << "Available tests:\n"; std::vector::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin(); std::vector::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end(); @@ -36,7 +36,7 @@ namespace Catch { std::cout << std::endl; } - if( ( config.listWhat() & List::All ) == 0 ) { + if( ( config.listSpec & List::All ) == 0 ) { std::cerr << "Unknown list type" << std::endl; return (std::numeric_limits::max)(); }