Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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