diff options
| author | Martin Hořeňovský | 2026-08-01 16:52:08 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-08-07 20:57:42 +0200 |
| commit | a0eba50e9d56c743aff1de7a50d02a6e01e73cdc (patch) | |
| tree | fd87a006c59acd9295ec3c2856e29ee6d31ba30e /src | |
| parent | 8b08d4d79514f45f7e4ce2a607ac9c94e920d1bb (diff) | |
| download | catch3-a0eba50e9d56c743aff1de7a50d02a6e01e73cdc.tar.gz | |
Make verbosity per-reporter
Diffstat (limited to 'src')
| -rw-r--r-- | src/catch2/catch_config.cpp | 4 | ||||
| -rw-r--r-- | src/catch2/catch_config.hpp | 1 | ||||
| -rw-r--r-- | src/catch2/catch_session.cpp | 2 | ||||
| -rw-r--r-- | src/catch2/interfaces/catch_interfaces_reporter.cpp | 3 | ||||
| -rw-r--r-- | src/catch2/interfaces/catch_interfaces_reporter.hpp | 4 | ||||
| -rw-r--r-- | src/catch2/internal/catch_reporter_spec_parser.cpp | 23 | ||||
| -rw-r--r-- | src/catch2/internal/catch_reporter_spec_parser.hpp | 7 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_common_base.cpp | 9 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_common_base.hpp | 2 |
9 files changed, 49 insertions, 6 deletions
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp index b4584f3c..86b9b8dd 100644 --- a/src/catch2/catch_config.cpp +++ b/src/catch2/catch_config.cpp @@ -89,6 +89,7 @@ namespace Catch { return lhs.name == rhs.name && lhs.outputFilename == rhs.outputFilename && lhs.colourMode == rhs.colourMode && + lhs.verbosity == rhs.verbosity && lhs.customOptions == rhs.customOptions; } @@ -157,6 +158,7 @@ namespace Catch { reporterSpec.outputFile() ? *reporterSpec.outputFile() : data.defaultOutputFilename, reporterSpec.colourMode().valueOr( data.defaultColourMode ), + reporterSpec.verbosity().valueOr( data.verbosity ), reporterSpec.customOptions() } ); } } @@ -232,7 +234,7 @@ namespace Catch { if ( bazelOutputFile ) { m_data.reporterSpecifications.push_back( - { "junit", std::string( bazelOutputFile ), {}, {} } ); + { "junit", std::string( bazelOutputFile ), {}, {}, {} } ); } const auto bazelTestSpec = Detail::getEnv( "TESTBRIDGE_TEST_ONLY" ); diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp index c3fea561..429c7156 100644 --- a/src/catch2/catch_config.hpp +++ b/src/catch2/catch_config.hpp @@ -35,6 +35,7 @@ namespace Catch { std::string name; std::string outputFilename; ColourMode colourMode; + Verbosity verbosity; std::map<std::string, std::string> customOptions; friend bool operator==( ProcessedReporterSpec const& lhs, ProcessedReporterSpec const& rhs ); diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index 0487fe75..97def8dc 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -52,6 +52,7 @@ namespace Catch { ReporterConfig( config, makeStream( spec.outputFilename ), spec.colourMode, + spec.verbosity, spec.customOptions ) ); } @@ -68,6 +69,7 @@ namespace Catch { ReporterConfig( config, makeStream( reporterSpec.outputFilename ), reporterSpec.colourMode, + reporterSpec.verbosity, reporterSpec.customOptions ) ) ); } diff --git a/src/catch2/interfaces/catch_interfaces_reporter.cpp b/src/catch2/interfaces/catch_interfaces_reporter.cpp index 90536bb3..929c6424 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.cpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.cpp @@ -19,10 +19,12 @@ namespace Catch { IConfig const* _fullConfig, Detail::unique_ptr<IStream> _stream, ColourMode colourMode, + Verbosity verbosity, std::map<std::string, std::string> customOptions ): m_stream( CATCH_MOVE(_stream) ), m_fullConfig( _fullConfig ), m_colourMode( colourMode ), + m_verbosity( verbosity ), m_customOptions( CATCH_MOVE( customOptions ) ) {} Detail::unique_ptr<IStream> ReporterConfig::takeStream() && { @@ -31,6 +33,7 @@ namespace Catch { } IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; } ColourMode ReporterConfig::colourMode() const { return m_colourMode; } + Verbosity ReporterConfig::verbosity() const { return m_verbosity; } std::map<std::string, std::string> const& ReporterConfig::customOptions() const { diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp index c7217889..edf2955f 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp @@ -12,6 +12,7 @@ #include <catch2/catch_test_run_info.hpp> #include <catch2/catch_totals.hpp> #include <catch2/catch_assertion_result.hpp> +#include <catch2/interfaces/catch_interfaces_config.hpp> #include <catch2/internal/catch_message_info.hpp> #include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_unique_ptr.hpp> @@ -36,6 +37,7 @@ namespace Catch { ReporterConfig( IConfig const* _fullConfig, Detail::unique_ptr<IStream> _stream, ColourMode colourMode, + Verbosity verbosity, std::map<std::string, std::string> customOptions ); ReporterConfig( ReporterConfig&& ) = default; @@ -45,12 +47,14 @@ namespace Catch { Detail::unique_ptr<IStream> takeStream() &&; IConfig const* fullConfig() const; ColourMode colourMode() const; + Verbosity verbosity() const; std::map<std::string, std::string> const& customOptions() const; private: Detail::unique_ptr<IStream> m_stream; IConfig const* m_fullConfig; ColourMode m_colourMode; + Verbosity m_verbosity; std::map<std::string, std::string> m_customOptions; }; diff --git a/src/catch2/internal/catch_reporter_spec_parser.cpp b/src/catch2/internal/catch_reporter_spec_parser.cpp index 2b08758a..3347c082 100644 --- a/src/catch2/internal/catch_reporter_spec_parser.cpp +++ b/src/catch2/internal/catch_reporter_spec_parser.cpp @@ -93,6 +93,18 @@ namespace Catch { return {}; } } + + Optional<Verbosity> stringToVerbosity( StringRef verbosity ) { + if (verbosity == "quiet") { return Verbosity::Quiet; + } else if ( verbosity == "normal" ) { + return Verbosity::Normal; + } else if ( verbosity == "high" ) { + return Verbosity::High; + } else { + return {}; + } + } + } // namespace Detail @@ -100,6 +112,7 @@ namespace Catch { return lhs.m_name == rhs.m_name && lhs.m_outputFileName == rhs.m_outputFileName && lhs.m_colourMode == rhs.m_colourMode && + lhs.m_verbosity == rhs.m_verbosity && lhs.m_customOptions == rhs.m_customOptions; } @@ -111,6 +124,7 @@ namespace Catch { std::map<std::string, std::string> kvPairs; Optional<std::string> outputFileName; Optional<ColourMode> colourMode; + Optional<Verbosity> verbosity; // First part is always reporter name, so we skip it for ( size_t i = 1; i < parts.size(); ++i ) { @@ -148,6 +162,12 @@ namespace Catch { if ( !colourMode ) { return {}; } + } else if ( key == "verbosity" ) { + // Duplicated key + if ( verbosity ) { return {}; } + verbosity = Detail::stringToVerbosity( value ); + // Parsing failed + if ( !verbosity ) { return {}; } } else { // Unrecognized option return {}; @@ -157,6 +177,7 @@ namespace Catch { return ReporterSpec{ CATCH_MOVE( parts[0] ), CATCH_MOVE( outputFileName ), CATCH_MOVE( colourMode ), + CATCH_MOVE( verbosity), CATCH_MOVE( kvPairs ) }; } @@ -164,10 +185,12 @@ ReporterSpec::ReporterSpec( std::string name, Optional<std::string> outputFileName, Optional<ColourMode> colourMode, + Optional<Verbosity> verbosity, std::map<std::string, std::string> customOptions ): m_name( CATCH_MOVE( name ) ), m_outputFileName( CATCH_MOVE( outputFileName ) ), m_colourMode( CATCH_MOVE( colourMode ) ), + m_verbosity( CATCH_MOVE( verbosity ) ), m_customOptions( CATCH_MOVE( customOptions ) ) {} } // namespace Catch diff --git a/src/catch2/internal/catch_reporter_spec_parser.hpp b/src/catch2/internal/catch_reporter_spec_parser.hpp index 9f447ee2..41102c2c 100644 --- a/src/catch2/internal/catch_reporter_spec_parser.hpp +++ b/src/catch2/internal/catch_reporter_spec_parser.hpp @@ -25,6 +25,7 @@ namespace Catch { std::vector<std::string> splitReporterSpec( StringRef reporterSpec ); Optional<ColourMode> stringToColourMode( StringRef colourMode ); + Optional<Verbosity> stringToVerbosity( StringRef verbosity ); } /** @@ -39,6 +40,7 @@ namespace Catch { std::string m_name; Optional<std::string> m_outputFileName; Optional<ColourMode> m_colourMode; + Optional<Verbosity> m_verbosity; std::map<std::string, std::string> m_customOptions; friend bool operator==( ReporterSpec const& lhs, @@ -53,6 +55,7 @@ namespace Catch { std::string name, Optional<std::string> outputFileName, Optional<ColourMode> colourMode, + Optional<Verbosity> verbosity, std::map<std::string, std::string> customOptions ); std::string const& name() const { return m_name; } @@ -63,13 +66,15 @@ namespace Catch { Optional<ColourMode> const& colourMode() const { return m_colourMode; } + Optional<Verbosity> const& verbosity() const { return m_verbosity; } + std::map<std::string, std::string> const& customOptions() const { return m_customOptions; } }; /** - * Parses provided reporter spec string into + * Parses provided reporter spec string into actual `ReporterSpec` * * Returns empty optional on errors, e.g. * * field that is not first and not a key+value pair diff --git a/src/catch2/reporters/catch_reporter_common_base.cpp b/src/catch2/reporters/catch_reporter_common_base.cpp index 0a3671e1..638824d2 100644 --- a/src/catch2/reporters/catch_reporter_common_base.cpp +++ b/src/catch2/reporters/catch_reporter_common_base.cpp @@ -19,6 +19,7 @@ namespace Catch { m_wrapped_stream( CATCH_MOVE(config).takeStream() ), m_stream( m_wrapped_stream->stream() ), m_colour( makeColourImpl( config.colourMode(), m_wrapped_stream.get() ) ), + m_verbosity( config.verbosity() ), m_customOptions( config.customOptions() ) {} @@ -26,12 +27,12 @@ namespace Catch { void ReporterBase::listReporters( std::vector<ReporterDescription> const& descriptions ) { - defaultListReporters( m_stream, descriptions, m_config->verbosity() ); + defaultListReporters( m_stream, descriptions, m_verbosity ); } void ReporterBase::listListeners( std::vector<ListenerDescription> const& descriptions ) { - defaultListListeners( m_stream, descriptions, m_config->verbosity() ); + defaultListListeners( m_stream, descriptions, m_verbosity ); } void ReporterBase::listTests(std::vector<TestCaseHandle> const& tests) { @@ -39,11 +40,11 @@ namespace Catch { m_colour.get(), tests, m_config->hasTestFilters(), - m_config->verbosity()); + m_verbosity); } void ReporterBase::listTags(std::vector<TagInfo> const& tags) { - defaultListTags( m_stream, tags, m_config->hasTestFilters(), m_config->verbosity() ); + defaultListTags( m_stream, tags, m_config->hasTestFilters(), m_verbosity ); } } // namespace Catch diff --git a/src/catch2/reporters/catch_reporter_common_base.hpp b/src/catch2/reporters/catch_reporter_common_base.hpp index b4f0a9ff..a7497a35 100644 --- a/src/catch2/reporters/catch_reporter_common_base.hpp +++ b/src/catch2/reporters/catch_reporter_common_base.hpp @@ -35,6 +35,8 @@ namespace Catch { std::ostream& m_stream; //! Colour implementation this reporter was configured for Detail::unique_ptr<ColourImpl> m_colour; + //! Verbosity configured for this reporter + Verbosity m_verbosity; //! The custom reporter options user passed down to the reporter std::map<std::string, std::string> m_customOptions; |