From 04cbbb8a4b2c1cb0d833d2f989a3555cb2e8d744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 10 May 2020 20:59:59 +0200 Subject: [PATCH] Replace getLineOfChars with non-templated, runtime version --- src/catch2/reporters/catch_reporter_bases.cpp | 9 +++++++++ src/catch2/reporters/catch_reporter_bases.hpp | 16 +++++++--------- src/catch2/reporters/catch_reporter_console.cpp | 14 +++++++------- src/catch2/reporters/catch_reporter_teamcity.cpp | 8 ++++---- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/catch2/reporters/catch_reporter_bases.cpp b/src/catch2/reporters/catch_reporter_bases.cpp index f0343a19..e716167d 100644 --- a/src/catch2/reporters/catch_reporter_bases.cpp +++ b/src/catch2/reporters/catch_reporter_bases.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -70,4 +71,12 @@ namespace Catch { StreamingReporterBase::~StreamingReporterBase() = default; CumulativeReporterBase::~CumulativeReporterBase() = default; + + std::ostream& operator<<(std::ostream& out, lineOfChars value) { + for (size_t idx = 0; idx < CATCH_CONFIG_CONSOLE_WIDTH - 1; ++idx) { + out.put(value.c); + } + return out; + } + } // end namespace Catch diff --git a/src/catch2/reporters/catch_reporter_bases.hpp b/src/catch2/reporters/catch_reporter_bases.hpp index 181b34ec..128362a3 100644 --- a/src/catch2/reporters/catch_reporter_bases.hpp +++ b/src/catch2/reporters/catch_reporter_bases.hpp @@ -241,16 +241,14 @@ namespace Catch { ReporterPreferences m_reporterPrefs; }; - template - char const* getLineOfChars() { - static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; - if( !*line ) { - std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); - line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; - } - return line; - } + struct lineOfChars { + char c; + constexpr lineOfChars(char c): + c(c) + {} + friend std::ostream& operator<< (std::ostream& out, lineOfChars value); + }; struct TestEventListenerBase : StreamingReporterBase { TestEventListenerBase( ReporterConfig const& _config ); diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index e9bea0ee..848d519c 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -300,7 +300,7 @@ public: } m_os << headerCols << '\n'; - m_os << Catch::getLineOfChars<'-'>() << '\n'; + m_os << lineOfChars('-') << '\n'; } } void close() { @@ -519,7 +519,7 @@ void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() { } } void ConsoleReporter::lazyPrintRunInfo() { - stream << '\n' << getLineOfChars<'~'>() << '\n'; + stream << '\n' << lineOfChars('~') << '\n'; Colour colour(Colour::SecondaryText); stream << currentTestRunInfo->name << " is a Catch v" << libraryVersion() << " host application.\n" @@ -553,18 +553,18 @@ void ConsoleReporter::printTestCaseAndSectionHeader() { SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; - stream << getLineOfChars<'-'>() << '\n'; + stream << lineOfChars('-') << '\n'; Colour colourGuard(Colour::FileName); stream << lineInfo << '\n'; - stream << getLineOfChars<'.'>() << '\n' << std::endl; + stream << lineOfChars('.') << '\n' << std::endl; } void ConsoleReporter::printClosedHeader(std::string const& _name) { printOpenHeader(_name); - stream << getLineOfChars<'.'>() << '\n'; + stream << lineOfChars('.') << '\n'; } void ConsoleReporter::printOpenHeader(std::string const& _name) { - stream << getLineOfChars<'-'>() << '\n'; + stream << lineOfChars('-') << '\n'; { Colour colourGuard(Colour::Headers); printHeaderString(_name); @@ -676,7 +676,7 @@ void ConsoleReporter::printTotalsDivider(Totals const& totals) { stream << '\n'; } void ConsoleReporter::printSummaryDivider() { - stream << getLineOfChars<'-'>() << '\n'; + stream << lineOfChars('-') << '\n'; } void ConsoleReporter::printTestFilters() { diff --git a/src/catch2/reporters/catch_reporter_teamcity.cpp b/src/catch2/reporters/catch_reporter_teamcity.cpp index c25707a1..bab27bef 100644 --- a/src/catch2/reporters/catch_reporter_teamcity.cpp +++ b/src/catch2/reporters/catch_reporter_teamcity.cpp @@ -22,7 +22,7 @@ namespace Catch { i = 0; os << Column(_string) .indent(indent + i) - .initialIndent(indent) << "\n"; + .initialIndent(indent) << '\n'; } std::string escape(std::string const& str) { @@ -152,20 +152,20 @@ namespace Catch { assert(!m_sectionStack.empty()); if (m_sectionStack.size() > 1) { - os << getLineOfChars<'-'>() << '\n'; + os << lineOfChars('-') << '\n'; std::vector::const_iterator it = m_sectionStack.begin() + 1, // Skip first section (test case) itEnd = m_sectionStack.end(); for (; it != itEnd; ++it) printHeaderString(os, it->name); - os << getLineOfChars<'-'>() << '\n'; + os << lineOfChars('-') << '\n'; } SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; os << lineInfo << '\n'; - os << getLineOfChars<'.'>() << "\n\n"; + os << lineOfChars('.') << "\n\n"; } } // end namespace Catch