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 tests for StringRef's copy operations being shallow

Commit
8711b63a0a7a64e0b0e65f41971a3a8c27ab7a44
Author
Martin Jeřábek ·
Committer
Martin Hořeňovský
Parents
72a09de2369b

Files · Download .tar.gz

Changes

 tests/SelfTest/Baselines/compact.sw.approved.txt   |  2 ++
 tests/SelfTest/Baselines/console.std.approved.txt  |  2 +-
 tests/SelfTest/Baselines/console.sw.approved.txt   | 26 +++++++++++++++++++++-
 tests/SelfTest/Baselines/junit.sw.approved.txt     |  4 +++-
 tests/SelfTest/Baselines/sonarqube.sw.approved.txt |  2 ++
 tests/SelfTest/Baselines/tap.sw.approved.txt       |  6 ++++-
 tests/SelfTest/Baselines/xml.sw.approved.txt       | 24 +++++++++++++++++++-
 tests/SelfTest/IntrospectiveTests/String.tests.cpp | 12 +++++++++-
 8 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index fab13bf2..390e9a6e 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -1554,6 +1554,8 @@ String.tests.cpp:<line number>: passed: std::strcmp( rawChars, "hello" ) == 0 fo
 String.tests.cpp:<line number>: passed: s.data() == rawChars for: "hello" == "hello"
 String.tests.cpp:<line number>: passed: original == "original"
 String.tests.cpp:<line number>: passed: original.data()
+String.tests.cpp:<line number>: passed: original.begin() == copy.begin() for: "original string" == "original string"
+String.tests.cpp:<line number>: passed: original.begin() == copy.begin() for: "original string" == "original string"
 String.tests.cpp:<line number>: passed: ss.empty() == false for: false == false
 String.tests.cpp:<line number>: passed: ss.size() == 5 for: 5 == 5
 String.tests.cpp:<line number>: passed: std::strncmp( ss.data(), "hello", 5 ) == 0 for: 0 == 0
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index 92b8d9d9..fb5b2b28 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -1427,5 +1427,5 @@ due to unexpected exception with message:
 
 ===============================================================================
 test cases:  384 |  307 passed |  70 failed |  7 failed as expected
-assertions: 2183 | 2027 passed | 129 failed | 27 failed as expected
+assertions: 2185 | 2029 passed | 129 failed | 27 failed as expected
 
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index ac9f7eee..65baafcf 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -11079,6 +11079,30 @@ String.tests.cpp:<line number>: PASSED:
 String.tests.cpp:<line number>: PASSED:
   REQUIRE_NOTHROW( original.data() )
 
+-------------------------------------------------------------------------------
+StringRef
+  Copy construction is shallow
+-------------------------------------------------------------------------------
+String.tests.cpp:<line number>
+...............................................................................
+
+String.tests.cpp:<line number>: PASSED:
+  REQUIRE( original.begin() == copy.begin() )
+with expansion:
+  "original string" == "original string"
+
+-------------------------------------------------------------------------------
+StringRef
+  Copy assignment is shallow
+-------------------------------------------------------------------------------
+String.tests.cpp:<line number>
+...............................................................................
+
+String.tests.cpp:<line number>: PASSED:
+  REQUIRE( original.begin() == copy.begin() )
+with expansion:
+  "original string" == "original string"
+
 -------------------------------------------------------------------------------
 StringRef
   Substrings
@@ -17541,5 +17565,5 @@ Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
 test cases:  384 |  291 passed |  86 failed |  7 failed as expected
-assertions: 2200 | 2027 passed | 146 failed | 27 failed as expected
+assertions: 2202 | 2029 passed | 146 failed | 27 failed as expected
 
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index a82176bd..9132e982 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/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="17" failures="129" tests="2200" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="129" tests="2202" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="random-seed" value="1"/>
       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
@@ -1235,6 +1235,8 @@ Matchers.tests.cpp:<line number>
     <testcase classname="<exe-name>.global" name="StringRef/Empty string" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="StringRef/From string literal" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="StringRef/From sub-string" time="{duration}" status="run"/>
+    <testcase classname="<exe-name>.global" name="StringRef/Copy construction is shallow" time="{duration}" status="run"/>
+    <testcase classname="<exe-name>.global" name="StringRef/Copy assignment is shallow" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="StringRef/Substrings/zero-based substring" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="StringRef/Substrings/non-zero-based substring" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="StringRef/Substrings/Pointer values of full refs should match" time="{duration}" status="run"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index 72c2e692..ee0df2e4 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -210,6 +210,8 @@
     <testCase name="StringRef/Empty string" duration="{duration}"/>
     <testCase name="StringRef/From string literal" duration="{duration}"/>
     <testCase name="StringRef/From sub-string" duration="{duration}"/>
+    <testCase name="StringRef/Copy construction is shallow" duration="{duration}"/>
+    <testCase name="StringRef/Copy assignment is shallow" duration="{duration}"/>
     <testCase name="StringRef/Substrings/zero-based substring" duration="{duration}"/>
     <testCase name="StringRef/Substrings/non-zero-based substring" duration="{duration}"/>
     <testCase name="StringRef/Substrings/Pointer values of full refs should match" duration="{duration}"/>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index e3d75dd8..0a587189 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2792,6 +2792,10 @@ ok {test-number} - original == "original"
 # StringRef
 ok {test-number} - original.data()
 # StringRef
+ok {test-number} - original.begin() == copy.begin() for: "original string" == "original string"
+# StringRef
+ok {test-number} - original.begin() == copy.begin() for: "original string" == "original string"
+# StringRef
 ok {test-number} - ss.empty() == false for: false == false
 # StringRef
 ok {test-number} - ss.size() == 5 for: 5 == 5
@@ -4402,5 +4406,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
 ok {test-number} -
 # xmlentitycheck
 ok {test-number} -
-1..2200
+1..2202
 
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 2551e03b..fd542b29 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -13222,6 +13222,28 @@ Message from section two
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
     </Section>
+    <Section name="Copy construction is shallow" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
+      <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
+        <Original>
+          original.begin() == copy.begin()
+        </Original>
+        <Expanded>
+          "original string" == "original string"
+        </Expanded>
+      </Expression>
+      <OverallResults successes="1" failures="0" expectedFailures="0"/>
+    </Section>
+    <Section name="Copy assignment is shallow" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
+      <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
+        <Original>
+          original.begin() == copy.begin()
+        </Original>
+        <Expanded>
+          "original string" == "original string"
+        </Expanded>
+      </Expression>
+      <OverallResults successes="1" failures="0" expectedFailures="0"/>
+    </Section>
     <Section name="Substrings" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
       <Section name="zero-based substring" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
         <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
@@ -20573,6 +20595,6 @@ loose text artifact
     </Section>
     <OverallResult success="true"/>
   </TestCase>
-  <OverallResults successes="2027" failures="146" expectedFailures="27"/>
+  <OverallResults successes="2029" failures="146" expectedFailures="27"/>
   <OverallResultsCases successes="291" failures="86" expectedFailures="7"/>
 </Catch2TestRun>
diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
index 9fd8a780..6245ca77 100644
--- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -29,7 +29,17 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
 
         REQUIRE_NOTHROW(original.data());
     }
-
+    SECTION( "Copy construction is shallow" ) {
+        StringRef original = StringRef( "original string" );
+        StringRef copy = original;
+        REQUIRE(original.begin() == copy.begin());
+    }
+    SECTION( "Copy assignment is shallow" ) {
+        StringRef original = StringRef( "original string" );
+        StringRef copy;
+        copy = original;
+        REQUIRE(original.begin() == copy.begin());
+    }
 
     SECTION( "Substrings" ) {
         StringRef s = "hello world!";