mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-16 10:42:25 +01:00
Do not assume that CATCH_CONFIG_CONSOLE_WIDTH is always a constant
This commit is contained in:
parent
a9bbc42e9c
commit
dc18c0556d
@ -120,6 +120,7 @@ namespace Catch {
|
||||
}
|
||||
}
|
||||
|
||||
auto consoleWidth = static_cast<size_t> (CATCH_CONFIG_CONSOLE_WIDTH);
|
||||
for( auto const& tagCount : tagCounts ) {
|
||||
ReusableStringStream rss;
|
||||
rss << " " << std::setw(2) << tagCount.second.count << " ";
|
||||
@ -127,7 +128,7 @@ namespace Catch {
|
||||
auto wrapper = Column( tagCount.second.all() )
|
||||
.initialIndent( 0 )
|
||||
.indent( str.size() )
|
||||
.width( CATCH_CONFIG_CONSOLE_WIDTH-10 );
|
||||
.width( consoleWidth-10 );
|
||||
Catch::cout() << str << wrapper << '\n';
|
||||
}
|
||||
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
|
||||
@ -141,6 +142,7 @@ namespace Catch {
|
||||
for( auto const& factoryKvp : factories )
|
||||
maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
|
||||
|
||||
auto consoleWidth = static_cast<size_t> (CATCH_CONFIG_CONSOLE_WIDTH);
|
||||
for( auto const& factoryKvp : factories ) {
|
||||
Catch::cout()
|
||||
<< Column( factoryKvp.first + ":" )
|
||||
@ -149,7 +151,7 @@ namespace Catch {
|
||||
+ Column( factoryKvp.second->getDescription() )
|
||||
.initialIndent(0)
|
||||
.indent(2)
|
||||
.width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 )
|
||||
.width( consoleWidth - maxNameLen-8 )
|
||||
<< "\n";
|
||||
}
|
||||
Catch::cout() << std::endl;
|
||||
|
@ -264,8 +264,9 @@ namespace Catch {
|
||||
char const* getLineOfChars() {
|
||||
static char line[CATCH_CONFIG_CONSOLE_MAXIMUM_WIDTH] = {0};
|
||||
if( !*line ) {
|
||||
std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
|
||||
line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
|
||||
auto consoleWidth = static_cast<size_t> (CATCH_CONFIG_CONSOLE_WIDTH);
|
||||
std::memset( line, C, consoleWidth-1 );
|
||||
line[consoleWidth-1] = 0;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ private:
|
||||
};
|
||||
|
||||
std::size_t makeRatio(std::size_t number, std::size_t total) {
|
||||
std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
|
||||
std::size_t ratio = total > 0 ? static_cast<size_t> (CATCH_CONFIG_CONSOLE_WIDTH) * number / total : 0;
|
||||
return (ratio == 0 && number > 0) ? 1 : ratio;
|
||||
}
|
||||
|
||||
@ -350,10 +350,11 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
|
||||
: StreamingReporterBase(config),
|
||||
m_tablePrinter(new TablePrinter(config.stream(),
|
||||
[&config]() -> std::vector<ColumnInfo> {
|
||||
auto consoleWidth = static_cast<int> (CATCH_CONFIG_CONSOLE_WIDTH);
|
||||
if (config.fullConfig()->benchmarkNoAnalysis())
|
||||
{
|
||||
return{
|
||||
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
|
||||
{ "benchmark name", consoleWidth - 43, ColumnInfo::Left },
|
||||
{ " samples", 14, ColumnInfo::Right },
|
||||
{ " iterations", 14, ColumnInfo::Right },
|
||||
{ " mean", 14, ColumnInfo::Right }
|
||||
@ -362,7 +363,7 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
|
||||
else
|
||||
{
|
||||
return{
|
||||
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
|
||||
{ "benchmark name", consoleWidth - 43, ColumnInfo::Left },
|
||||
{ "samples mean std dev", 14, ColumnInfo::Right },
|
||||
{ "iterations low mean low std dev", 14, ColumnInfo::Right },
|
||||
{ "estimated high mean high std dev", 14, ColumnInfo::Right }
|
||||
@ -656,13 +657,14 @@ void ConsoleReporter::printSummaryRow(std::string const& label, std::vector<Summ
|
||||
}
|
||||
|
||||
void ConsoleReporter::printTotalsDivider(Totals const& totals) {
|
||||
auto consoleWidth = static_cast<size_t> (CATCH_CONFIG_CONSOLE_WIDTH);
|
||||
if (totals.testCases.total() > 0) {
|
||||
std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total());
|
||||
std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total());
|
||||
std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total());
|
||||
while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1)
|
||||
while (failedRatio + failedButOkRatio + passedRatio < consoleWidth - 1)
|
||||
findMax(failedRatio, failedButOkRatio, passedRatio)++;
|
||||
while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1)
|
||||
while (failedRatio + failedButOkRatio + passedRatio > consoleWidth - 1)
|
||||
findMax(failedRatio, failedButOkRatio, passedRatio)--;
|
||||
|
||||
stream << Colour(Colour::Error) << std::string(failedRatio, '=');
|
||||
@ -672,7 +674,7 @@ void ConsoleReporter::printTotalsDivider(Totals const& totals) {
|
||||
else
|
||||
stream << Colour(Colour::Success) << std::string(passedRatio, '=');
|
||||
} else {
|
||||
stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '=');
|
||||
stream << Colour(Colour::Warning) << std::string(consoleWidth - 1, '=');
|
||||
}
|
||||
stream << '\n';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user