From a404f37cec56e6ff161db9b26cfb1e77de3bc1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 16 Feb 2026 22:51:27 +0100 Subject: [PATCH] Add quiet verbosity variant to the default listener and tag listing --- docs/command-line.md | 5 +++-- .../reporters/catch_reporter_common_base.cpp | 6 +++--- .../reporters/catch_reporter_helpers.cpp | 21 ++++++++++++++++--- .../reporters/catch_reporter_helpers.hpp | 8 +++++-- .../IntrospectiveTests/Reporters.tests.cpp | 4 ++-- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/docs/command-line.md b/docs/command-line.md index 9a2b9e13..0b7fb0d4 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -289,9 +289,10 @@ as follows: | Option | `normal` (default) | `quiet` | `high` | |--------------------|---------------------------------|---------------------|-----------------------------------------| | `--list-tests` | Test names and tags | Test names only | Same as `normal`, plus source code line | -| `--list-tags` | Tags and counts | Same as `normal` | Same as `normal` | +| `--list-tags` | Tags and counts | Tags only | Same as `normal` | | `--list-reporters` | Reporter names and descriptions | Reporter names only | Same as `normal` | -| `--list-listeners` | Listener names and descriptions | Same as `normal` | Same as `normal` | +| `--list-listeners` | Listener names and descriptions | Listener names only | Same as `normal` | + ## Sending output to a file diff --git a/src/catch2/reporters/catch_reporter_common_base.cpp b/src/catch2/reporters/catch_reporter_common_base.cpp index a1ca76a0..0a3671e1 100644 --- a/src/catch2/reporters/catch_reporter_common_base.cpp +++ b/src/catch2/reporters/catch_reporter_common_base.cpp @@ -26,12 +26,12 @@ namespace Catch { void ReporterBase::listReporters( std::vector const& descriptions ) { - defaultListReporters(m_stream, descriptions, m_config->verbosity()); + defaultListReporters( m_stream, descriptions, m_config->verbosity() ); } void ReporterBase::listListeners( std::vector const& descriptions ) { - defaultListListeners( m_stream, descriptions ); + defaultListListeners( m_stream, descriptions, m_config->verbosity() ); } void ReporterBase::listTests(std::vector const& tests) { @@ -43,7 +43,7 @@ namespace Catch { } void ReporterBase::listTags(std::vector const& tags) { - defaultListTags( m_stream, tags, m_config->hasTestFilters() ); + defaultListTags( m_stream, tags, m_config->hasTestFilters(), m_config->verbosity() ); } } // namespace Catch diff --git a/src/catch2/reporters/catch_reporter_helpers.cpp b/src/catch2/reporters/catch_reporter_helpers.cpp index c710ac43..6fa68a3c 100644 --- a/src/catch2/reporters/catch_reporter_helpers.cpp +++ b/src/catch2/reporters/catch_reporter_helpers.cpp @@ -143,7 +143,15 @@ namespace Catch { } void defaultListListeners( std::ostream& out, - std::vector const& descriptions ) { + std::vector const& descriptions, + Verbosity verbosity ) { + if ( verbosity == Verbosity::Quiet ) { + for ( auto const& desc : descriptions ) { + out << desc.name << '\n'; + } + return; + } + out << "Registered listeners:\n"; if(descriptions.empty()) { @@ -176,7 +184,14 @@ namespace Catch { void defaultListTags( std::ostream& out, std::vector const& tags, - bool isFiltered ) { + bool isFiltered, + Verbosity verbosity ) { + if (verbosity == Verbosity::Quiet) { + for (auto const& tagCount : tags) { + out << tagCount.all() << '\n'; + } + return; + } if ( isFiltered ) { out << "Tags for matching test cases:\n"; } else { @@ -195,7 +210,7 @@ namespace Catch { return lhs.count < rhs.count; } ) ->count; - + // more padding necessary for 3+ digits if (maxTagCount >= 100) { auto numDigits = 1 + std::floor( std::log10( maxTagCount ) ); diff --git a/src/catch2/reporters/catch_reporter_helpers.hpp b/src/catch2/reporters/catch_reporter_helpers.hpp index 316cb404..46988888 100644 --- a/src/catch2/reporters/catch_reporter_helpers.hpp +++ b/src/catch2/reporters/catch_reporter_helpers.hpp @@ -55,7 +55,8 @@ namespace Catch { * format */ void defaultListListeners( std::ostream& out, - std::vector const& descriptions ); + std::vector const& descriptions, + Verbosity verbosity ); /** * Lists tag information to the provided stream in user-friendly format @@ -64,7 +65,10 @@ namespace Catch { * bases. The output should be backwards compatible with the output of * Catch2 v2 binaries. */ - void defaultListTags( std::ostream& out, std::vector const& tags, bool isFiltered ); + void defaultListTags( std::ostream& out, + std::vector const& tags, + bool isFiltered, + Verbosity verbosity ); /** * Lists test case information to the provided stream in user-friendly diff --git a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp index 86ba1175..edf7f3fd 100644 --- a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp @@ -54,7 +54,7 @@ TEST_CASE( "The default listing implementation write to provided stream", SECTION( "Listing tags" ) { std::vector tags(1); tags[0].add("fakeTag"_catch_sr); - Catch::defaultListTags(sstream.stream(), tags, false); + Catch::defaultListTags(sstream.stream(), tags, false, Catch::Verbosity::Normal); auto listingString = sstream.str(); REQUIRE_THAT(listingString, ContainsSubstring("[fakeTag]"s)); @@ -87,7 +87,7 @@ TEST_CASE( "The default listing implementation write to provided stream", std::vector listeners( { { "fakeListener"_catch_sr, "fake description" } } ); - Catch::defaultListListeners( sstream.stream(), listeners ); + Catch::defaultListListeners( sstream.stream(), listeners, Catch::Verbosity::Normal ); auto listingString = sstream.str(); REQUIRE_THAT( listingString, ContainsSubstring( "fakeListener"s ) &&