mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-03 21:49:32 +01:00 
			
		
		
		
	Use StringRef in more places in reporters
This commit is contained in:
		@@ -171,7 +171,7 @@ namespace Catch {
 | 
			
		||||
                               .width( CATCH_CONFIG_CONSOLE_WIDTH - 10 );
 | 
			
		||||
            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) {
 | 
			
		||||
@@ -207,9 +207,9 @@ namespace Catch {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isFiltered) {
 | 
			
		||||
            out << pluralise(tests.size(), "matching test case");
 | 
			
		||||
            out << pluralise(tests.size(), "matching test case"_sr);
 | 
			
		||||
        } else {
 | 
			
		||||
            out << pluralise(tests.size(), "test case");
 | 
			
		||||
            out << pluralise(tests.size(), "test case"_sr);
 | 
			
		||||
        }
 | 
			
		||||
        out << "\n\n" << std::flush;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -62,25 +62,25 @@ void printTotals(std::ostream& out, const Totals& totals) {
 | 
			
		||||
            bothOrAll(totals.assertions.failed) : StringRef{};
 | 
			
		||||
        out <<
 | 
			
		||||
            "Failed " << bothOrAll(totals.testCases.failed)
 | 
			
		||||
            << pluralise(totals.testCases.failed, "test case") << ", "
 | 
			
		||||
            << pluralise(totals.testCases.failed, "test case"_sr) << ", "
 | 
			
		||||
            "failed " << qualify_assertions_failed <<
 | 
			
		||||
            pluralise(totals.assertions.failed, "assertion") << '.';
 | 
			
		||||
            pluralise(totals.assertions.failed, "assertion"_sr) << '.';
 | 
			
		||||
    } else if (totals.assertions.total() == 0) {
 | 
			
		||||
        out <<
 | 
			
		||||
            "Passed " << bothOrAll(totals.testCases.total())
 | 
			
		||||
            << pluralise(totals.testCases.total(), "test case")
 | 
			
		||||
            << pluralise(totals.testCases.total(), "test case"_sr)
 | 
			
		||||
            << " (no assertions).";
 | 
			
		||||
    } else if (totals.assertions.failed) {
 | 
			
		||||
        Colour colour(Colour::ResultError);
 | 
			
		||||
        out <<
 | 
			
		||||
            "Failed " << pluralise(totals.testCases.failed, "test case") << ", "
 | 
			
		||||
            "failed " << pluralise(totals.assertions.failed, "assertion") << '.';
 | 
			
		||||
            "Failed " << pluralise(totals.testCases.failed, "test case"_sr) << ", "
 | 
			
		||||
            "failed " << pluralise(totals.assertions.failed, "assertion"_sr) << '.';
 | 
			
		||||
    } else {
 | 
			
		||||
        Colour colour(Colour::ResultSuccess);
 | 
			
		||||
        out <<
 | 
			
		||||
            "Passed " << bothOrAll(totals.testCases.passed)
 | 
			
		||||
            << pluralise(totals.testCases.passed, "test case") <<
 | 
			
		||||
            " with " << pluralise(totals.assertions.passed, "assertion") << '.';
 | 
			
		||||
            << pluralise(totals.testCases.passed, "test case"_sr) <<
 | 
			
		||||
            " with " << pluralise(totals.assertions.passed, "assertion"_sr) << '.';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -227,7 +227,7 @@ private:
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            Colour colourGuard(colour);
 | 
			
		||||
            stream << " with " << pluralise(N, "message") << ':';
 | 
			
		||||
            stream << " with " << pluralise(N, "message"_sr) << ':';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        while (itMessage != itEnd) {
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,7 @@ public:
 | 
			
		||||
        switch (result.getResultType()) {
 | 
			
		||||
        case ResultWas::Ok:
 | 
			
		||||
            colour = Colour::Success;
 | 
			
		||||
            passOrFail = "PASSED";
 | 
			
		||||
            passOrFail = "PASSED"_sr;
 | 
			
		||||
            //if( result.hasMessage() )
 | 
			
		||||
            if (_stats.infoMessages.size() == 1)
 | 
			
		||||
                messageLabel = "with message";
 | 
			
		||||
@@ -66,10 +66,10 @@ public:
 | 
			
		||||
        case ResultWas::ExpressionFailed:
 | 
			
		||||
            if (result.isOk()) {
 | 
			
		||||
                colour = Colour::Success;
 | 
			
		||||
                passOrFail = "FAILED - but was ok";
 | 
			
		||||
                passOrFail = "FAILED - but was ok"_sr;
 | 
			
		||||
            } else {
 | 
			
		||||
                colour = Colour::Error;
 | 
			
		||||
                passOrFail = "FAILED";
 | 
			
		||||
                passOrFail = "FAILED"_sr;
 | 
			
		||||
            }
 | 
			
		||||
            if (_stats.infoMessages.size() == 1)
 | 
			
		||||
                messageLabel = "with message";
 | 
			
		||||
@@ -78,7 +78,7 @@ public:
 | 
			
		||||
            break;
 | 
			
		||||
        case ResultWas::ThrewException:
 | 
			
		||||
            colour = Colour::Error;
 | 
			
		||||
            passOrFail = "FAILED";
 | 
			
		||||
            passOrFail = "FAILED"_sr;
 | 
			
		||||
            messageLabel = "due to unexpected exception with ";
 | 
			
		||||
            if (_stats.infoMessages.size() == 1)
 | 
			
		||||
                messageLabel += "message";
 | 
			
		||||
@@ -87,12 +87,12 @@ public:
 | 
			
		||||
            break;
 | 
			
		||||
        case ResultWas::FatalErrorCondition:
 | 
			
		||||
            colour = Colour::Error;
 | 
			
		||||
            passOrFail = "FAILED";
 | 
			
		||||
            passOrFail = "FAILED"_sr;
 | 
			
		||||
            messageLabel = "due to a fatal error condition";
 | 
			
		||||
            break;
 | 
			
		||||
        case ResultWas::DidntThrowException:
 | 
			
		||||
            colour = Colour::Error;
 | 
			
		||||
            passOrFail = "FAILED";
 | 
			
		||||
            passOrFail = "FAILED"_sr;
 | 
			
		||||
            messageLabel = "because no exception was thrown where one was expected";
 | 
			
		||||
            break;
 | 
			
		||||
        case ResultWas::Info:
 | 
			
		||||
@@ -102,7 +102,7 @@ public:
 | 
			
		||||
            messageLabel = "warning";
 | 
			
		||||
            break;
 | 
			
		||||
        case ResultWas::ExplicitFailure:
 | 
			
		||||
            passOrFail = "FAILED";
 | 
			
		||||
            passOrFail = "FAILED"_sr;
 | 
			
		||||
            colour = Colour::Error;
 | 
			
		||||
            if (_stats.infoMessages.size() == 1)
 | 
			
		||||
                messageLabel = "explicitly with message";
 | 
			
		||||
@@ -113,7 +113,7 @@ public:
 | 
			
		||||
        case ResultWas::Unknown:
 | 
			
		||||
        case ResultWas::FailureBit:
 | 
			
		||||
        case ResultWas::Exception:
 | 
			
		||||
            passOrFail = "** internal error **";
 | 
			
		||||
            passOrFail = "** internal error **"_sr;
 | 
			
		||||
            colour = Colour::Error;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
@@ -171,7 +171,7 @@ private:
 | 
			
		||||
    AssertionStats const& stats;
 | 
			
		||||
    AssertionResult const& result;
 | 
			
		||||
    Colour::Code colour;
 | 
			
		||||
    std::string passOrFail;
 | 
			
		||||
    StringRef passOrFail;
 | 
			
		||||
    std::string messageLabel;
 | 
			
		||||
    std::string message;
 | 
			
		||||
    std::vector<MessageInfo> messages;
 | 
			
		||||
@@ -603,8 +603,8 @@ void ConsoleReporter::printTotals( Totals const& totals ) {
 | 
			
		||||
    } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) {
 | 
			
		||||
        stream << Colour(Colour::ResultSuccess) << "All tests passed";
 | 
			
		||||
        stream << " ("
 | 
			
		||||
            << pluralise(totals.assertions.passed, "assertion") << " in "
 | 
			
		||||
            << pluralise(totals.testCases.passed, "test case") << ')'
 | 
			
		||||
            << pluralise(totals.assertions.passed, "assertion"_sr) << " in "
 | 
			
		||||
            << pluralise(totals.testCases.passed, "test case"_sr) << ')'
 | 
			
		||||
            << '\n';
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
@@ -622,11 +622,11 @@ void ConsoleReporter::printTotals( Totals const& totals ) {
 | 
			
		||||
                          .addRow(totals.testCases.failedButOk)
 | 
			
		||||
                          .addRow(totals.assertions.failedButOk));
 | 
			
		||||
 | 
			
		||||
        printSummaryRow("test cases", columns, 0);
 | 
			
		||||
        printSummaryRow("assertions", columns, 1);
 | 
			
		||||
        printSummaryRow("test cases"_sr, columns, 0);
 | 
			
		||||
        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) {
 | 
			
		||||
        std::string value = col.rows[row];
 | 
			
		||||
        if (col.label.empty()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ namespace Catch {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        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 printSummaryDivider();
 | 
			
		||||
 
 | 
			
		||||
@@ -168,7 +168,7 @@ namespace Catch {
 | 
			
		||||
 | 
			
		||||
                {
 | 
			
		||||
                    Colour colourGuard(colour);
 | 
			
		||||
                    stream << " with " << pluralise(N, "message") << ':';
 | 
			
		||||
                    stream << " with " << pluralise(N, "message"_sr) << ':';
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                for (; itMessage != itEnd; ) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user