Use StringRef in more places in reporters

This commit is contained in:
Martin Hořeňovský 2021-09-08 10:22:27 +02:00
parent cf5ccaa9df
commit 317db82396
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
5 changed files with 27 additions and 27 deletions

View File

@ -171,7 +171,7 @@ namespace Catch {
.width( CATCH_CONFIG_CONSOLE_WIDTH - 10 ); .width( CATCH_CONFIG_CONSOLE_WIDTH - 10 );
out << str << wrapper << '\n'; out << str << wrapper << '\n';
} }
out << pluralise(tags.size(), "tag") << "\n\n" << std::flush; out << pluralise(tags.size(), "tag"_sr) << "\n\n" << std::flush;
} }
void defaultListTests(std::ostream& out, std::vector<TestCaseHandle> const& tests, bool isFiltered, Verbosity verbosity) { void defaultListTests(std::ostream& out, std::vector<TestCaseHandle> const& tests, bool isFiltered, Verbosity verbosity) {
@ -207,9 +207,9 @@ namespace Catch {
} }
if (isFiltered) { if (isFiltered) {
out << pluralise(tests.size(), "matching test case"); out << pluralise(tests.size(), "matching test case"_sr);
} else { } else {
out << pluralise(tests.size(), "test case"); out << pluralise(tests.size(), "test case"_sr);
} }
out << "\n\n" << std::flush; out << "\n\n" << std::flush;
} }

View File

@ -62,25 +62,25 @@ void printTotals(std::ostream& out, const Totals& totals) {
bothOrAll(totals.assertions.failed) : StringRef{}; bothOrAll(totals.assertions.failed) : StringRef{};
out << out <<
"Failed " << bothOrAll(totals.testCases.failed) "Failed " << bothOrAll(totals.testCases.failed)
<< pluralise(totals.testCases.failed, "test case") << ", " << pluralise(totals.testCases.failed, "test case"_sr) << ", "
"failed " << qualify_assertions_failed << "failed " << qualify_assertions_failed <<
pluralise(totals.assertions.failed, "assertion") << '.'; pluralise(totals.assertions.failed, "assertion"_sr) << '.';
} else if (totals.assertions.total() == 0) { } else if (totals.assertions.total() == 0) {
out << out <<
"Passed " << bothOrAll(totals.testCases.total()) "Passed " << bothOrAll(totals.testCases.total())
<< pluralise(totals.testCases.total(), "test case") << pluralise(totals.testCases.total(), "test case"_sr)
<< " (no assertions)."; << " (no assertions).";
} else if (totals.assertions.failed) { } else if (totals.assertions.failed) {
Colour colour(Colour::ResultError); Colour colour(Colour::ResultError);
out << out <<
"Failed " << pluralise(totals.testCases.failed, "test case") << ", " "Failed " << pluralise(totals.testCases.failed, "test case"_sr) << ", "
"failed " << pluralise(totals.assertions.failed, "assertion") << '.'; "failed " << pluralise(totals.assertions.failed, "assertion"_sr) << '.';
} else { } else {
Colour colour(Colour::ResultSuccess); Colour colour(Colour::ResultSuccess);
out << out <<
"Passed " << bothOrAll(totals.testCases.passed) "Passed " << bothOrAll(totals.testCases.passed)
<< pluralise(totals.testCases.passed, "test case") << << pluralise(totals.testCases.passed, "test case"_sr) <<
" with " << pluralise(totals.assertions.passed, "assertion") << '.'; " with " << pluralise(totals.assertions.passed, "assertion"_sr) << '.';
} }
} }
@ -227,7 +227,7 @@ private:
{ {
Colour colourGuard(colour); Colour colourGuard(colour);
stream << " with " << pluralise(N, "message") << ':'; stream << " with " << pluralise(N, "message"_sr) << ':';
} }
while (itMessage != itEnd) { while (itMessage != itEnd) {

View File

@ -56,7 +56,7 @@ public:
switch (result.getResultType()) { switch (result.getResultType()) {
case ResultWas::Ok: case ResultWas::Ok:
colour = Colour::Success; colour = Colour::Success;
passOrFail = "PASSED"; passOrFail = "PASSED"_sr;
//if( result.hasMessage() ) //if( result.hasMessage() )
if (_stats.infoMessages.size() == 1) if (_stats.infoMessages.size() == 1)
messageLabel = "with message"; messageLabel = "with message";
@ -66,10 +66,10 @@ public:
case ResultWas::ExpressionFailed: case ResultWas::ExpressionFailed:
if (result.isOk()) { if (result.isOk()) {
colour = Colour::Success; colour = Colour::Success;
passOrFail = "FAILED - but was ok"; passOrFail = "FAILED - but was ok"_sr;
} else { } else {
colour = Colour::Error; colour = Colour::Error;
passOrFail = "FAILED"; passOrFail = "FAILED"_sr;
} }
if (_stats.infoMessages.size() == 1) if (_stats.infoMessages.size() == 1)
messageLabel = "with message"; messageLabel = "with message";
@ -78,7 +78,7 @@ public:
break; break;
case ResultWas::ThrewException: case ResultWas::ThrewException:
colour = Colour::Error; colour = Colour::Error;
passOrFail = "FAILED"; passOrFail = "FAILED"_sr;
messageLabel = "due to unexpected exception with "; messageLabel = "due to unexpected exception with ";
if (_stats.infoMessages.size() == 1) if (_stats.infoMessages.size() == 1)
messageLabel += "message"; messageLabel += "message";
@ -87,12 +87,12 @@ public:
break; break;
case ResultWas::FatalErrorCondition: case ResultWas::FatalErrorCondition:
colour = Colour::Error; colour = Colour::Error;
passOrFail = "FAILED"; passOrFail = "FAILED"_sr;
messageLabel = "due to a fatal error condition"; messageLabel = "due to a fatal error condition";
break; break;
case ResultWas::DidntThrowException: case ResultWas::DidntThrowException:
colour = Colour::Error; colour = Colour::Error;
passOrFail = "FAILED"; passOrFail = "FAILED"_sr;
messageLabel = "because no exception was thrown where one was expected"; messageLabel = "because no exception was thrown where one was expected";
break; break;
case ResultWas::Info: case ResultWas::Info:
@ -102,7 +102,7 @@ public:
messageLabel = "warning"; messageLabel = "warning";
break; break;
case ResultWas::ExplicitFailure: case ResultWas::ExplicitFailure:
passOrFail = "FAILED"; passOrFail = "FAILED"_sr;
colour = Colour::Error; colour = Colour::Error;
if (_stats.infoMessages.size() == 1) if (_stats.infoMessages.size() == 1)
messageLabel = "explicitly with message"; messageLabel = "explicitly with message";
@ -113,7 +113,7 @@ public:
case ResultWas::Unknown: case ResultWas::Unknown:
case ResultWas::FailureBit: case ResultWas::FailureBit:
case ResultWas::Exception: case ResultWas::Exception:
passOrFail = "** internal error **"; passOrFail = "** internal error **"_sr;
colour = Colour::Error; colour = Colour::Error;
break; break;
} }
@ -171,7 +171,7 @@ private:
AssertionStats const& stats; AssertionStats const& stats;
AssertionResult const& result; AssertionResult const& result;
Colour::Code colour; Colour::Code colour;
std::string passOrFail; StringRef passOrFail;
std::string messageLabel; std::string messageLabel;
std::string message; std::string message;
std::vector<MessageInfo> messages; std::vector<MessageInfo> messages;
@ -603,8 +603,8 @@ void ConsoleReporter::printTotals( Totals const& totals ) {
} else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) { } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) {
stream << Colour(Colour::ResultSuccess) << "All tests passed"; stream << Colour(Colour::ResultSuccess) << "All tests passed";
stream << " (" stream << " ("
<< pluralise(totals.assertions.passed, "assertion") << " in " << pluralise(totals.assertions.passed, "assertion"_sr) << " in "
<< pluralise(totals.testCases.passed, "test case") << ')' << pluralise(totals.testCases.passed, "test case"_sr) << ')'
<< '\n'; << '\n';
} else { } else {
@ -622,11 +622,11 @@ void ConsoleReporter::printTotals( Totals const& totals ) {
.addRow(totals.testCases.failedButOk) .addRow(totals.testCases.failedButOk)
.addRow(totals.assertions.failedButOk)); .addRow(totals.assertions.failedButOk));
printSummaryRow("test cases", columns, 0); printSummaryRow("test cases"_sr, columns, 0);
printSummaryRow("assertions", columns, 1); printSummaryRow("assertions"_sr, columns, 1);
} }
} }
void ConsoleReporter::printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row) { void ConsoleReporter::printSummaryRow(StringRef label, std::vector<SummaryColumn> const& cols, std::size_t row) {
for (auto col : cols) { for (auto col : cols) {
std::string value = col.rows[row]; std::string value = col.rows[row];
if (col.label.empty()) { if (col.label.empty()) {

View File

@ -59,7 +59,7 @@ namespace Catch {
void printTotals(Totals const& totals); void printTotals(Totals const& totals);
void printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row); void printSummaryRow(StringRef label, std::vector<SummaryColumn> const& cols, std::size_t row);
void printTotalsDivider(Totals const& totals); void printTotalsDivider(Totals const& totals);
void printSummaryDivider(); void printSummaryDivider();

View File

@ -168,7 +168,7 @@ namespace Catch {
{ {
Colour colourGuard(colour); Colour colourGuard(colour);
stream << " with " << pluralise(N, "message") << ':'; stream << " with " << pluralise(N, "message"_sr) << ':';
} }
for (; itMessage != itEnd; ) { for (; itMessage != itEnd; ) {