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.
  • Loading branch information
Sergio Losilla committed Jun 2, 2022
1 parent 0f44d83 commit 9bf2eae
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/catch2/reporters/catch_reporter_combined_tu.cpp
Expand Up @@ -154,29 +154,32 @@ namespace Catch {

void defaultListListeners( std::ostream& out,
std::vector<ListenerDescription> const& descriptions ) {
const auto maxNameLen =
std::max_element( descriptions.begin(),
descriptions.end(),
[]( ListenerDescription const& lhs,
ListenerDescription const& rhs ) {
return lhs.name.size() < rhs.name.size();
} )
->name.size();

out << "Registered listeners:\n";
for ( auto const& desc : descriptions ) {
out << TextFlow::Column( static_cast<std::string>( desc.name ) +
':' )
.indent( 2 )
.width( maxNameLen + 5 ) +
TextFlow::Column( desc.description )
.initialIndent( 0 )
.indent( 2 )
.width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen - 8 )
<< '\n';
}

out << '\n' << std::flush;
if(!descriptions.empty()) {
const auto maxNameLen =
std::max_element( descriptions.begin(),
descriptions.end(),
[]( ListenerDescription const& lhs,
ListenerDescription const& rhs ) {
return lhs.name.size() < rhs.name.size();
} )
->name.size();

for ( auto const& desc : descriptions ) {
out << TextFlow::Column( static_cast<std::string>( desc.name ) +
':' )
.indent( 2 )
.width( maxNameLen + 5 ) +
TextFlow::Column( desc.description )
.initialIndent( 0 )
.indent( 2 )
.width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen - 8 )
<< '\n';
}

out << '\n' << std::flush;
}
}

void defaultListTags( std::ostream& out,
Expand Down

0 comments on commit 9bf2eae

Please sign in to comment.