mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Replace getLineOfChars with non-templated, runtime version
This commit is contained in:
parent
f64487bf70
commit
04cbbb8a4b
@ -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
|
||||
|
@ -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 );
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user