Added << ostream overload to StringRef

This commit is contained in:
Phil Nash 2017-08-14 08:50:44 +01:00
parent bb8c1fb17f
commit fa3535e95e
5 changed files with 54 additions and 92 deletions

View File

@ -173,7 +173,7 @@ namespace Catch {
return StringRef( lhs ) + rhs; return StringRef( lhs ) + rhs;
} }
std::ostream& operator << ( std::ostream& os, StringRef const& str ) { auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
return os << str.c_str(); return os << str.c_str();
} }

View File

@ -9,6 +9,7 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <iosfwd>
namespace Catch { namespace Catch {
@ -76,7 +77,9 @@ namespace Catch {
auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> String; auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> String;
auto operator + ( StringRef const& lhs, char const* rhs ) -> String; auto operator + ( StringRef const& lhs, char const* rhs ) -> String;
auto operator + ( char const* lhs, StringRef const& rhs ) -> String; auto operator + ( char const* lhs, StringRef const& rhs ) -> String;
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
} // namespace Catch } // namespace Catch
#endif // CATCH_STRINGREF_H_INCLUDED #endif // CATCH_STRINGREF_H_INCLUDED

View File

@ -4378,7 +4378,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s == "hello" ) REQUIRE( s == "hello" )
with expansion: with expansion:
{?} == "hello" hello == "hello"
StringBuilder.tests.cpp:<line number>: StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
@ -4397,7 +4397,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s == "hello world" ) REQUIRE( s == "hello world" )
with expansion: with expansion:
{?} == "hello world" hello world == "hello world"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
StringBuilder StringBuilder
@ -4410,7 +4410,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s == "hello world" ) REQUIRE( s == "hello world" )
with expansion: with expansion:
{?} == "hello world" hello world == "hello world"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
StringBuilder StringBuilder
@ -4435,7 +4435,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s == "hello world" ) REQUIRE( s == "hello world" )
with expansion: with expansion:
{?} == "hello world" hello world == "hello world"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
StringBuilder StringBuilder
@ -4449,7 +4449,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s2 == s ) REQUIRE( s2 == s )
with expansion: with expansion:
{?} == {?} hello == hello
StringBuilder.tests.cpp:<line number>: StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
@ -4469,7 +4469,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s2 == "hello" ) REQUIRE( s2 == "hello" )
with expansion: with expansion:
{?} == "hello" hello == "hello"
StringBuilder.tests.cpp:<line number>: StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
@ -4489,7 +4489,7 @@ StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( s2 == "hello" ) REQUIRE( s2 == "hello" )
with expansion: with expansion:
{?} == "hello" hello == "hello"
StringBuilder.tests.cpp:<line number>: StringBuilder.tests.cpp:<line number>:
PASSED: PASSED:
@ -4589,32 +4589,11 @@ StringRef.tests.cpp:<line number>
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( original == "original" ) REQUIRE( original == "original" )
with expansion:
{?} == "original"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>: FAILED:
PASSED:
REQUIRE( isSubstring( original ) ) REQUIRE( isSubstring( original ) )
with expansion: with expansion:
true false
StringRef.tests.cpp:<line number>:
PASSED:
REQUIRE( isOwned( original ) == false )
with expansion:
false == false
StringRef.tests.cpp:<line number>:
PASSED:
REQUIRE( isSubstring( original ) == false )
with expansion:
false == false
StringRef.tests.cpp:<line number>:
PASSED:
REQUIRE( isOwned( original ) )
with expansion:
true
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
StringRef StringRef
@ -4646,7 +4625,7 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( ss == "hello" ) REQUIRE( ss == "hello" )
with expansion: with expansion:
{?} == "hello" hello == "hello"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
StringRef StringRef
@ -4757,13 +4736,13 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( StringRef("hello") == StringRef("hello") ) REQUIRE( StringRef("hello") == StringRef("hello") )
with expansion: with expansion:
{?} == {?} hello == hello
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( StringRef("hello") != StringRef("cello") ) REQUIRE( StringRef("hello") != StringRef("cello") )
with expansion: with expansion:
{?} != {?} hello != cello
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
StringRef StringRef
@ -4777,13 +4756,13 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( copied == "hot potato" ) REQUIRE( copied == "hot potato" )
with expansion: with expansion:
{?} == "hot potato" hot potato == "hot potato"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( str == "hot potato" ) REQUIRE( str == "hot potato" )
with expansion: with expansion:
{?} == "hot potato" hot potato == "hot potato"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
@ -4809,7 +4788,7 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( copied == "hot potato" ) REQUIRE( copied == "hot potato" )
with expansion: with expansion:
{?} == "hot potato" hot potato == "hot potato"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
@ -4841,7 +4820,7 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( sr == "a standard string" ) REQUIRE( sr == "a standard string" )
with expansion: with expansion:
{?} == "a standard string" a standard string == "a standard string"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
@ -4861,7 +4840,7 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( sr == "a standard string" ) REQUIRE( sr == "a standard string" )
with expansion: with expansion:
{?} == "a standard string" a standard string == "a standard string"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
@ -4881,7 +4860,7 @@ StringRef.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( sr == "a standard string" ) REQUIRE( sr == "a standard string" )
with expansion: with expansion:
{?} == "a standard string" a standard string == "a standard string"
StringRef.tests.cpp:<line number>: StringRef.tests.cpp:<line number>:
PASSED: PASSED:
@ -7758,6 +7737,6 @@ MiscTests.cpp:<line number>:
PASSED: PASSED:
=============================================================================== ===============================================================================
test cases: 183 | 130 passed | 49 failed | 4 failed as expected test cases: 183 | 129 passed | 50 failed | 4 failed as expected
assertions: 913 | 791 passed | 101 failed | 21 failed as expected assertions: 910 | 787 passed | 102 failed | 21 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="15" failures="87" tests="914" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="15" failures="88" tests="911" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}"> <testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
<error type="TEST_CASE"> <error type="TEST_CASE">
@ -518,7 +518,11 @@ MatchersTests.cpp:<line number>
<testcase classname="<exe-name>.global" name="StringRef/Empty string" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/Empty string" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/From string literal" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/From string literal" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/From string literal/c_str() does not cause copy" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/From string literal/c_str() does not cause copy" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/From sub-string" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/From sub-string" time="{duration}">
<failure message="false" type="REQUIRE">
StringRef.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/zero-based substring" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/Substrings/zero-based substring" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/c_str() causes copy" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/Substrings/c_str() causes copy" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/non-zero-based substring" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/Substrings/non-zero-based substring" time="{duration}"/>

View File

@ -4999,7 +4999,7 @@ Message from section two
s == "hello" s == "hello"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello" hello == "hello"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" >
@ -5018,7 +5018,7 @@ Message from section two
s == "hello world" s == "hello world"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello world" hello world == "hello world"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
@ -5029,7 +5029,7 @@ Message from section two
s == "hello world" s == "hello world"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello world" hello world == "hello world"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
@ -5056,7 +5056,7 @@ Message from section two
s == "hello world" s == "hello world"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello world" hello world == "hello world"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/> <OverallResults successes="3" failures="0" expectedFailures="0"/>
@ -5068,7 +5068,7 @@ Message from section two
s2 == s s2 == s
</Original> </Original>
<Expanded> <Expanded>
{?} == {?} hello == hello
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" >
@ -5090,7 +5090,7 @@ Message from section two
s2 == "hello" s2 == "hello"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello" hello == "hello"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" >
@ -5112,7 +5112,7 @@ Message from section two
s2 == "hello" s2 == "hello"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello" hello == "hello"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringBuilder.tests.cpp" >
@ -5225,42 +5225,18 @@ Message from section two
original == "original" original == "original"
</Original> </Original>
<Expanded> <Expanded>
{?} == "original" original == "original"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="false" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
<Original> <Original>
isSubstring( original ) isSubstring( original )
</Original> </Original>
<Expanded> <Expanded>
true false
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <OverallResults successes="1" failures="1" expectedFailures="0"/>
<Original>
isOwned( original ) == false
</Original>
<Expanded>
false == false
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
<Original>
isSubstring( original ) == false
</Original>
<Expanded>
false == false
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
<Original>
isOwned( original )
</Original>
<Expanded>
true
</Expanded>
</Expression>
<OverallResults successes="5" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="Substrings" filename="projects/<exe-name>/StringRef.tests.cpp" > <Section name="Substrings" filename="projects/<exe-name>/StringRef.tests.cpp" >
<Section name="zero-based substring" filename="projects/<exe-name>/StringRef.tests.cpp" > <Section name="zero-based substring" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5293,7 +5269,7 @@ Message from section two
ss == "hello" ss == "hello"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hello" hello == "hello"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="4" failures="0" expectedFailures="0"/> <OverallResults successes="4" failures="0" expectedFailures="0"/>
@ -5418,7 +5394,7 @@ Message from section two
StringRef("hello") == StringRef("hello") StringRef("hello") == StringRef("hello")
</Original> </Original>
<Expanded> <Expanded>
{?} == {?} hello == hello
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5426,7 +5402,7 @@ Message from section two
StringRef("hello") != StringRef("cello") StringRef("hello") != StringRef("cello")
</Original> </Original>
<Expanded> <Expanded>
{?} != {?} hello != cello
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/> <OverallResults successes="2" failures="0" expectedFailures="0"/>
@ -5438,7 +5414,7 @@ Message from section two
copied == "hot potato" copied == "hot potato"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hot potato" hot potato == "hot potato"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5446,7 +5422,7 @@ Message from section two
str == "hot potato" str == "hot potato"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hot potato" hot potato == "hot potato"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5476,7 +5452,7 @@ Message from section two
copied == "hot potato" copied == "hot potato"
</Original> </Original>
<Expanded> <Expanded>
{?} == "hot potato" hot potato == "hot potato"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5514,7 +5490,7 @@ Message from section two
sr == "a standard string" sr == "a standard string"
</Original> </Original>
<Expanded> <Expanded>
{?} == "a standard string" a standard string == "a standard string"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5536,7 +5512,7 @@ Message from section two
sr == "a standard string" sr == "a standard string"
</Original> </Original>
<Expanded> <Expanded>
{?} == "a standard string" a standard string == "a standard string"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5558,7 +5534,7 @@ Message from section two
sr == "a standard string" sr == "a standard string"
</Original> </Original>
<Expanded> <Expanded>
{?} == "a standard string" a standard string == "a standard string"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/StringRef.tests.cpp" >
@ -5639,7 +5615,7 @@ Message from section two
</Section> </Section>
<OverallResults successes="2" failures="0" expectedFailures="0"/> <OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="Tabs and newlines show in output" tags="[.][failing][hide][whitespace]" filename="projects/<exe-name>/MiscTests.cpp" > <TestCase name="Tabs and newlines show in output" tags="[.][failing][hide][whitespace]" filename="projects/<exe-name>/MiscTests.cpp" >
<Expression success="false" type="CHECK" filename="projects/<exe-name>/MiscTests.cpp" > <Expression success="false" type="CHECK" filename="projects/<exe-name>/MiscTests.cpp" >
@ -8592,7 +8568,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="791" failures="102" expectedFailures="21"/> <OverallResults successes="787" failures="103" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="791" failures="101" expectedFailures="21"/> <OverallResults successes="787" failures="102" expectedFailures="21"/>
</Catch> </Catch>