Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add test for overriding the fallback stringifier

Commit
c0267e5c20c29f61e9a9d04b1725d4a706f74cce
Author
Martin Hořeňovský ·
Parents
bb84f0788af1

Files · Download .tar.gz

Changes

 .../SelfTest/Baselines/compact.sw.approved.txt     |  3 ++-
 .../SelfTest/Baselines/console.std.approved.txt    |  4 +--
 .../SelfTest/Baselines/console.sw.approved.txt     | 20 ++++++++++++---
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  3 ++-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 19 +++++++++++---
 .../SelfTest/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:<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>"
 ==
 "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 )"
 ==
 "operator<<( has_operator )"
@@ -1002,7 +1003,7 @@ ToStringWhich.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(string
 ==
 "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(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> }"
 ==
 "{ StringMaker<has_maker> }"
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<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 )
 -------------------------------------------------------------------------------
@@ -7982,9 +7994,9 @@ with expansion:
 
 ToStringWhich.tests.cpp:<line number>:
 PASSED:
-  REQUIRE( ::Catch::Detail::stringify(disabled_range{}) == "{?}" )
+  REQUIRE( ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }" )
 with expansion:
-  "{?}" == "{?}"
+  "{ !!! }" == "{ !!! }"
 
 -------------------------------------------------------------------------------
 toString( vectors<has_maker> )
@@ -8499,6 +8511,6 @@ Misc.tests.cpp:<line number>:
 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 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <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="#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}"/>
@@ -822,6 +822,7 @@ Tricky.tests.cpp:<line number>
     </testcase>
     <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_neither )" 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 pointer returns the string contents" time="{duration}"/>
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
       </Expression>
       <OverallResult success="true"/>
     </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" >
       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
         <Original>
@@ -8843,10 +8854,10 @@ loose text artifact
       </Expression>
       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringWhich.tests.cpp" >
         <Original>
-          ::Catch::Detail::stringify(disabled_range{}) == "{?}"
+          ::Catch::Detail::stringify(disabled_range{}) == "{ !!! }"
         </Original>
         <Expanded>
-          "{?}" == "{?}"
+          "{ !!! }" == "{ !!! }"
         </Expanded>
       </Expression>
       <OverallResult success="true"/>
@@ -9358,7 +9369,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="874" failures="121" expectedFailures="21"/>
+    <OverallResults successes="875" failures="121" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="874" failures="120" expectedFailures="21"/>
+  <OverallResults successes="875" failures="120" expectedFailures="21"/>
 </Catch>
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 <string>
+template <typename T>
+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<has_maker_and_operator>" );
 }
 
+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<has_maker> )", "[toString]" ) {
     REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" );
 }
 
-
 // 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]" ) {
     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(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{}) == "{ !!! }");
 }