mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
Make StringRef's operator std::string explicit
This way it is explicit when there is a `StringRef` -> `std::string` conversion and makes it easier to look for allocations that could be avoided. Doing this has already removed one allocation per registered test case, as there was a completely pointless `StringRef` -> `std::string` conversion when parsing tags of a test case.
This commit is contained in:
@@ -1043,8 +1043,6 @@ 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: stdStr == "a stringref" for: "a stringref" == "a stringref"
|
||||
String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11
|
||||
ToStringChrono.tests.cpp:<line number>: passed: minute == seconds for: 1 m == 60 s
|
||||
ToStringChrono.tests.cpp:<line number>: passed: hour != seconds for: 1 h != 60 s
|
||||
ToStringChrono.tests.cpp:<line number>: passed: micro != milli for: 1 us != 1 ms
|
||||
|
@@ -1381,5 +1381,5 @@ due to unexpected exception with message:
|
||||
|
||||
===============================================================================
|
||||
test cases: 300 | 226 passed | 70 failed | 4 failed as expected
|
||||
assertions: 1559 | 1407 passed | 131 failed | 21 failed as expected
|
||||
assertions: 1557 | 1405 passed | 131 failed | 21 failed as expected
|
||||
|
||||
|
@@ -7783,24 +7783,6 @@ String.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
17 == 17
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef
|
||||
to std::string
|
||||
implicitly constructed
|
||||
-------------------------------------------------------------------------------
|
||||
String.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( stdStr == "a stringref" )
|
||||
with expansion:
|
||||
"a stringref" == "a stringref"
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( stdStr.size() == sr.size() )
|
||||
with expansion:
|
||||
11 == 11
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef
|
||||
to std::string
|
||||
@@ -12462,5 +12444,5 @@ Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 300 | 210 passed | 86 failed | 4 failed as expected
|
||||
assertions: 1576 | 1407 passed | 148 failed | 21 failed as expected
|
||||
assertions: 1574 | 1405 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="1577" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1575" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@@ -726,7 +726,6 @@ Matchers.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/from std::string/implicitly constructed" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/from std::string/explicitly constructed" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/from std::string/assigned" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/to std::string/implicitly constructed" 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="Stringifying std::chrono::duration helpers" time="{duration}"/>
|
||||
|
@@ -9601,28 +9601,6 @@ Message from section two
|
||||
</Section>
|
||||
<OverallResults successes="2" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="to std::string" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Section name="implicitly constructed" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
stdStr == "a stringref"
|
||||
</Original>
|
||||
<Expanded>
|
||||
"a stringref" == "a stringref"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
stdStr.size() == sr.size()
|
||||
</Original>
|
||||
<Expanded>
|
||||
11 == 11
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="2" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<OverallResults successes="2" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="to std::string" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Section name="explicitly constructed" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
@@ -14834,7 +14812,7 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1407" failures="149" expectedFailures="21"/>
|
||||
<OverallResults successes="1405" failures="149" expectedFailures="21"/>
|
||||
</Group>
|
||||
<OverallResults successes="1407" failures="148" expectedFailures="21"/>
|
||||
<OverallResults successes="1405" failures="148" expectedFailures="21"/>
|
||||
</Catch>
|
||||
|
@@ -142,11 +142,6 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
SECTION( "to std::string" ) {
|
||||
StringRef sr = "a stringref";
|
||||
|
||||
SECTION( "implicitly constructed" ) {
|
||||
std::string stdStr = sr;
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
SECTION( "explicitly constructed" ) {
|
||||
std::string stdStr( sr );
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
@@ -154,7 +149,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
}
|
||||
SECTION( "assigned" ) {
|
||||
std::string stdStr;
|
||||
stdStr = sr;
|
||||
stdStr = static_cast<std::string>(sr);
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
|
Reference in New Issue
Block a user