mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-03 21:49:32 +01:00 
			
		
		
		
	Check that reporter supports requested verbosity
This commit is contained in:
		@@ -86,8 +86,6 @@ namespace Catch {
 | 
				
			|||||||
        bool listTags() const           { return m_data.listTags; }
 | 
					        bool listTags() const           { return m_data.listTags; }
 | 
				
			||||||
        bool listReporters() const      { return m_data.listReporters; }
 | 
					        bool listReporters() const      { return m_data.listReporters; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Verbosity verbosity() const     { return m_data.verbosity; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        std::string getProcessName() const { return m_data.processName; }
 | 
					        std::string getProcessName() const { return m_data.processName; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
 | 
					        std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
 | 
				
			||||||
@@ -110,6 +108,7 @@ namespace Catch {
 | 
				
			|||||||
        virtual bool shouldDebugBreak() const override              { return m_data.shouldDebugBreak; }
 | 
					        virtual bool shouldDebugBreak() const override              { return m_data.shouldDebugBreak; }
 | 
				
			||||||
        virtual int abortAfter() const override                     { return m_data.abortAfter; }
 | 
					        virtual int abortAfter() const override                     { return m_data.abortAfter; }
 | 
				
			||||||
        virtual bool showInvisibles() const override                { return m_data.showInvisibles; }
 | 
					        virtual bool showInvisibles() const override                { return m_data.showInvisibles; }
 | 
				
			||||||
 | 
					        virtual Verbosity verbosity() const override                { return m_data.verbosity; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,6 +64,7 @@ namespace Catch {
 | 
				
			|||||||
        virtual unsigned int rngSeed() const = 0;
 | 
					        virtual unsigned int rngSeed() const = 0;
 | 
				
			||||||
        virtual UseColour::YesOrNo useColour() const = 0;
 | 
					        virtual UseColour::YesOrNo useColour() const = 0;
 | 
				
			||||||
        virtual std::vector<std::string> const& getSectionsToRun() const = 0;
 | 
					        virtual std::vector<std::string> const& getSectionsToRun() const = 0;
 | 
				
			||||||
 | 
					        virtual Verbosity verbosity() const = 0;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    using IConfigPtr = std::shared_ptr<IConfig const>;
 | 
					    using IConfigPtr = std::shared_ptr<IConfig const>;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@
 | 
				
			|||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <ostream>
 | 
					#include <ostream>
 | 
				
			||||||
#include <map>
 | 
					#include <map>
 | 
				
			||||||
 | 
					#include <set>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Catch
 | 
					namespace Catch
 | 
				
			||||||
@@ -212,6 +213,8 @@ namespace Catch
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        virtual ReporterPreferences getPreferences() const = 0;
 | 
					        virtual ReporterPreferences getPreferences() const = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        virtual std::set<Verbosity> const& getSupportedVerbosities() const = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual void noMatchingTestCases( std::string const& spec ) = 0;
 | 
					        virtual void noMatchingTestCases( std::string const& spec ) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
 | 
					        virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,12 +49,18 @@ namespace Catch {
 | 
				
			|||||||
            stream( _config.stream() )
 | 
					            stream( _config.stream() )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            m_reporterPrefs.shouldRedirectStdOut = false;
 | 
					            m_reporterPrefs.shouldRedirectStdOut = false;
 | 
				
			||||||
 | 
					            CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual ReporterPreferences getPreferences() const override {
 | 
					        virtual ReporterPreferences getPreferences() const override {
 | 
				
			||||||
            return m_reporterPrefs;
 | 
					            return m_reporterPrefs;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
 | 
				
			||||||
 | 
					            static std::set<Verbosity> supported{ Verbosity::Normal };
 | 
				
			||||||
 | 
					            return supported;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual ~StreamingReporterBase() override;
 | 
					        virtual ~StreamingReporterBase() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual void noMatchingTestCases( std::string const& ) override {}
 | 
					        virtual void noMatchingTestCases( std::string const& ) override {}
 | 
				
			||||||
@@ -155,6 +161,7 @@ namespace Catch {
 | 
				
			|||||||
            stream( _config.stream() )
 | 
					            stream( _config.stream() )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            m_reporterPrefs.shouldRedirectStdOut = false;
 | 
					            m_reporterPrefs.shouldRedirectStdOut = false;
 | 
				
			||||||
 | 
					            CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ~CumulativeReporterBase();
 | 
					        ~CumulativeReporterBase();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -162,6 +169,11 @@ namespace Catch {
 | 
				
			|||||||
            return m_reporterPrefs;
 | 
					            return m_reporterPrefs;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
 | 
				
			||||||
 | 
					            static std::set<Verbosity> supported{ Verbosity::Normal };
 | 
				
			||||||
 | 
					            return supported;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual void testRunStarting( TestRunInfo const& ) override {}
 | 
					        virtual void testRunStarting( TestRunInfo const& ) override {}
 | 
				
			||||||
        virtual void testGroupStarting( GroupInfo const& ) override {}
 | 
					        virtual void testGroupStarting( GroupInfo const& ) override {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,9 +15,23 @@ namespace Catch {
 | 
				
			|||||||
class MultipleReporters : public IStreamingReporter {
 | 
					class MultipleReporters : public IStreamingReporter {
 | 
				
			||||||
    typedef std::vector<IStreamingReporterPtr> Reporters;
 | 
					    typedef std::vector<IStreamingReporterPtr> Reporters;
 | 
				
			||||||
    Reporters m_reporters;
 | 
					    Reporters m_reporters;
 | 
				
			||||||
 | 
					    std::set<Verbosity> m_verbosities;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    void add( IStreamingReporterPtr&& reporter ) {
 | 
					    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 ) );
 | 
					        m_reporters.push_back( std::move( reporter ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,6 +41,10 @@ public: // IStreamingReporter
 | 
				
			|||||||
        return m_reporters[0]->getPreferences();
 | 
					        return m_reporters[0]->getPreferences();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
 | 
				
			||||||
 | 
					        return m_verbosities;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void noMatchingTestCases( std::string const& spec ) override {
 | 
					    virtual void noMatchingTestCases( std::string const& spec ) override {
 | 
				
			||||||
        for( auto const& reporter : m_reporters )
 | 
					        for( auto const& reporter : m_reporters )
 | 
				
			||||||
            reporter->noMatchingTestCases( spec );
 | 
					            reporter->noMatchingTestCases( spec );
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user