Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Replace getLineOfChars with non-templated, runtime version

Commit
04cbbb8a4b2c1cb0d833d2f989a3555cb2e8d744
Author
Martin Hořeňovský ·
Parents
f64487bf7074

Files · Download .tar.gz

Changes

 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 <catch2/internal/catch_errno_guard.hpp>
 #include <catch2/reporters/catch_reporter_bases.hpp>
 #include <catch2/internal/catch_stream.hpp>
+#include <catch2/catch_config.hpp>
 
 #include <cstring>
 #include <cfloat>
@@ -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 C>
-    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<SectionInfo>::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