From f7493475230aa25a4086bbd44af59f9705aea493 Mon Sep 17 00:00:00 2001 From: Baruch Burstein Date: Thu, 6 Jul 2017 01:25:49 +0300 Subject: [PATCH] Check that reporter supports requested verbosity --- include/internal/catch_config.hpp | 3 +-- include/internal/catch_interfaces_config.h | 1 + include/internal/catch_interfaces_reporter.h | 3 +++ include/reporters/catch_reporter_bases.hpp | 12 ++++++++++++ include/reporters/catch_reporter_multi.hpp | 18 ++++++++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index bc1f5b26..3f967b93 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -86,8 +86,6 @@ namespace Catch { bool listTags() const { return m_data.listTags; } bool listReporters() const { return m_data.listReporters; } - Verbosity verbosity() const { return m_data.verbosity; } - std::string getProcessName() const { return m_data.processName; } std::vector const& getReporterNames() const { return m_data.reporterNames; } @@ -110,6 +108,7 @@ namespace Catch { virtual bool shouldDebugBreak() const override { return m_data.shouldDebugBreak; } virtual int abortAfter() const override { return m_data.abortAfter; } virtual bool showInvisibles() const override { return m_data.showInvisibles; } + virtual Verbosity verbosity() const override { return m_data.verbosity; } private: diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h index 75499014..d2d7602c 100644 --- a/include/internal/catch_interfaces_config.h +++ b/include/internal/catch_interfaces_config.h @@ -64,6 +64,7 @@ namespace Catch { virtual unsigned int rngSeed() const = 0; virtual UseColour::YesOrNo useColour() const = 0; virtual std::vector const& getSectionsToRun() const = 0; + virtual Verbosity verbosity() const = 0; }; using IConfigPtr = std::shared_ptr; diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index 7a42f097..ea68aa54 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace Catch @@ -212,6 +213,8 @@ namespace Catch virtual ReporterPreferences getPreferences() const = 0; + virtual std::set const& getSupportedVerbosities() const = 0; + virtual void noMatchingTestCases( std::string const& spec ) = 0; virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index 27767060..f6a8d28e 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -49,12 +49,18 @@ namespace Catch { stream( _config.stream() ) { m_reporterPrefs.shouldRedirectStdOut = false; + CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" ); } virtual ReporterPreferences getPreferences() const override { return m_reporterPrefs; } + virtual std::set const& getSupportedVerbosities() const override { + static std::set supported{ Verbosity::Normal }; + return supported; + } + virtual ~StreamingReporterBase() override; virtual void noMatchingTestCases( std::string const& ) override {} @@ -155,6 +161,7 @@ namespace Catch { stream( _config.stream() ) { m_reporterPrefs.shouldRedirectStdOut = false; + CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" ); } ~CumulativeReporterBase(); @@ -162,6 +169,11 @@ namespace Catch { return m_reporterPrefs; } + virtual std::set const& getSupportedVerbosities() const override { + static std::set supported{ Verbosity::Normal }; + return supported; + } + virtual void testRunStarting( TestRunInfo const& ) override {} virtual void testGroupStarting( GroupInfo const& ) override {} diff --git a/include/reporters/catch_reporter_multi.hpp b/include/reporters/catch_reporter_multi.hpp index 589c34e0..57f0974c 100644 --- a/include/reporters/catch_reporter_multi.hpp +++ b/include/reporters/catch_reporter_multi.hpp @@ -15,9 +15,23 @@ namespace Catch { class MultipleReporters : public IStreamingReporter { typedef std::vector Reporters; Reporters m_reporters; + std::set m_verbosities; public: void add( IStreamingReporterPtr&& reporter ) { + if( m_reporters.empty() ) { + m_verbosities = reporter->getSupportedVerbosities(); + } + else { + for( auto it = m_verbosities.cbegin(); it != m_verbosities.cend(); ) { + if( reporter->getSupportedVerbosities().count( *it ) == 0 ) { + it = m_verbosities.erase(it); + } + else { + ++it; + } + } + } m_reporters.push_back( std::move( reporter ) ); } @@ -27,6 +41,10 @@ public: // IStreamingReporter return m_reporters[0]->getPreferences(); } + virtual std::set const& getSupportedVerbosities() const override { + return m_verbosities; + } + virtual void noMatchingTestCases( std::string const& spec ) override { for( auto const& reporter : m_reporters ) reporter->noMatchingTestCases( spec );