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/internal/catch_errno_guard.hpp>
|
||||||
#include <catch2/reporters/catch_reporter_bases.hpp>
|
#include <catch2/reporters/catch_reporter_bases.hpp>
|
||||||
#include <catch2/internal/catch_stream.hpp>
|
#include <catch2/internal/catch_stream.hpp>
|
||||||
|
#include <catch2/catch_config.hpp>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
@ -70,4 +71,12 @@ namespace Catch {
|
|||||||
StreamingReporterBase::~StreamingReporterBase() = default;
|
StreamingReporterBase::~StreamingReporterBase() = default;
|
||||||
CumulativeReporterBase::~CumulativeReporterBase() = 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
|
} // end namespace Catch
|
||||||
|
@ -241,16 +241,14 @@ namespace Catch {
|
|||||||
ReporterPreferences m_reporterPrefs;
|
ReporterPreferences m_reporterPrefs;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<char C>
|
struct lineOfChars {
|
||||||
char const* getLineOfChars() {
|
char c;
|
||||||
static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
|
constexpr lineOfChars(char c):
|
||||||
if( !*line ) {
|
c(c)
|
||||||
std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
|
{}
|
||||||
line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
|
|
||||||
}
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
friend std::ostream& operator<< (std::ostream& out, lineOfChars value);
|
||||||
|
};
|
||||||
|
|
||||||
struct TestEventListenerBase : StreamingReporterBase {
|
struct TestEventListenerBase : StreamingReporterBase {
|
||||||
TestEventListenerBase( ReporterConfig const& _config );
|
TestEventListenerBase( ReporterConfig const& _config );
|
||||||
|
@ -300,7 +300,7 @@ public:
|
|||||||
}
|
}
|
||||||
m_os << headerCols << '\n';
|
m_os << headerCols << '\n';
|
||||||
|
|
||||||
m_os << Catch::getLineOfChars<'-'>() << '\n';
|
m_os << lineOfChars('-') << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void close() {
|
void close() {
|
||||||
@ -519,7 +519,7 @@ void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ConsoleReporter::lazyPrintRunInfo() {
|
void ConsoleReporter::lazyPrintRunInfo() {
|
||||||
stream << '\n' << getLineOfChars<'~'>() << '\n';
|
stream << '\n' << lineOfChars('~') << '\n';
|
||||||
Colour colour(Colour::SecondaryText);
|
Colour colour(Colour::SecondaryText);
|
||||||
stream << currentTestRunInfo->name
|
stream << currentTestRunInfo->name
|
||||||
<< " is a Catch v" << libraryVersion() << " host application.\n"
|
<< " is a Catch v" << libraryVersion() << " host application.\n"
|
||||||
@ -553,18 +553,18 @@ void ConsoleReporter::printTestCaseAndSectionHeader() {
|
|||||||
SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
|
SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
|
||||||
|
|
||||||
|
|
||||||
stream << getLineOfChars<'-'>() << '\n';
|
stream << lineOfChars('-') << '\n';
|
||||||
Colour colourGuard(Colour::FileName);
|
Colour colourGuard(Colour::FileName);
|
||||||
stream << lineInfo << '\n';
|
stream << lineInfo << '\n';
|
||||||
stream << getLineOfChars<'.'>() << '\n' << std::endl;
|
stream << lineOfChars('.') << '\n' << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleReporter::printClosedHeader(std::string const& _name) {
|
void ConsoleReporter::printClosedHeader(std::string const& _name) {
|
||||||
printOpenHeader(_name);
|
printOpenHeader(_name);
|
||||||
stream << getLineOfChars<'.'>() << '\n';
|
stream << lineOfChars('.') << '\n';
|
||||||
}
|
}
|
||||||
void ConsoleReporter::printOpenHeader(std::string const& _name) {
|
void ConsoleReporter::printOpenHeader(std::string const& _name) {
|
||||||
stream << getLineOfChars<'-'>() << '\n';
|
stream << lineOfChars('-') << '\n';
|
||||||
{
|
{
|
||||||
Colour colourGuard(Colour::Headers);
|
Colour colourGuard(Colour::Headers);
|
||||||
printHeaderString(_name);
|
printHeaderString(_name);
|
||||||
@ -676,7 +676,7 @@ void ConsoleReporter::printTotalsDivider(Totals const& totals) {
|
|||||||
stream << '\n';
|
stream << '\n';
|
||||||
}
|
}
|
||||||
void ConsoleReporter::printSummaryDivider() {
|
void ConsoleReporter::printSummaryDivider() {
|
||||||
stream << getLineOfChars<'-'>() << '\n';
|
stream << lineOfChars('-') << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleReporter::printTestFilters() {
|
void ConsoleReporter::printTestFilters() {
|
||||||
|
@ -22,7 +22,7 @@ namespace Catch {
|
|||||||
i = 0;
|
i = 0;
|
||||||
os << Column(_string)
|
os << Column(_string)
|
||||||
.indent(indent + i)
|
.indent(indent + i)
|
||||||
.initialIndent(indent) << "\n";
|
.initialIndent(indent) << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string escape(std::string const& str) {
|
std::string escape(std::string const& str) {
|
||||||
@ -152,20 +152,20 @@ namespace Catch {
|
|||||||
assert(!m_sectionStack.empty());
|
assert(!m_sectionStack.empty());
|
||||||
|
|
||||||
if (m_sectionStack.size() > 1) {
|
if (m_sectionStack.size() > 1) {
|
||||||
os << getLineOfChars<'-'>() << '\n';
|
os << lineOfChars('-') << '\n';
|
||||||
|
|
||||||
std::vector<SectionInfo>::const_iterator
|
std::vector<SectionInfo>::const_iterator
|
||||||
it = m_sectionStack.begin() + 1, // Skip first section (test case)
|
it = m_sectionStack.begin() + 1, // Skip first section (test case)
|
||||||
itEnd = m_sectionStack.end();
|
itEnd = m_sectionStack.end();
|
||||||
for (; it != itEnd; ++it)
|
for (; it != itEnd; ++it)
|
||||||
printHeaderString(os, it->name);
|
printHeaderString(os, it->name);
|
||||||
os << getLineOfChars<'-'>() << '\n';
|
os << lineOfChars('-') << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
|
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
|
||||||
|
|
||||||
os << lineInfo << '\n';
|
os << lineInfo << '\n';
|
||||||
os << getLineOfChars<'.'>() << "\n\n";
|
os << lineOfChars('.') << "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
Loading…
Reference in New Issue
Block a user