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

Added tests for stringifying map and set

Commit
e41e8e8384c415a875309180e9d310a8da9972c4
Author
Phil Nash ·
Parents
af3f2499bcc8

Files · Download .tar.gz

Changes

 .../SelfTest/Baselines/compact.sw.approved.txt     | 10 +++
 .../SelfTest/Baselines/console.std.approved.txt    |  4 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 86 +++++++++++++++++++++-
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  8 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 80 +++++++++++++++++++-
 .../SelfTest/UsageTests/ToStringGeneral.tests.cpp  | 49 ++++++++++++
 6 files changed, 230 insertions(+), 7 deletions(-)

diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt
index b205a13f..b2c492cb 100644
--- a/projects/SelfTest/Baselines/compact.sw.approved.txt
+++ b/projects/SelfTest/Baselines/compact.sw.approved.txt
@@ -944,8 +944,18 @@ String.tests.cpp:<line number>: passed: Catch::replaceInPlace( s, "'", "|'" ) fo
 String.tests.cpp:<line number>: passed: s == "didn|'t" for: "didn|'t" == "didn|'t"
 Misc.tests.cpp:<line number>: failed: false with 1 message: '3'
 Message.tests.cpp:<line number>: failed: false with 2 messages: 'hi' and 'i := 7'
+ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( emptyMap ) == "{  }" for: "{  }" == "{  }"
+ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( map ) == "{ { /"one/", 1 } }" for: "{ { "one", 1 } }" == "{ { "one", 1 } }"
+ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( map ) == "{ { /"abc/", 1 }, { /"def/", 2 }, { /"ghi/", 3 } }" for: "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
+==
+"{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
 ToStringPair.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(value) == "{ 34, /"xyzzy/" }" for: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }"
 ToStringPair.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( value ) == "{ 34, /"xyzzy/" }" for: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }"
+ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( emptySet ) == "{  }" for: "{  }" == "{  }"
+ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( set ) == "{ /"one/" }" for: "{ "one" }" == "{ "one" }"
+ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( set ) == "{ /"abc/", /"def/", /"ghi/" }" for: "{ "abc", "def", "ghi" }"
+==
+"{ "abc", "def", "ghi" }"
 ToStringPair.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( pr ) == "{ { /"green/", 55 } }" for: "{ { "green", 55 } }"
 ==
 "{ { "green", 55 } }"
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index d8087755..85b6fff3 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1080,6 +1080,6 @@ with expansion:
   "{?}" == "1"
 
 ===============================================================================
-test cases: 191 | 139 passed |  48 failed |  4 failed as expected
-assertions: 971 | 843 passed | 107 failed | 21 failed as expected
+test cases: 193 | 141 passed |  48 failed |  4 failed as expected
+assertions: 977 | 849 passed | 107 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index cce06fd3..96fc922e 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -7488,6 +7488,47 @@ with messages:
   hi
   i := 7
 
+-------------------------------------------------------------------------------
+std::map is convertible string
+  empty
+-------------------------------------------------------------------------------
+ToStringGeneral.tests.cpp:<line number>
+...............................................................................
+
+ToStringGeneral.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( Catch::Detail::stringify( emptyMap ) == "{  }" )
+with expansion:
+  "{  }" == "{  }"
+
+-------------------------------------------------------------------------------
+std::map is convertible string
+  single item
+-------------------------------------------------------------------------------
+ToStringGeneral.tests.cpp:<line number>
+...............................................................................
+
+ToStringGeneral.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" )
+with expansion:
+  "{ { "one", 1 } }" == "{ { "one", 1 } }"
+
+-------------------------------------------------------------------------------
+std::map is convertible string
+  several items
+-------------------------------------------------------------------------------
+ToStringGeneral.tests.cpp:<line number>
+...............................................................................
+
+ToStringGeneral.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" )
+with expansion:
+  "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
+  ==
+  "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
+
 -------------------------------------------------------------------------------
 std::pair<int,const std::string> -> toString
 -------------------------------------------------------------------------------
@@ -7512,6 +7553,47 @@ PASSED:
 with expansion:
   "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }"
 
+-------------------------------------------------------------------------------
+std::set is convertible string
+  empty
+-------------------------------------------------------------------------------
+ToStringGeneral.tests.cpp:<line number>
+...............................................................................
+
+ToStringGeneral.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( Catch::Detail::stringify( emptySet ) == "{  }" )
+with expansion:
+  "{  }" == "{  }"
+
+-------------------------------------------------------------------------------
+std::set is convertible string
+  single item
+-------------------------------------------------------------------------------
+ToStringGeneral.tests.cpp:<line number>
+...............................................................................
+
+ToStringGeneral.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" )
+with expansion:
+  "{ "one" }" == "{ "one" }"
+
+-------------------------------------------------------------------------------
+std::set is convertible string
+  several items
+-------------------------------------------------------------------------------
+ToStringGeneral.tests.cpp:<line number>
+...............................................................................
+
+ToStringGeneral.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" )
+with expansion:
+  "{ "abc", "def", "ghi" }"
+  ==
+  "{ "abc", "def", "ghi" }"
+
 -------------------------------------------------------------------------------
 std::vector<std::pair<std::string,int> > -> toString
 -------------------------------------------------------------------------------
@@ -8114,6 +8196,6 @@ Misc.tests.cpp:<line number>:
 PASSED:
 
 ===============================================================================
-test cases: 191 | 137 passed |  50 failed |  4 failed as expected
-assertions: 970 | 839 passed | 110 failed | 21 failed as expected
+test cases: 193 | 139 passed |  50 failed |  4 failed as expected
+assertions: 976 | 845 passed | 110 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index 6b09d917..435a40f0 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="96" tests="971" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="15" failures="96" tests="977" 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}"/>
@@ -799,8 +799,14 @@ i := 7
 Message.tests.cpp:<line number>
       </failure>
     </testcase>
+    <testcase classname="<exe-name>.global" name="std::map is convertible string/empty" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="std::map is convertible string/single item" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="std::map is convertible string/several items" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="std::pair&lt;int,const std::string> -> toString" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="std::pair&lt;int,std::string> -> toString" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="std::set is convertible string/empty" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="std::set is convertible string/single item" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="std::set is convertible string/several items" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="std::vector&lt;std::pair&lt;std::string,int> > -> toString" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="string literals of different sizes can be compared" time="{duration}">
       <failure message="&quot;first&quot; == &quot;second&quot;" type="REQUIRE">
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index dcc9f894..b39b1b00 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -8429,6 +8429,44 @@ loose text artifact
       </Expression>
       <OverallResult success="false"/>
     </TestCase>
+    <TestCase name="std::map is convertible string" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+      <Section name="empty" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+          <Original>
+            Catch::Detail::stringify( emptyMap ) == "{  }"
+          </Original>
+          <Expanded>
+            "{  }" == "{  }"
+          </Expanded>
+        </Expression>
+        <OverallResults successes="1" failures="0" expectedFailures="0"/>
+      </Section>
+      <Section name="single item" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+          <Original>
+            Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }"
+          </Original>
+          <Expanded>
+            "{ { "one", 1 } }" == "{ { "one", 1 } }"
+          </Expanded>
+        </Expression>
+        <OverallResults successes="1" failures="0" expectedFailures="0"/>
+      </Section>
+      <Section name="several items" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+          <Original>
+            Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }"
+          </Original>
+          <Expanded>
+            "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
+==
+"{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
+          </Expanded>
+        </Expression>
+        <OverallResults successes="1" failures="0" expectedFailures="0"/>
+      </Section>
+      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="std::pair&lt;int,const std::string> -> toString" tags="[pair][toString]" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
         <Original>
@@ -8451,6 +8489,44 @@ loose text artifact
       </Expression>
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="std::set is convertible string" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+      <Section name="empty" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+          <Original>
+            Catch::Detail::stringify( emptySet ) == "{  }"
+          </Original>
+          <Expanded>
+            "{  }" == "{  }"
+          </Expanded>
+        </Expression>
+        <OverallResults successes="1" failures="0" expectedFailures="0"/>
+      </Section>
+      <Section name="single item" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+          <Original>
+            Catch::Detail::stringify( set ) == "{ \"one\" }"
+          </Original>
+          <Expanded>
+            "{ "one" }" == "{ "one" }"
+          </Expanded>
+        </Expression>
+        <OverallResults successes="1" failures="0" expectedFailures="0"/>
+      </Section>
+      <Section name="several items" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
+          <Original>
+            Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }"
+          </Original>
+          <Expanded>
+            "{ "abc", "def", "ghi" }"
+==
+"{ "abc", "def", "ghi" }"
+          </Expanded>
+        </Expression>
+        <OverallResults successes="1" failures="0" expectedFailures="0"/>
+      </Section>
+      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="std::vector&lt;std::pair&lt;std::string,int> > -> toString" tags="[pair][toString]" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
         <Original>
@@ -9038,7 +9114,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="839" failures="111" expectedFailures="21"/>
+    <OverallResults successes="845" failures="111" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="839" failures="110" expectedFailures="21"/>
+  <OverallResults successes="845" failures="110" expectedFailures="21"/>
 </Catch>
diff --git a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
index 743882b1..3c5a3d94 100644
--- a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
+++ b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
@@ -5,8 +5,11 @@
  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  */
 
+#define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
 #include "catch.hpp"
 
+#include <map>
+#include <set>
 
 TEST_CASE( "Character pretty printing" ){
     SECTION("Specifically escaped"){
@@ -51,3 +54,49 @@ TEST_CASE( "Capture and info messages" ) {
         REQUIRE(true);
     }
 }
+
+TEST_CASE( "std::map is convertible string", "[toString]" ) {
+
+    SECTION( "empty" ) {
+        std::map<std::string, int> emptyMap;
+
+        REQUIRE( Catch::Detail::stringify( emptyMap ) == "{  }" );
+    }
+
+    SECTION( "single item" ) {
+        std::map<std::string, int> map = { { "one", 1 } };
+
+        REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" );
+    }
+
+    SECTION( "several items" ) {
+        std::map<std::string, int> map = {
+                { "abc", 1 },
+                { "def", 2 },
+                { "ghi", 3 }
+            };
+
+        REQUIRE( Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" );
+    }
+}
+
+TEST_CASE( "std::set is convertible string", "[toString]" ) {
+
+    SECTION( "empty" ) {
+        std::set<std::string> emptySet;
+
+        REQUIRE( Catch::Detail::stringify( emptySet ) == "{  }" );
+    }
+
+    SECTION( "single item" ) {
+        std::set<std::string> set = { "one" };
+
+        REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" );
+    }
+
+    SECTION( "several items" ) {
+        std::set<std::string> set = { "abc", "def", "ghi" };
+
+        REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" );
+    }
+}