diff options
| author | Martin Hořeňovský | 2021-10-25 15:10:35 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-10-25 15:21:28 +0200 |
| commit | 905bf438ae4358d1e6b9fb99be40f868589d0857 (patch) | |
| tree | aa35e86f965a4142b76233738499a2e461d58d54 /src/catch2 | |
| parent | 0fdee1c27362f18f2769ba13d9a2f74823b3b8c4 (diff) | |
| download | catch3-905bf438ae4358d1e6b9fb99be40f868589d0857.tar.gz | |
Fix bad indentation calculation in the console reporter
The problem came from the console reporter trying to provide a
fancy linebreaking (primarily for things like `SCENARIO` or the
BDD macros), so that new lines start with extra indentation if
the text being line broken starts as "{text}: ".
The console reporter did not properly take into account cases
where the ": " part would already be in a later line, in which
case it would ask for non-sensical level of indentation (larger
than single line length).
We fixed this by also enforcing that the special indentation case
only triggers if the ": " is found early enough in the line, so
that we also avoid degenerate cases like this:
```
blablabla: F
a
n
c
y
.
.
.
```
Fixes #2309
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/reporters/catch_reporter_console.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index 5c8b6ec7..a1890897 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -559,15 +559,37 @@ void ConsoleReporter::printOpenHeader(std::string const& _name) { } } -// if string has a : in first line will set indent to follow it on -// subsequent lines void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) { - std::size_t i = _string.find(": "); - if (i != std::string::npos) - i += 2; - else - i = 0; - stream << TextFlow::Column(_string).indent(indent + i).initialIndent(indent) << '\n'; + // We want to get a bit fancy with line breaking here, so that subsequent + // lines start after ":" if one is present, e.g. + // ``` + // blablabla: Fancy + // linebreaking + // ``` + // but we also want to avoid problems with overly long indentation causing + // the text to take up too many lines, e.g. + // ``` + // blablabla: F + // a + // n + // c + // y + // . + // . + // . + // ``` + // So we limit the prefix indentation check to first quarter of the possible + // width + std::size_t idx = _string.find( ": " ); + if ( idx != std::string::npos && idx < CATCH_CONFIG_CONSOLE_WIDTH / 4 ) { + idx += 2; + } else { + idx = 0; + } + stream << TextFlow::Column( _string ) + .indent( indent + idx ) + .initialIndent( indent ) + << '\n'; } struct SummaryColumn { |