Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add quiet verbosity variant to the default listener and tag listing

Commit
a404f37cec56e6ff161db9b26cfb1e77de3bc1e0
Author
Martin Hořeňovský ·
Parents
29c9844f688a

Files · Download .tar.gz

Changes

 docs/command-line.md                                |  5 +++--
 src/catch2/reporters/catch_reporter_common_base.cpp |  6 +++---
 src/catch2/reporters/catch_reporter_helpers.cpp     | 21 ++++++++++++++++++---
 src/catch2/reporters/catch_reporter_helpers.hpp     |  8 ++++++--
 .../SelfTest/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`                        |
+
 
 <a id="sending-output-to-a-file"></a>
 ## 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<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
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<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 ) );
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<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
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<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 ) &&