Skip to content

Commit

Permalink
Fix crash when running with --list-listeners and no registered listen…
Browse files Browse the repository at this point in the history
…ers (#2442)

Co-authored-by: Sergio Losilla <sergio.losilla@nt-bnct.com>
  • Loading branch information
loximann and Sergio Losilla committed Jun 2, 2022
1 parent 40dd9dd commit 5efd327
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/catch2/reporters/catch_reporter_combined_tu.cpp
Expand Up @@ -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(),
Expand All @@ -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 ) +
':' )
Expand Down
5 changes: 4 additions & 1 deletion tests/ExtraTests/CMakeLists.txt
Expand Up @@ -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
Expand Down

0 comments on commit 5efd327

Please sign in to comment.