From dc18c0556d6c0ee5fe83750cae41f77365582310 Mon Sep 17 00:00:00 2001 From: Nic Ramage Date: Mon, 26 Jul 2021 13:15:15 +0200 Subject: [PATCH] Do not assume that CATCH_CONFIG_CONSOLE_WIDTH is always a constant --- include/internal/catch_list.cpp | 6 ++++-- include/reporters/catch_reporter_bases.hpp | 5 +++-- include/reporters/catch_reporter_console.cpp | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/internal/catch_list.cpp b/include/internal/catch_list.cpp index 9f748e4c..593eb1c4 100644 --- a/include/internal/catch_list.cpp +++ b/include/internal/catch_list.cpp @@ -120,6 +120,7 @@ namespace Catch { } } + auto consoleWidth = static_cast (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 (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; diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index 7f0f15db..f3c43657 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -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 (CATCH_CONFIG_CONSOLE_WIDTH); + std::memset( line, C, consoleWidth-1 ); + line[consoleWidth-1] = 0; } return line; } diff --git a/include/reporters/catch_reporter_console.cpp b/include/reporters/catch_reporter_console.cpp index 4f74ccb3..880075ad 100644 --- a/include/reporters/catch_reporter_console.cpp +++ b/include/reporters/catch_reporter_console.cpp @@ -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 (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 { + auto consoleWidth = static_cast (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 (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'; }