From 284672cc84f3fd53332618d1654d95bc4254ff3f 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) --- include/internal/catch_tostring.h | 4 ++-- .../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 + .../SelfTest/Baselines/xml.sw.approved.txt | 19 +++++++++++++++---- .../IntrospectiveTests/ToString.tests.cpp | 11 +++++++++++ 8 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 8687c4a6..e650458f 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -309,8 +309,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/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 59a909b2..efefa833 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1203,6 +1203,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/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index c1600545..cfcdc72e 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/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: 321 | 247 passed | 70 failed | 4 failed as expected -assertions: 1758 | 1606 passed | 131 failed | 21 failed as expected +test cases: 322 | 248 passed | 70 failed | 4 failed as expected +assertions: 1759 | 1607 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 3603215f..3c09bf31 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -8895,6 +8895,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 ------------------------------------------------------------------------------- @@ -14127,6 +14138,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 321 | 231 passed | 86 failed | 4 failed as expected -assertions: 1775 | 1606 passed | 148 failed | 21 failed as expected +test cases: 322 | 232 passed | 86 failed | 4 failed as expected +assertions: 1776 | 1607 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 9c850534..89a0b438 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1045,6 +1045,7 @@ Message.tests.cpp: + FAILED: diff --git a/projects/SelfTest/Baselines/sonarqube.sw.approved.txt b/projects/SelfTest/Baselines/sonarqube.sw.approved.txt index 35360ebc..12a4e5be 100644 --- a/projects/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/projects/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -162,6 +162,7 @@ + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 30d113ef..2b5da8d3 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -10962,6 +10962,17 @@ Nor would this + + + + Catch::Detail::stringify(UsesSentinel{}) == "{ }" + + + "{ }" == "{ }" + + + + @@ -16711,9 +16722,9 @@ loose text artifact - - + + - - + + diff --git a/projects/SelfTest/IntrospectiveTests/ToString.tests.cpp b/projects/SelfTest/IntrospectiveTests/ToString.tests.cpp index caa924f5..d1eb261c 100644 --- a/projects/SelfTest/IntrospectiveTests/ToString.tests.cpp +++ b/projects/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