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

Fix crash when running with --list-listeners and no registered listeners (#2442)

Co-authored-by: Sergio Losilla <sergio.losilla@nt-bnct.com>
Commit
5efd327dd4a638f63396ff22e908f16a8d6b9f20
Author
Sergio Losilla ·
Committer
GitHub
Parents
40dd9dd3f4cb

Files · Download .tar.gz

Changes

 src/catch2/reporters/catch_reporter_combined_tu.cpp | 7 ++++++-
 tests/ExtraTests/CMakeLists.txt                     | 5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp
index 06259433..2d6e112c 100644
--- a/src/catch2/reporters/catch_reporter_combined_tu.cpp
+++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp
@@ -154,6 +154,12 @@ namespace Catch {
 
     void defaultListListeners( std::ostream& out,
                                std::vector<ListenerDescription> const& descriptions ) {
+        out << "Registered listeners:\n";
+
+        if(descriptions.empty()) {
+            return;
+        }
+
         const auto maxNameLen =
             std::max_element( descriptions.begin(),
                               descriptions.end(),
@@ -163,7 +169,6 @@ namespace Catch {
                               } )
                 ->name.size();
 
-        out << "Registered listeners:\n";
         for ( auto const& desc : descriptions ) {
             out << TextFlow::Column( static_cast<std::string>( desc.name ) +
                                      ':' )
diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index e533ad4a..f33bd7c1 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -459,7 +459,10 @@ add_test(
   NAME TestSpecs::OverrideFailureWithEmptySpec
   COMMAND $<TARGET_FILE:NoTests> --allow-running-no-tests
 )
-
+add_test(
+  NAME List::Listeners::WorksWithoutRegisteredListeners
+  COMMAND $<TARGET_FILE:NoTests> --list-listeners
+)
 set( EXTRA_TEST_BINARIES
     PrefixedMacros
     DisabledMacros