mirror of
https://github.com/catchorg/Catch2.git
synced 2025-01-16 07:08:01 +00:00
Compare commits
2 Commits
f2b9508081
...
392e44ec21
Author | SHA1 | Date | |
---|---|---|---|
|
392e44ec21 | ||
|
317145514f |
@ -39,6 +39,14 @@ namespace Catch {
|
||||
return os.write(str.data(), str.size());
|
||||
}
|
||||
|
||||
std::string operator+(StringRef lhs, StringRef rhs) {
|
||||
std::string ret;
|
||||
ret.reserve(lhs.size() + rhs.size());
|
||||
ret += lhs;
|
||||
ret += rhs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
|
||||
lhs.append(rhs.data(), rhs.size());
|
||||
return lhs;
|
||||
|
@ -101,6 +101,7 @@ namespace Catch {
|
||||
|
||||
friend std::string& operator += (std::string& lhs, StringRef const& sr);
|
||||
friend std::ostream& operator << (std::ostream& os, StringRef const& sr);
|
||||
friend std::string operator+(StringRef lhs, StringRef rhs);
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,27 +7,27 @@
|
||||
|
||||
#include <catch2/reporters/catch_reporter_compact.hpp>
|
||||
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_console_colour.hpp>
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace {
|
||||
|
||||
#ifdef CATCH_PLATFORM_MAC
|
||||
const char* failedString() { return "FAILED"; }
|
||||
const char* passedString() { return "PASSED"; }
|
||||
#else
|
||||
const char* failedString() { return "failed"; }
|
||||
const char* passedString() { return "passed"; }
|
||||
#endif
|
||||
|
||||
// Colour::LightGrey
|
||||
Catch::Colour::Code dimColour() { return Catch::Colour::FileName; }
|
||||
|
||||
std::string bothOrAll( std::size_t count ) {
|
||||
return count == 1 ? std::string() :
|
||||
count == 2 ? "both " : "all " ;
|
||||
Catch::StringRef bothOrAll( std::size_t count ) {
|
||||
switch (count) {
|
||||
case 1:
|
||||
return Catch::StringRef{};
|
||||
case 2:
|
||||
return "both "_catch_sr;
|
||||
default:
|
||||
return "all "_catch_sr;
|
||||
}
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
@ -35,6 +35,15 @@ namespace {
|
||||
|
||||
namespace Catch {
|
||||
namespace {
|
||||
|
||||
#ifdef CATCH_PLATFORM_MAC
|
||||
static constexpr Catch::StringRef compactFailedString = "FAILED"_sr;
|
||||
static constexpr Catch::StringRef compactPassedString = "PASSED"_sr;
|
||||
#else
|
||||
static constexpr Catch::StringRef compactFailedString = "failed"_sr;
|
||||
static constexpr Catch::StringRef compactPassedString = "passed"_sr;
|
||||
#endif
|
||||
|
||||
// Colour, message variants:
|
||||
// - white: No tests ran.
|
||||
// - red: Failed [both/all] N test cases, failed [both/all] M assertions.
|
||||
@ -46,9 +55,9 @@ void printTotals(std::ostream& out, const Totals& totals) {
|
||||
out << "No tests ran.";
|
||||
} else if (totals.testCases.failed == totals.testCases.total()) {
|
||||
Colour colour(Colour::ResultError);
|
||||
const std::string qualify_assertions_failed =
|
||||
const StringRef qualify_assertions_failed =
|
||||
totals.assertions.failed == totals.assertions.total() ?
|
||||
bothOrAll(totals.assertions.failed) : std::string();
|
||||
bothOrAll(totals.assertions.failed) : StringRef{};
|
||||
out <<
|
||||
"Failed " << bothOrAll(totals.testCases.failed)
|
||||
<< pluralise(totals.testCases.failed, "test case") << ", "
|
||||
@ -92,7 +101,7 @@ public:
|
||||
|
||||
switch (result.getResultType()) {
|
||||
case ResultWas::Ok:
|
||||
printResultType(Colour::ResultSuccess, passedString());
|
||||
printResultType(Colour::ResultSuccess, compactPassedString);
|
||||
printOriginalExpression();
|
||||
printReconstructedExpression();
|
||||
if (!result.hasExpression())
|
||||
@ -102,45 +111,45 @@ public:
|
||||
break;
|
||||
case ResultWas::ExpressionFailed:
|
||||
if (result.isOk())
|
||||
printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok"));
|
||||
printResultType(Colour::ResultSuccess, compactFailedString + " - but was ok"_sr);
|
||||
else
|
||||
printResultType(Colour::Error, failedString());
|
||||
printResultType(Colour::Error, compactFailedString);
|
||||
printOriginalExpression();
|
||||
printReconstructedExpression();
|
||||
printRemainingMessages();
|
||||
break;
|
||||
case ResultWas::ThrewException:
|
||||
printResultType(Colour::Error, failedString());
|
||||
printResultType(Colour::Error, compactFailedString);
|
||||
printIssue("unexpected exception with message:");
|
||||
printMessage();
|
||||
printExpressionWas();
|
||||
printRemainingMessages();
|
||||
break;
|
||||
case ResultWas::FatalErrorCondition:
|
||||
printResultType(Colour::Error, failedString());
|
||||
printResultType(Colour::Error, compactFailedString);
|
||||
printIssue("fatal error condition with message:");
|
||||
printMessage();
|
||||
printExpressionWas();
|
||||
printRemainingMessages();
|
||||
break;
|
||||
case ResultWas::DidntThrowException:
|
||||
printResultType(Colour::Error, failedString());
|
||||
printResultType(Colour::Error, compactFailedString);
|
||||
printIssue("expected exception, got none");
|
||||
printExpressionWas();
|
||||
printRemainingMessages();
|
||||
break;
|
||||
case ResultWas::Info:
|
||||
printResultType(Colour::None, "info");
|
||||
printResultType(Colour::None, "info"_sr);
|
||||
printMessage();
|
||||
printRemainingMessages();
|
||||
break;
|
||||
case ResultWas::Warning:
|
||||
printResultType(Colour::None, "warning");
|
||||
printResultType(Colour::None, "warning"_sr);
|
||||
printMessage();
|
||||
printRemainingMessages();
|
||||
break;
|
||||
case ResultWas::ExplicitFailure:
|
||||
printResultType(Colour::Error, failedString());
|
||||
printResultType(Colour::Error, compactFailedString);
|
||||
printIssue("explicitly");
|
||||
printRemainingMessages(Colour::None);
|
||||
break;
|
||||
@ -159,7 +168,7 @@ private:
|
||||
stream << result.getSourceInfo() << ':';
|
||||
}
|
||||
|
||||
void printResultType(Colour::Code colour, std::string const& passOrFail) const {
|
||||
void printResultType(Colour::Code colour, StringRef passOrFail) const {
|
||||
if (!passOrFail.empty()) {
|
||||
{
|
||||
Colour colourGuard(colour);
|
||||
@ -169,7 +178,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void printIssue(std::string const& issue) const {
|
||||
void printIssue(char const* issue) const {
|
||||
stream << ' ' << issue;
|
||||
}
|
||||
|
||||
|
@ -1289,6 +1289,10 @@ String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringre
|
||||
String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11
|
||||
String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringref" == "a stringref"
|
||||
String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11
|
||||
String.tests.cpp:<line number>: passed: lhs == "some string += the stringref contents" for: "some string += the stringref contents"
|
||||
==
|
||||
"some string += the stringref contents"
|
||||
String.tests.cpp:<line number>: passed: together == "abrakadabra" for: "abrakadabra" == "abrakadabra"
|
||||
String.tests.cpp:<line number>: passed: with 1 message: 'empty.size() == 0'
|
||||
String.tests.cpp:<line number>: passed: with 1 message: 'empty.begin() == empty.end()'
|
||||
String.tests.cpp:<line number>: passed: with 1 message: 'stringref.size() == 3'
|
||||
|
@ -1381,5 +1381,5 @@ due to unexpected exception with message:
|
||||
|
||||
===============================================================================
|
||||
test cases: 337 | 263 passed | 70 failed | 4 failed as expected
|
||||
assertions: 1924 | 1772 passed | 131 failed | 21 failed as expected
|
||||
assertions: 1926 | 1774 passed | 131 failed | 21 failed as expected
|
||||
|
||||
|
@ -9449,6 +9449,32 @@ String.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
11 == 11
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef
|
||||
std::string += StringRef
|
||||
-------------------------------------------------------------------------------
|
||||
String.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( lhs == "some string += the stringref contents" )
|
||||
with expansion:
|
||||
"some string += the stringref contents"
|
||||
==
|
||||
"some string += the stringref contents"
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef
|
||||
StringRef + StringRef
|
||||
-------------------------------------------------------------------------------
|
||||
String.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( together == "abrakadabra" )
|
||||
with expansion:
|
||||
"abrakadabra" == "abrakadabra"
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef at compilation time
|
||||
Simple constructors
|
||||
@ -15033,5 +15059,5 @@ Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 337 | 247 passed | 86 failed | 4 failed as expected
|
||||
assertions: 1941 | 1772 passed | 148 failed | 21 failed as expected
|
||||
assertions: 1943 | 1774 passed | 148 failed | 21 failed as expected
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1942" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1944" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@ -1145,6 +1145,8 @@ Matchers.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/from std::string/assigned" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/to std::string/explicitly constructed" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/to std::string/assigned" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/std::string += StringRef" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/StringRef + StringRef" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef at compilation time/Simple constructors" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef at compilation time/UDL construction" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}"/>
|
||||
|
@ -155,6 +155,8 @@
|
||||
<testCase name="StringRef/from std::string/assigned" duration="{duration}"/>
|
||||
<testCase name="StringRef/to std::string/explicitly constructed" duration="{duration}"/>
|
||||
<testCase name="StringRef/to std::string/assigned" duration="{duration}"/>
|
||||
<testCase name="StringRef/std::string += StringRef" duration="{duration}"/>
|
||||
<testCase name="StringRef/StringRef + StringRef" duration="{duration}"/>
|
||||
<testCase name="StringRef at compilation time/Simple constructors" duration="{duration}"/>
|
||||
<testCase name="StringRef at compilation time/UDL construction" duration="{duration}"/>
|
||||
</file>
|
||||
|
@ -2491,6 +2491,10 @@ ok {test-number} - stdStr.size() == sr.size() for: 11 == 11
|
||||
ok {test-number} - stdStr == "a stringref" for: "a stringref" == "a stringref"
|
||||
# StringRef
|
||||
ok {test-number} - stdStr.size() == sr.size() for: 11 == 11
|
||||
# StringRef
|
||||
ok {test-number} - lhs == "some string += the stringref contents" for: "some string += the stringref contents" == "some string += the stringref contents"
|
||||
# StringRef
|
||||
ok {test-number} - together == "abrakadabra" for: "abrakadabra" == "abrakadabra"
|
||||
# StringRef at compilation time
|
||||
ok {test-number} - with 1 message: 'empty.size() == 0'
|
||||
# StringRef at compilation time
|
||||
@ -3874,5 +3878,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..1933
|
||||
1..1935
|
||||
|
||||
|
@ -11724,6 +11724,30 @@ Message from section two
|
||||
</Section>
|
||||
<OverallResults successes="2" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="std::string += StringRef" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
lhs == "some string += the stringref contents"
|
||||
</Original>
|
||||
<Expanded>
|
||||
"some string += the stringref contents"
|
||||
==
|
||||
"some string += the stringref contents"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="StringRef + StringRef" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
together == "abrakadabra"
|
||||
</Original>
|
||||
<Expanded>
|
||||
"abrakadabra" == "abrakadabra"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="StringRef at compilation time" tags="[constexpr][StringRef][Strings]" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
@ -18031,7 +18055,7 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1772" failures="149" expectedFailures="21"/>
|
||||
<OverallResults successes="1774" failures="149" expectedFailures="21"/>
|
||||
</Group>
|
||||
<OverallResults successes="1772" failures="148" expectedFailures="21"/>
|
||||
<OverallResults successes="1774" failures="148" expectedFailures="21"/>
|
||||
</Catch>
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <cstring>
|
||||
|
||||
TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
|
||||
using Catch::StringRef;
|
||||
|
||||
SECTION( "Empty string" ) {
|
||||
@ -123,6 +122,18 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("std::string += StringRef") {
|
||||
StringRef sr = "the stringref contents";
|
||||
std::string lhs("some string += ");
|
||||
lhs += sr;
|
||||
REQUIRE(lhs == "some string += the stringref contents");
|
||||
}
|
||||
SECTION("StringRef + StringRef") {
|
||||
StringRef sr1 = "abraka", sr2 = "dabra";
|
||||
std::string together = sr1 + sr2;
|
||||
REQUIRE(together == "abrakadabra");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
|
||||
|
Loading…
Reference in New Issue
Block a user