Skip to content

Patch >2-digit tag-count padding in base reporter #2963

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/catch2/reporters/catch_reporter_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <ostream>
#include <iomanip>
Expand Down Expand Up @@ -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<size_t>( 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 )
Expand Down