From c0267e5c20c29f61e9a9d04b1725d4a706f74cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Thu, 15 Feb 2018 15:12:19 +0100 Subject: [PATCH] Add test for overriding the fallback stringifier --- .../Baselines/compact.sw.approved.txt | 3 +- .../Baselines/console.std.approved.txt | 4 +-- .../Baselines/console.sw.approved.txt | 20 ++++++++++--- .../SelfTest/Baselines/junit.sw.approved.txt | 3 +- .../SelfTest/Baselines/xml.sw.approved.txt | 19 +++++++++--- .../UsageTests/ToStringWhich.tests.cpp | 29 +++++++++++++++---- 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 39ca4347..5569efd6 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -988,6 +988,7 @@ ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify( item ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify( item ) == "StringMaker" for: "StringMaker" == "StringMaker" +ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify(item) == "{ !!! }" for: "{ !!! }" == "{ !!! }" ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify( item ) == "operator<<( has_operator )" for: "operator<<( has_operator )" == "operator<<( has_operator )" @@ -1002,7 +1003,7 @@ ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify(string == "stringmaker(streamable_range)" ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify(just_range{}) == "{ 1, 2, 3, 4 }" for: "{ 1, 2, 3, 4 }" == "{ 1, 2, 3, 4 }" -ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify(disabled_range{}) == "{?}" for: "{?}" == "{?}" +ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }" for: "{ !!! }" == "{ !!! }" ToStringWhich.tests.cpp:: passed: ::Catch::Detail::stringify( v ) == "{ StringMaker }" for: "{ StringMaker }" == "{ StringMaker }" diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index cbea6267..d06cdfa3 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1064,6 +1064,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 199 | 148 passed | 47 failed | 4 failed as expected -assertions: 1004 | 878 passed | 105 failed | 21 failed as expected +test cases: 200 | 149 passed | 47 failed | 4 failed as expected +assertions: 1005 | 879 passed | 105 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index db544f8c..c1f1161e 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -7890,6 +7890,18 @@ with expansion: == "StringMaker" +------------------------------------------------------------------------------- +stringify( has_neither ) +------------------------------------------------------------------------------- +ToStringWhich.tests.cpp: +............................................................................... + +ToStringWhich.tests.cpp:: +PASSED: + REQUIRE( ::Catch::Detail::stringify(item) == "{ !!! }" ) +with expansion: + "{ !!! }" == "{ !!! }" + ------------------------------------------------------------------------------- stringify( has_operator ) ------------------------------------------------------------------------------- @@ -7982,9 +7994,9 @@ with expansion: ToStringWhich.tests.cpp:: PASSED: - REQUIRE( ::Catch::Detail::stringify(disabled_range{}) == "{?}" ) + REQUIRE( ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }" ) with expansion: - "{?}" == "{?}" + "{ !!! }" == "{ !!! }" ------------------------------------------------------------------------------- toString( vectors ) @@ -8499,6 +8511,6 @@ Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 199 | 134 passed | 61 failed | 4 failed as expected -assertions: 1015 | 874 passed | 120 failed | 21 failed as expected +test cases: 200 | 135 passed | 61 failed | 4 failed as expected +assertions: 1016 | 875 passed | 120 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 2c6a6fc7..cbca0198 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -822,6 +822,7 @@ Tricky.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index af22a1bc..abfc0590 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -8755,6 +8755,17 @@ loose text artifact + + + + ::Catch::Detail::stringify(item) == "{ !!! }" + + + "{ !!! }" == "{ !!! }" + + + + @@ -8843,10 +8854,10 @@ loose text artifact - ::Catch::Detail::stringify(disabled_range{}) == "{?}" + ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }" - "{?}" == "{?}" + "{ !!! }" == "{ !!! }" @@ -9358,7 +9369,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp b/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp index fe961865..eb1e53e5 100644 --- a/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp @@ -1,13 +1,25 @@ -#include "catch.hpp" /* - Demonstrate which version of toString/StringMaker is being used - for various types -*/ + * Demonstrate which version of toString/StringMaker is being used + * 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 +template +std::string fallbackStringifier(T const&) { + return "{ !!! }"; +} + +#define CATCH_CONFIG_FALLBACK_STRINGIFIER fallbackStringifier +#include "catch.hpp" struct has_operator { }; struct has_maker {}; struct has_maker_and_operator {}; +struct has_neither {}; std::ostream& operator<<(std::ostream& os, const has_operator&) { os << "operator<<( has_operator )"; @@ -52,6 +64,12 @@ TEST_CASE( "stringify( has_maker_and_toString )", "[.][toString]" ) { REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker" ); } +TEST_CASE("stringify( has_neither )", "[toString]") { + has_neither item; + REQUIRE( ::Catch::Detail::stringify(item) == "{ !!! }" ); +} + + // Vectors... // Don't run this in approval tests as it is sensitive to two phase lookup differences @@ -65,7 +83,6 @@ TEST_CASE( "toString( vectors )", "[toString]" ) { REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker }" ); } - // Don't run this in approval tests as it is sensitive to two phase lookup differences TEST_CASE( "toString( vectors )", "[toString]" ) { std::vector 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(stringmaker_range{}) == "stringmaker(streamable_range)"); REQUIRE(::Catch::Detail::stringify(just_range{}) == "{ 1, 2, 3, 4 }"); - REQUIRE(::Catch::Detail::stringify(disabled_range{}) == "{?}"); + REQUIRE(::Catch::Detail::stringify(disabled_range{}) == "{ !!! }"); }