mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-04 14:25:40 +02:00
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
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user