From 31d483124532184aefc9595903af7493c206b874 Mon Sep 17 00:00:00 2001 From: Sean Middleditch Date: Tue, 18 Aug 2020 01:34:47 -0700 Subject: [PATCH] Support sentinel-based ranges in default stringify (#2004) --- src/catch2/catch_tostring.hpp | 4 ++-- .../Baselines/automake.sw.approved.txt | 1 + .../Baselines/compact.sw.approved.txt | 1 + .../Baselines/console.std.approved.txt | 4 ++-- .../Baselines/console.sw.approved.txt | 15 +++++++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 ++- .../Baselines/sonarqube.sw.approved.txt | 1 + tests/SelfTest/Baselines/tap.sw.approved.txt | 4 +++- .../Baselines/teamcity.sw.approved.txt | 2 ++ tests/SelfTest/Baselines/xml.sw.approved.txt | 19 +++++++++++++++---- .../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 - std::string rangeToString(InputIterator first, InputIterator last) { + template + 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 :test-result: PASS Product with differing arities - std::tuple :test-result: PASS Product with differing arities - std::tuple +: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:: passed: config.benchmarkWarmupTime == 10 for: 1 Misc.tests.cpp:: passed: std::tuple_size::value >= 1 for: 3 >= 1 Misc.tests.cpp:: passed: std::tuple_size::value >= 1 for: 2 >= 1 Misc.tests.cpp:: passed: std::tuple_size::value >= 1 for: 1 >= 1 +ToString.tests.cpp:: passed: Catch::Detail::stringify(UsesSentinel{}) == "{ }" for: "{ }" == "{ }" Decomposition.tests.cpp:: failed: truthy(false) for: Hey, its truthy! Matchers.tests.cpp:: 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:: 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:: PASSED: with expansion: 1 >= 1 +------------------------------------------------------------------------------- +Range type with sentinel +------------------------------------------------------------------------------- +ToString.tests.cpp: +............................................................................... + +ToString.tests.cpp:: PASSED: + CHECK( Catch::Detail::stringify(UsesSentinel{}) == "{ }" ) +with expansion: + "{ }" == "{ }" + ------------------------------------------------------------------------------- Reconstruction should be based on stringification: #914 ------------------------------------------------------------------------------- @@ -15654,6 +15665,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 @@ - + @@ -1063,6 +1063,7 @@ Message.tests.cpp: + 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 @@ + 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::value >= 1 for: 3 >= 1 ok {test-number} - std::tuple_size::value >= 1 for: 2 >= 1 # Product with differing arities - std::tuple ok {test-number} - std::tuple_size::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:|nexplicit failure with message:|n "Message from ##teamcity[testFinished name='Product with differing arities - std::tuple' duration="{duration}"] ##teamcity[testStarted name='Product with differing arities - std::tuple'] ##teamcity[testFinished name='Product with differing arities - std::tuple' 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:|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 + + + + Catch::Detail::stringify(UsesSentinel{}) == "{ }" + + + "{ }" == "{ }" + + + + @@ -18568,9 +18579,9 @@ loose text artifact - - + + - - + + 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