diff --git a/src/catch2/reporters/catch_reporter_helpers.cpp b/src/catch2/reporters/catch_reporter_helpers.cpp index ffb32ffb0b..c710ac43ce 100644 --- a/src/catch2/reporters/catch_reporter_helpers.cpp +++ b/src/catch2/reporters/catch_reporter_helpers.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -182,9 +183,29 @@ namespace Catch { out << "All available tags:\n"; } + // minimum whitespace to pad tag counts, possibly overwritten below + size_t maxTagCountLen = 2; + + // determine necessary padding for tag count column + if ( ! tags.empty() ) { + const auto maxTagCount = + std::max_element( tags.begin(), + tags.end(), + []( auto const& lhs, auto const& rhs ) { + return lhs.count < rhs.count; + } ) + ->count; + + // more padding necessary for 3+ digits + if (maxTagCount >= 100) { + auto numDigits = 1 + std::floor( std::log10( maxTagCount ) ); + maxTagCountLen = static_cast( numDigits ); + } + } + for ( auto const& tagCount : tags ) { ReusableStringStream rss; - rss << " " << std::setw( 2 ) << tagCount.count << " "; + rss << " " << std::setw( maxTagCountLen ) << tagCount.count << " "; auto str = rss.str(); auto wrapper = TextFlow::Column( tagCount.all() ) .initialIndent( 0 )