Patch >2-digit tag-count padding in base reporter #2963
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello beautiful Catch2 team!
This PR patches a minor formatting bug in the base reporter due to this line in
catch_reporter_helpers.cpp
, which includes:Passing the CLI argument
--list-tags
outputs a list like:However, the width of the tag-count column was previously hardcoded to
2
(as per the line above), such that the formatting broke (with the tag names awkwardly misaligned/displaced) for 3+ digit tag counts. This occurred whenever a tag contains one hundred or more tests (like in my use-case for scientific software tests), and would result in formatting like:This patch pre-computes the maximum number of digits among the tag counts, expanding the padding when there are more than 100 tests in a tag (and handling when tags are empty). It now outputs e.g.
I have endeavoured to replicate the format of
clang-format
, modelled from a code snippet just above the diff performing a similar chore (defaultListListeners
choosing the padding of the listener name column). Note I used an explicitsize_t
type overauto
for the "main" variablemaxTagCountLen
to inform thestatic_cast
, necessarily becausestd::floor
returns a non-integral type (e.g.double
) which cannot be passed tostd::setw
.This abominable MWE can be used to generate many same-tag tests to check the formatting:
Previously this MWE would erroneously output:
but under this patch, now outputs:
Finally, invoking no macros correctly outputs:
All things considered, this solves an extremely minor issue, but I'm thrilled in any case to be able to give back to a project I adore!
Tyson