Add test for overriding the fallback stringifier

This commit is contained in:
Martin Hořeňovský 2018-02-15 15:12:19 +01:00
parent bb84f0788a
commit c0267e5c20
6 changed files with 60 additions and 18 deletions

View File

@ -988,6 +988,7 @@ ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( item
ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( item ) == "StringMaker<has_maker_and_operator>" for: "StringMaker<has_maker_and_operator>" ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( item ) == "StringMaker<has_maker_and_operator>" for: "StringMaker<has_maker_and_operator>"
== ==
"StringMaker<has_maker_and_operator>" "StringMaker<has_maker_and_operator>"
ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(item) == "{ !!! }" for: "{ !!! }" == "{ !!! }"
ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( item ) == "operator<<( has_operator )" for: "operator<<( has_operator )" ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( item ) == "operator<<( has_operator )" for: "operator<<( has_operator )"
== ==
"operator<<( has_operator )" "operator<<( has_operator )"
@ -1002,7 +1003,7 @@ ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(string
== ==
"stringmaker(streamable_range)" "stringmaker(streamable_range)"
ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(just_range{}) == "{ 1, 2, 3, 4 }" for: "{ 1, 2, 3, 4 }" == "{ 1, 2, 3, 4 }" ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(just_range{}) == "{ 1, 2, 3, 4 }" for: "{ 1, 2, 3, 4 }" == "{ 1, 2, 3, 4 }"
ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(disabled_range{}) == "{?}" for: "{?}" == "{?}" ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }" for: "{ !!! }" == "{ !!! }"
ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" for: "{ StringMaker<has_maker> }" ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" for: "{ StringMaker<has_maker> }"
== ==
"{ StringMaker<has_maker> }" "{ StringMaker<has_maker> }"

View File

@ -1064,6 +1064,6 @@ with expansion:
"first" == "second" "first" == "second"
=============================================================================== ===============================================================================
test cases: 199 | 148 passed | 47 failed | 4 failed as expected test cases: 200 | 149 passed | 47 failed | 4 failed as expected
assertions: 1004 | 878 passed | 105 failed | 21 failed as expected assertions: 1005 | 879 passed | 105 failed | 21 failed as expected

View File

@ -7890,6 +7890,18 @@ with expansion:
== ==
"StringMaker<has_maker_and_operator>" "StringMaker<has_maker_and_operator>"
-------------------------------------------------------------------------------
stringify( has_neither )
-------------------------------------------------------------------------------
ToStringWhich.tests.cpp:<line number>
...............................................................................
ToStringWhich.tests.cpp:<line number>:
PASSED:
REQUIRE( ::Catch::Detail::stringify(item) == "{ !!! }" )
with expansion:
"{ !!! }" == "{ !!! }"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
stringify( has_operator ) stringify( has_operator )
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -7982,9 +7994,9 @@ with expansion:
ToStringWhich.tests.cpp:<line number>: ToStringWhich.tests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( ::Catch::Detail::stringify(disabled_range{}) == "{?}" ) REQUIRE( ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }" )
with expansion: with expansion:
"{?}" == "{?}" "{ !!! }" == "{ !!! }"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
toString( vectors<has_maker> ) toString( vectors<has_maker> )
@ -8499,6 +8511,6 @@ Misc.tests.cpp:<line number>:
PASSED: PASSED:
=============================================================================== ===============================================================================
test cases: 199 | 134 passed | 61 failed | 4 failed as expected test cases: 200 | 135 passed | 61 failed | 4 failed as expected
assertions: 1015 | 874 passed | 120 failed | 21 failed as expected assertions: 1016 | 875 passed | 120 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="106" tests="1016" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="15" failures="106" tests="1017" 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="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
@ -822,6 +822,7 @@ Tricky.tests.cpp:<line number>
</testcase> </testcase>
<testcase classname="<exe-name>.global" name="stringify( has_maker )" time="{duration}"/> <testcase classname="<exe-name>.global" name="stringify( has_maker )" time="{duration}"/>
<testcase classname="<exe-name>.global" name="stringify( has_maker_and_toString )" time="{duration}"/> <testcase classname="<exe-name>.global" name="stringify( has_maker_and_toString )" time="{duration}"/>
<testcase classname="<exe-name>.global" name="stringify( has_neither )" time="{duration}"/>
<testcase classname="<exe-name>.global" name="stringify( has_operator )" time="{duration}"/> <testcase classname="<exe-name>.global" name="stringify( has_operator )" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString on const wchar_t const pointer returns the string contents" time="{duration}"/> <testcase classname="<exe-name>.global" name="toString on const wchar_t const pointer returns the string contents" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString on const wchar_t pointer returns the string contents" time="{duration}"/> <testcase classname="<exe-name>.global" name="toString on const wchar_t pointer returns the string contents" time="{duration}"/>

View File

@ -8755,6 +8755,17 @@ loose text artifact
</Expression> </Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="stringify( has_neither )" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
<Original>
::Catch::Detail::stringify(item) == "{ !!! }"
</Original>
<Expanded>
"{ !!! }" == "{ !!! }"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="stringify( has_operator )" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" > <TestCase name="stringify( has_operator )" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
<Original> <Original>
@ -8843,10 +8854,10 @@ loose text artifact
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
<Original> <Original>
::Catch::Detail::stringify(disabled_range{}) == "{?}" ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }"
</Original> </Original>
<Expanded> <Expanded>
"{?}" == "{?}" "{ !!! }" == "{ !!! }"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
@ -9358,7 +9369,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="874" failures="121" expectedFailures="21"/> <OverallResults successes="875" failures="121" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="874" failures="120" expectedFailures="21"/> <OverallResults successes="875" failures="120" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -1,13 +1,25 @@
#include "catch.hpp"
/* /*
Demonstrate which version of toString/StringMaker is being used * Demonstrate which version of toString/StringMaker is being used
for various types * for various types
*/ */
// Replace fallback stringifier for this TU
// We should avoid ODR violations because these specific types aren't
// present in different TUs
#include <string>
template <typename T>
std::string fallbackStringifier(T const&) {
return "{ !!! }";
}
#define CATCH_CONFIG_FALLBACK_STRINGIFIER fallbackStringifier
#include "catch.hpp"
struct has_operator { }; struct has_operator { };
struct has_maker {}; struct has_maker {};
struct has_maker_and_operator {}; struct has_maker_and_operator {};
struct has_neither {};
std::ostream& operator<<(std::ostream& os, const has_operator&) { std::ostream& operator<<(std::ostream& os, const has_operator&) {
os << "operator<<( has_operator )"; os << "operator<<( has_operator )";
@ -52,6 +64,12 @@ TEST_CASE( "stringify( has_maker_and_toString )", "[.][toString]" ) {
REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker<has_maker_and_operator>" ); REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker<has_maker_and_operator>" );
} }
TEST_CASE("stringify( has_neither )", "[toString]") {
has_neither item;
REQUIRE( ::Catch::Detail::stringify(item) == "{ !!! }" );
}
// Vectors... // Vectors...
// Don't run this in approval tests as it is sensitive to two phase lookup differences // Don't run this in approval tests as it is sensitive to two phase lookup differences
@ -65,7 +83,6 @@ TEST_CASE( "toString( vectors<has_maker> )", "[toString]" ) {
REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" ); REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" );
} }
// Don't run this in approval tests as it is sensitive to two phase lookup differences // Don't run this in approval tests as it is sensitive to two phase lookup differences
TEST_CASE( "toString( vectors<has_maker_and_operator> )", "[toString]" ) { TEST_CASE( "toString( vectors<has_maker_and_operator> )", "[toString]" ) {
std::vector<has_maker_and_operator> v(1); std::vector<has_maker_and_operator> v(1);
@ -142,5 +159,5 @@ TEST_CASE("toString streamable range", "[toString]") {
REQUIRE(::Catch::Detail::stringify(streamable_range{}) == "op<<(streamable_range)"); REQUIRE(::Catch::Detail::stringify(streamable_range{}) == "op<<(streamable_range)");
REQUIRE(::Catch::Detail::stringify(stringmaker_range{}) == "stringmaker(streamable_range)"); REQUIRE(::Catch::Detail::stringify(stringmaker_range{}) == "stringmaker(streamable_range)");
REQUIRE(::Catch::Detail::stringify(just_range{}) == "{ 1, 2, 3, 4 }"); REQUIRE(::Catch::Detail::stringify(just_range{}) == "{ 1, 2, 3, 4 }");
REQUIRE(::Catch::Detail::stringify(disabled_range{}) == "{?}"); REQUIRE(::Catch::Detail::stringify(disabled_range{}) == "{ !!! }");
} }