From 50712a34c3388b9707afb8bb45f23238c0a1d81f Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sat, 1 Jan 2011 00:18:35 +0000 Subject: [PATCH] Folded ReporterConfig into RunnerConfig --- catch_runner.hpp | 2 +- internal/catch_commandline.hpp | 2 +- internal/catch_hub.h | 2 +- internal/catch_runnerconfig.hpp | 94 ++++++++++++--------------------- 4 files changed, 37 insertions(+), 63 deletions(-) diff --git a/catch_runner.hpp b/catch_runner.hpp index bff7b003..9921e7f4 100644 --- a/catch_runner.hpp +++ b/catch_runner.hpp @@ -70,7 +70,7 @@ namespace Catch std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl; return std::numeric_limits::max(); } - config.getReporterConfig().setStreamBuf( ofs.rdbuf() ); + config.setStreamBuf( ofs.rdbuf() ); } Runner runner( config ); diff --git a/internal/catch_commandline.hpp b/internal/catch_commandline.hpp index dac7a567..be23f830 100644 --- a/internal/catch_commandline.hpp +++ b/internal/catch_commandline.hpp @@ -157,7 +157,7 @@ namespace Catch case modeSuccess: if( m_args.size() != 0 ) return setErrorMode( m_command + " does not accept arguments" ); - m_config.setIncludeAll( true ); + m_config.setIncludeWhat( RunnerConfig::Include::SuccessfulResults ); break; case modeBreak: if( m_args.size() != 0 ) diff --git a/internal/catch_hub.h b/internal/catch_hub.h index bc258ad6..1ac60929 100644 --- a/internal/catch_hub.h +++ b/internal/catch_hub.h @@ -13,11 +13,11 @@ #define TWOBLUECUBES_CATCH_HUB_H_INCLUDED #include +#include "catch_interfaces_reporter.h" namespace Catch { struct IResultListener; - struct IReporterRegistry; struct ITestCaseRegistry; class Hub diff --git a/internal/catch_runnerconfig.hpp b/internal/catch_runnerconfig.hpp index f66f8f38..7c187b6a 100644 --- a/internal/catch_runnerconfig.hpp +++ b/internal/catch_runnerconfig.hpp @@ -21,63 +21,19 @@ namespace Catch { - class ReporterConfig : public IReporterConfig + class RunnerConfig : public IReporterConfig { private: - ReporterConfig( const ReporterConfig& other ); - ReporterConfig& operator = ( const ReporterConfig& other ); - + RunnerConfig( const RunnerConfig& other ); + RunnerConfig& operator = ( const RunnerConfig& other ); public: struct Include { enum What - { - FailedOnly, - SuccessfulResults - }; }; - - public: - - /////////////////////////////////////////////////////////////////////////// - explicit ReporterConfig( Include::What includeWhat = Include::FailedOnly ) - : m_includeWhat( includeWhat ), - m_os( std::cout.rdbuf() ) { - } - - /////////////////////////////////////////////////////////////////////////// - virtual bool includeSuccessfulResults() const - { - return m_includeWhat == Include::SuccessfulResults; - } - - /////////////////////////////////////////////////////////////////////////// - void setIncludeWhat(Include::What includeWhat ) - { - m_includeWhat = includeWhat; - } - - /////////////////////////////////////////////////////////////////////////// - virtual std::ostream& stream() const - { - return m_os; - } - - /////////////////////////////////////////////////////////////////////////// - void setStreamBuf( std::streambuf* buf ) - { - m_os.rdbuf( buf ); - } - - private: - Include::What m_includeWhat; - - mutable std::ostream m_os; - }; + FailedOnly, + SuccessfulResults + }; }; - class RunnerConfig - { - public: - enum ListInfo { listNone = 0, @@ -99,14 +55,16 @@ namespace Catch : m_reporter( NULL ), m_listSpec( listNone ), m_shouldDebugBreak( false ), - m_showHelp( false ) + m_showHelp( false ), + m_os( std::cout.rdbuf() ), + m_includeWhat( Include::FailedOnly ) {} void setReporterInfo( const std::string& reporterName ) { if( m_reporter.get() ) return setError( "Only one reporter may be specified" ); - setReporter( Hub::getReporterRegistry().create( reporterName, m_reporterConfig ) ); + setReporter( Hub::getReporterRegistry().create( reporterName, *this ) ); } void addTestSpec( const std::string& testSpec ) @@ -141,7 +99,7 @@ namespace Catch IReporter* getReporter() { if( !m_reporter.get() ) - setReporter( Hub::getReporterRegistry().create( "basic", m_reporterConfig ) ); + setReporter( Hub::getReporterRegistry().create( "basic", *this ) ); return m_reporter.get(); } @@ -160,13 +118,9 @@ namespace Catch return (ListInfo)( m_listSpec & listAsMask ); } - ReporterConfig& getReporterConfig() + void setIncludeWhat( Include::What includeWhat ) { - return m_reporterConfig; - } - void setIncludeAll( bool includeAll ) - { - m_reporterConfig.setIncludeWhat( includeAll ? ReporterConfig::Include::SuccessfulResults : ReporterConfig::Include::FailedOnly ); + m_includeWhat = includeWhat; } void setShouldDebugBreak( bool shouldDebugBreak ) { @@ -184,16 +138,36 @@ namespace Catch { return m_showHelp; } + + /////////////////////////////////////////////////////////////////////////// + virtual std::ostream& stream() const + { + return m_os; + } + + /////////////////////////////////////////////////////////////////////////// + void setStreamBuf( std::streambuf* buf ) + { + m_os.rdbuf( buf ); + } + + /////////////////////////////////////////////////////////////////////////// + virtual bool includeSuccessfulResults() const + { + return m_includeWhat == Include::SuccessfulResults; + } + std::auto_ptr m_reporter; std::string m_filename; - ReporterConfig m_reporterConfig; std::string m_message; ListInfo m_listSpec; std::vector m_testSpecs; bool m_shouldDebugBreak; bool m_showHelp; + mutable std::ostream m_os; + Include::What m_includeWhat; }; } // end namespace Catch