Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-05-10 20:59:59 +0200
committerMartin Hořeňovský2020-05-10 23:52:38 +0200
commit04cbbb8a4b2c1cb0d833d2f989a3555cb2e8d744 (patch)
treeec2ba7737f6ece66ae6aede2f9993cf66c08236d /src
parentf64487bf7074eeb5247479f3896807d38059fc9a (diff)
downloadcatch3-04cbbb8a4b2c1cb0d833d2f989a3555cb2e8d744.tar.gz
Replace getLineOfChars with non-templated, runtime version
Diffstat (limited to 'src')
-rw-r--r--src/catch2/reporters/catch_reporter_bases.cpp9
-rw-r--r--src/catch2/reporters/catch_reporter_bases.hpp16
-rw-r--r--src/catch2/reporters/catch_reporter_console.cpp14
-rw-r--r--src/catch2/reporters/catch_reporter_teamcity.cpp8
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