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

Support sentinel-based ranges in default stringify (#2004)

Commit
31d483124532184aefc9595903af7493c206b874
Author
Sean Middleditch ·
Committer
Martin Hořeňovský
Parents
08fb5cbab2f8

Files · Download .tar.gz

Changes

 src/catch2/catch_tostring.hpp                        |  4 ++--
 tests/SelfTest/Baselines/automake.sw.approved.txt    |  1 +
 tests/SelfTest/Baselines/compact.sw.approved.txt     |  1 +
 tests/SelfTest/Baselines/console.std.approved.txt    |  4 ++--
 tests/SelfTest/Baselines/console.sw.approved.txt     | 15 +++++++++++++--
 tests/SelfTest/Baselines/junit.sw.approved.txt       |  3 ++-
 tests/SelfTest/Baselines/sonarqube.sw.approved.txt   |  1 +
 tests/SelfTest/Baselines/tap.sw.approved.txt         |  4 +++-
 tests/SelfTest/Baselines/teamcity.sw.approved.txt    |  2 ++
 tests/SelfTest/Baselines/xml.sw.approved.txt         | 19 +++++++++++++++----
 tests/SelfTest/IntrospectiveTests/ToString.tests.cpp | 11 +++++++++++
 11 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp
index fb247555..0462bc6b 100644
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -311,8 +311,8 @@ namespace Catch {
 #endif
 
     namespace Detail {
-        template<typename InputIterator>
-        std::string rangeToString(InputIterator first, InputIterator last) {
+        template<typename InputIterator, typename Sentinel = InputIterator>
+        std::string rangeToString(InputIterator first, Sentinel last) {
             ReusableStringStream rss;
             rss << "{ ";
             if (first != last) {
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt
index 1d00129c..4d599486 100644
--- a/tests/SelfTest/Baselines/automake.sw.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.approved.txt
@@ -180,6 +180,7 @@ Nor would this
 :test-result: PASS Product with differing arities - std::tuple<int, double, float>
 :test-result: PASS Product with differing arities - std::tuple<int, double>
 :test-result: PASS Product with differing arities - std::tuple<int>
+:test-result: PASS Range type with sentinel
 :test-result: FAIL Reconstruction should be based on stringification: #914
 :test-result: FAIL Regex string matcher
 :test-result: PASS Regression test #1
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index ab464e66..a7fb6780 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -1265,6 +1265,7 @@ CmdLine.tests.cpp:<line number>: passed: config.benchmarkWarmupTime == 10 for: 1
 Misc.tests.cpp:<line number>: passed: std::tuple_size<TestType>::value >= 1 for: 3 >= 1
 Misc.tests.cpp:<line number>: passed: std::tuple_size<TestType>::value >= 1 for: 2 >= 1
 Misc.tests.cpp:<line number>: passed: std::tuple_size<TestType>::value >= 1 for: 1 >= 1
+ToString.tests.cpp:<line number>: passed: Catch::Detail::stringify(UsesSentinel{}) == "{  }" for: "{  }" == "{  }"
 Decomposition.tests.cpp:<line number>: failed: truthy(false) for: Hey, its truthy!
 Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("this STRING contains 'abc' as a substring") for: "this string contains 'abc' as a substring" matches "this STRING contains 'abc' as a substring" case sensitively
 Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("contains 'abc' as a substring") for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index deb10bab..727cdda5 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -1380,6 +1380,6 @@ due to unexpected exception with message:
   Why would you throw a std::string?
 
 ===============================================================================
-test cases:  349 |  275 passed |  70 failed |  4 failed as expected
-assertions: 1989 | 1837 passed | 131 failed | 21 failed as expected
+test cases:  350 |  276 passed |  70 failed |  4 failed as expected
+assertions: 1990 | 1838 passed | 131 failed | 21 failed as expected
 
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 7fa50b2f..9442de74 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -9326,6 +9326,17 @@ Misc.tests.cpp:<line number>: PASSED:
 with expansion:
   1 >= 1
 
+-------------------------------------------------------------------------------
+Range type with sentinel
+-------------------------------------------------------------------------------
+ToString.tests.cpp:<line number>
+...............................................................................
+
+ToString.tests.cpp:<line number>: PASSED:
+  CHECK( Catch::Detail::stringify(UsesSentinel{}) == "{  }" )
+with expansion:
+  "{  }" == "{  }"
+
 -------------------------------------------------------------------------------
 Reconstruction should be based on stringification: #914
 -------------------------------------------------------------------------------
@@ -15654,6 +15665,6 @@ Misc.tests.cpp:<line number>
 Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
-test cases:  349 |  259 passed |  86 failed |  4 failed as expected
-assertions: 2006 | 1837 passed | 148 failed | 21 failed as expected
+test cases:  350 |  260 passed |  86 failed |  4 failed as expected
+assertions: 2007 | 1838 passed | 148 failed | 21 failed as expected
 
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index e4004469..0d5804c4 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="132" tests="2007" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="132" tests="2008" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
       <property name="random-seed" value="1"/>
@@ -1063,6 +1063,7 @@ Message.tests.cpp:<line number>
     <testcase classname="<exe-name>.global" name="Product with differing arities - std::tuple&lt;int, double, float>" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Product with differing arities - std::tuple&lt;int, double>" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Product with differing arities - std::tuple&lt;int>" time="{duration}" status="run"/>
+    <testcase classname="<exe-name>.global" name="Range type with sentinel" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="Reconstruction should be based on stringification: #914" time="{duration}" status="run">
       <failure message="truthy(false)" type="CHECK">
 FAILED:
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index 44f3adab..ff0a3d28 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -187,6 +187,7 @@
   </file>
   <file path="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp">
     <testCase name="Directly creating an EnumInfo" duration="{duration}"/>
+    <testCase name="Range type with sentinel" duration="{duration}"/>
     <testCase name="parseEnums/No enums" duration="{duration}"/>
     <testCase name="parseEnums/One enum value" duration="{duration}"/>
     <testCase name="parseEnums/Multiple enum values" duration="{duration}"/>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index 164ae09f..52ea17cc 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2452,6 +2452,8 @@ ok {test-number} - std::tuple_size<TestType>::value >= 1 for: 3 >= 1
 ok {test-number} - std::tuple_size<TestType>::value >= 1 for: 2 >= 1
 # Product with differing arities - std::tuple<int>
 ok {test-number} - std::tuple_size<TestType>::value >= 1 for: 1 >= 1
+# Range type with sentinel
+ok {test-number} - Catch::Detail::stringify(UsesSentinel{}) == "{  }" for: "{  }" == "{  }"
 # Reconstruction should be based on stringification: #914
 not ok {test-number} - truthy(false) for: Hey, its truthy!
 # Regex string matcher
@@ -4004,5 +4006,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
 ok {test-number} -
 # xmlentitycheck
 ok {test-number} -
-1..2006
+1..2007
 
diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
index 9fc5f4b7..e63b1502 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
@@ -461,6 +461,8 @@ Message.tests.cpp:<line number>|nexplicit failure with message:|n  "Message from
 ##teamcity[testFinished name='Product with differing arities - std::tuple<int, double>' duration="{duration}"]
 ##teamcity[testStarted name='Product with differing arities - std::tuple<int>']
 ##teamcity[testFinished name='Product with differing arities - std::tuple<int>' duration="{duration}"]
+##teamcity[testStarted name='Range type with sentinel']
+##teamcity[testFinished name='Range type with sentinel' duration="{duration}"]
 ##teamcity[testStarted name='Reconstruction should be based on stringification: #914']
 Decomposition.tests.cpp:<line number>|nexpression failed|n  CHECK( truthy(false) )|nwith expansion:|n  Hey, its truthy!|n']
 ##teamcity[testFinished name='Reconstruction should be based on stringification: #914' duration="{duration}"]
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index a8c2e3e3..bc92435e 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -11404,6 +11404,17 @@ Nor would this
       </Expression>
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="Range type with sentinel" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+      <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+        <Original>
+          Catch::Detail::stringify(UsesSentinel{}) == "{  }"
+        </Original>
+        <Expanded>
+          "{  }" == "{  }"
+        </Expanded>
+      </Expression>
+      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="Reconstruction should be based on stringification: #914" tags="[.][Decomposition][failing]" filename="tests/<exe-name>/UsageTests/Decomposition.tests.cpp" >
       <Expression success="false" type="CHECK" filename="tests/<exe-name>/UsageTests/Decomposition.tests.cpp" >
         <Original>
@@ -18568,9 +18579,9 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="1837" failures="149" expectedFailures="21"/>
-    <OverallResultsCases successes="259" failures="86" expectedFailures="4"/>
+    <OverallResults successes="1838" failures="149" expectedFailures="21"/>
+    <OverallResultsCases successes="260" failures="86" expectedFailures="4"/>
   </Group>
-  <OverallResults successes="1837" failures="148" expectedFailures="21"/>
-  <OverallResultsCases successes="259" failures="86" expectedFailures="4"/>
+  <OverallResults successes="1838" failures="148" expectedFailures="21"/>
+  <OverallResultsCases successes="260" failures="86" expectedFailures="4"/>
 </Catch>
diff --git a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp
index b50a4012..47dfdd37 100644
--- a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp
@@ -4,6 +4,13 @@
 
 enum class EnumClass3 { Value1, Value2, Value3, Value4 };
 
+struct UsesSentinel {
+    using const_iterator = int const*;
+    using const_sentinel = std::nullptr_t;
+
+    const_iterator begin() const { return nullptr; }
+    const_iterator end() const { return nullptr; }
+};
 
 TEST_CASE( "parseEnums", "[Strings][enums]" ) {
     using namespace Catch::Matchers;
@@ -40,3 +47,7 @@ TEST_CASE( "Directly creating an EnumInfo" ) {
     CHECK( enumInfo->lookup(1) == "Value2" );
     CHECK( enumInfo->lookup(3) == "{** unexpected enum value **}" );
 }
+
+TEST_CASE("Range type with sentinel") {
+    CHECK( Catch::Detail::stringify(UsesSentinel{}) == "{  }" );
+}
\ No newline at end of file