diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 1f74267e..1d00129c 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -113,6 +113,7 @@ Nor would this :test-result: PASS Comparisons between ints where one side is computed :test-result: PASS Comparisons between unsigned ints and negative signed ints match c++ standard behaviour :test-result: PASS Comparisons with int literals don't warn when mixing signed/ unsigned +:test-result: PASS Composed generic matchers shortcircuit :test-result: PASS Composed matchers shortcircuit :test-result: FAIL Contains string matcher :test-result: PASS Copy and then generate a range diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 6fd517fd..05fc49df 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -429,6 +429,12 @@ Condition.tests.cpp:: passed: 4 == ul for: 4 == 4 Condition.tests.cpp:: passed: 5 == c for: 5 == 5 Condition.tests.cpp:: passed: 6 == uc for: 6 == 6 Condition.tests.cpp:: passed: (std::numeric_limits::max)() > ul for: 4294967295 (0x) > 4 +Matchers.tests.cpp:: passed: !(matcher.match( 1 )) for: !false +Matchers.tests.cpp:: passed: first.matchCalled for: true +Matchers.tests.cpp:: passed: !second.matchCalled for: true +Matchers.tests.cpp:: passed: matcher.match(1) for: true +Matchers.tests.cpp:: passed: first.matchCalled for: true +Matchers.tests.cpp:: passed: !second.matchCalled for: true Matchers.tests.cpp:: passed: 1, !(first && second) for: 1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to fail ) Matchers.tests.cpp:: passed: first.matchCalled for: true Matchers.tests.cpp:: passed: !second.matchCalled for: true diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index fbcee17a..deb10bab 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: 348 | 274 passed | 70 failed | 4 failed as expected -assertions: 1983 | 1831 passed | 131 failed | 21 failed as expected +test cases: 349 | 275 passed | 70 failed | 4 failed as expected +assertions: 1989 | 1837 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 084bb78c..0f239c76 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -3373,6 +3373,50 @@ Condition.tests.cpp:: PASSED: with expansion: 4294967295 (0x) > 4 +------------------------------------------------------------------------------- +Composed generic matchers shortcircuit + MatchAllOf +------------------------------------------------------------------------------- +Matchers.tests.cpp: +............................................................................... + +Matchers.tests.cpp:: PASSED: + CHECK_FALSE( matcher.match( 1 ) ) +with expansion: + !false + +Matchers.tests.cpp:: PASSED: + REQUIRE( first.matchCalled ) +with expansion: + true + +Matchers.tests.cpp:: PASSED: + REQUIRE( !second.matchCalled ) +with expansion: + true + +------------------------------------------------------------------------------- +Composed generic matchers shortcircuit + MatchAnyOf +------------------------------------------------------------------------------- +Matchers.tests.cpp: +............................................................................... + +Matchers.tests.cpp:: PASSED: + CHECK( matcher.match(1) ) +with expansion: + true + +Matchers.tests.cpp:: PASSED: + REQUIRE( first.matchCalled ) +with expansion: + true + +Matchers.tests.cpp:: PASSED: + REQUIRE( !second.matchCalled ) +with expansion: + true + ------------------------------------------------------------------------------- Composed matchers shortcircuit && @@ -15612,6 +15656,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 348 | 258 passed | 86 failed | 4 failed as expected -assertions: 2000 | 1831 passed | 148 failed | 21 failed as expected +test cases: 349 | 259 passed | 86 failed | 4 failed as expected +assertions: 2006 | 1837 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 3c24a3a6..7ef0bba4 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -390,6 +390,8 @@ Exception.tests.cpp: + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index e51e53cc..1fd944a4 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -957,6 +957,8 @@ Exception.tests.cpp: + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index c1e5b5e9..6fb2aa15 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -856,6 +856,18 @@ ok {test-number} - 5 == c for: 5 == 5 ok {test-number} - 6 == uc for: 6 == 6 # Comparisons with int literals don't warn when mixing signed/ unsigned ok {test-number} - (std::numeric_limits::max)() > ul for: 4294967295 (0x) > 4 +# Composed generic matchers shortcircuit +ok {test-number} - !(matcher.match( 1 )) for: !false +# Composed generic matchers shortcircuit +ok {test-number} - first.matchCalled for: true +# Composed generic matchers shortcircuit +ok {test-number} - !second.matchCalled for: true +# Composed generic matchers shortcircuit +ok {test-number} - matcher.match(1) for: true +# Composed generic matchers shortcircuit +ok {test-number} - first.matchCalled for: true +# Composed generic matchers shortcircuit +ok {test-number} - !second.matchCalled for: true # Composed matchers shortcircuit ok {test-number} - 1, !(first && second) for: 1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to fail ) # Composed matchers shortcircuit @@ -3992,5 +4004,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2000 +1..2006 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 7a66092b..9fc5f4b7 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -259,6 +259,8 @@ Exception.tests.cpp:|nunexpected exception with message:|n "unexpe ##teamcity[testFinished name='Comparisons between unsigned ints and negative signed ints match c++ standard behaviour' duration="{duration}"] ##teamcity[testStarted name='Comparisons with int literals don|'t warn when mixing signed/ unsigned'] ##teamcity[testFinished name='Comparisons with int literals don|'t warn when mixing signed/ unsigned' duration="{duration}"] +##teamcity[testStarted name='Composed generic matchers shortcircuit'] +##teamcity[testFinished name='Composed generic matchers shortcircuit' duration="{duration}"] ##teamcity[testStarted name='Composed matchers shortcircuit'] ##teamcity[testFinished name='Composed matchers shortcircuit' duration="{duration}"] ##teamcity[testStarted name='Contains string matcher'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index f9617bd0..c2109e5d 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -3711,6 +3711,63 @@ Nor would this + +
+ + + !(matcher.match( 1 )) + + + !false + + + + + first.matchCalled + + + true + + + + + !second.matchCalled + + + true + + + +
+
+ + + matcher.match(1) + + + true + + + + + first.matchCalled + + + true + + + + + !second.matchCalled + + + true + + + +
+ +
@@ -18511,9 +18568,9 @@ loose text artifact
- - + + - - + + diff --git a/tests/SelfTest/UsageTests/Matchers.tests.cpp b/tests/SelfTest/UsageTests/Matchers.tests.cpp index c9c61285..8276cf84 100644 --- a/tests/SelfTest/UsageTests/Matchers.tests.cpp +++ b/tests/SelfTest/UsageTests/Matchers.tests.cpp @@ -661,6 +661,49 @@ namespace { namespace MatchersTests { } } + struct CheckedTestingGenericMatcher : Catch::Matchers::MatcherGenericBase { + mutable bool matchCalled = false; + bool matchSucceeds = false; + + bool match(int const&) const { + matchCalled = true; + return matchSucceeds; + } + std::string describe() const override { + return "CheckedTestingGenericMatcher set to " + (matchSucceeds ? std::string("succeed") : std::string("fail")); + } + }; + + TEST_CASE("Composed generic matchers shortcircuit", "[matchers][composed][generic]") { + // Check that if first returns false, second is not touched + CheckedTestingGenericMatcher first, second; + SECTION("MatchAllOf") { + first.matchSucceeds = false; + + Detail::MatchAllOfGeneric + matcher{ first, second }; + + CHECK_FALSE( matcher.match( 1 ) ); + + // These two assertions are the important ones + REQUIRE(first.matchCalled); + REQUIRE(!second.matchCalled); + } + // Check that if first returns true, second is not touched + SECTION("MatchAnyOf") { + first.matchSucceeds = true; + + Detail::MatchAnyOfGeneric + matcher{ first, second }; + CHECK(matcher.match(1)); + + // These two assertions are the important ones + REQUIRE(first.matchCalled); + REQUIRE(!second.matchCalled); + } + } template