2
0
mirror of https://github.com/catchorg/Catch2 synced 2026-02-23 04:12:15 +00:00

Add quiet verbosity variant to the default listener and tag listing

This commit is contained in:
Martin Hořeňovský
2026-02-16 22:51:27 +01:00
parent 29c9844f68
commit a404f37cec
5 changed files with 32 additions and 12 deletions

View File

@@ -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` |
<a id="sending-output-to-a-file"></a>
## Sending output to a file

View File

@@ -26,12 +26,12 @@ namespace Catch {
void ReporterBase::listReporters(
std::vector<ReporterDescription> const& descriptions ) {
defaultListReporters(m_stream, descriptions, m_config->verbosity());
defaultListReporters( m_stream, descriptions, m_config->verbosity() );
}
void ReporterBase::listListeners(
std::vector<ListenerDescription> const& descriptions ) {
defaultListListeners( m_stream, descriptions );
defaultListListeners( m_stream, descriptions, m_config->verbosity() );
}
void ReporterBase::listTests(std::vector<TestCaseHandle> const& tests) {
@@ -43,7 +43,7 @@ namespace Catch {
}
void ReporterBase::listTags(std::vector<TagInfo> const& tags) {
defaultListTags( m_stream, tags, m_config->hasTestFilters() );
defaultListTags( m_stream, tags, m_config->hasTestFilters(), m_config->verbosity() );
}
} // namespace Catch

View File

@@ -143,7 +143,15 @@ namespace Catch {
}
void defaultListListeners( std::ostream& out,
std::vector<ListenerDescription> const& descriptions ) {
std::vector<ListenerDescription> 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<TagInfo> 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 ) );

View File

@@ -55,7 +55,8 @@ namespace Catch {
* format
*/
void defaultListListeners( std::ostream& out,
std::vector<ListenerDescription> const& descriptions );
std::vector<ListenerDescription> 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<TagInfo> const& tags, bool isFiltered );
void defaultListTags( std::ostream& out,
std::vector<TagInfo> const& tags,
bool isFiltered,
Verbosity verbosity );
/**
* Lists test case information to the provided stream in user-friendly

View File

@@ -54,7 +54,7 @@ TEST_CASE( "The default listing implementation write to provided stream",
SECTION( "Listing tags" ) {
std::vector<Catch::TagInfo> 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<Catch::ListenerDescription> 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 ) &&