From 5ca68829e10cc28471d2340439b53a41e8ff4e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 26 Jul 2020 21:31:29 +0200 Subject: [PATCH] Refactor how shortcircuiting of old style matchers is tested --- .../SelfTest/Baselines/compact.sw.approved.txt | 4 ++-- .../SelfTest/Baselines/console.sw.approved.txt | 14 ++++++-------- tests/SelfTest/Baselines/junit.sw.approved.txt | 4 ++-- .../Baselines/sonarqube.sw.approved.txt | 4 ++-- tests/SelfTest/Baselines/tap.sw.approved.txt | 4 ++-- tests/SelfTest/Baselines/xml.sw.approved.txt | 16 ++++++++-------- tests/SelfTest/UsageTests/Matchers.tests.cpp | 18 ++++++++++-------- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 05fc49df..bb73ca18 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -435,10 +435,10 @@ 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: !(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: 1, first || second for: 1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail ) +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:: failed: testStringForMatching(), Contains("not there", Catch::CaseSensitive::No) for: "this string contains 'abc' as a substring" contains: "not there" (case insensitive) diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 0f239c76..e4298d25 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -3419,16 +3419,15 @@ with expansion: ------------------------------------------------------------------------------- Composed matchers shortcircuit - && + MatchAllOf ------------------------------------------------------------------------------- Matchers.tests.cpp: ............................................................................... Matchers.tests.cpp:: PASSED: - CHECK_THAT( 1, !(first && second) ) + CHECK_FALSE( matcher.match( 1 ) ) with expansion: - 1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to - fail ) + !false Matchers.tests.cpp:: PASSED: REQUIRE( first.matchCalled ) @@ -3442,16 +3441,15 @@ with expansion: ------------------------------------------------------------------------------- Composed matchers shortcircuit - || + MatchAnyOf ------------------------------------------------------------------------------- Matchers.tests.cpp: ............................................................................... Matchers.tests.cpp:: PASSED: - CHECK_THAT( 1, first || second ) + CHECK( matcher.match( 1 ) ) with expansion: - 1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail - ) + true Matchers.tests.cpp:: PASSED: REQUIRE( first.matchCalled ) diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 7ef0bba4..e4004469 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -392,8 +392,8 @@ Exception.tests.cpp: - - + + FAILED: diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 1fd944a4..44f3adab 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -959,8 +959,8 @@ Exception.tests.cpp: - - + + FAILED: diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 6fb2aa15..187c6a42 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -869,13 +869,13 @@ 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 ) +ok {test-number} - !(matcher.match( 1 )) for: !false # Composed matchers shortcircuit ok {test-number} - first.matchCalled for: true # Composed matchers shortcircuit ok {test-number} - !second.matchCalled for: true # Composed matchers shortcircuit -ok {test-number} - 1, first || second for: 1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail ) +ok {test-number} - matcher.match( 1 ) for: true # Composed matchers shortcircuit ok {test-number} - first.matchCalled for: true # Composed matchers shortcircuit diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index c2109e5d..8604c74b 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -3769,13 +3769,13 @@ Nor would this -
- +
+ - 1, !(first && second) + !(matcher.match( 1 )) - 1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to fail ) + !false @@ -3796,13 +3796,13 @@ Nor would this
-
- +
+ - 1, first || second + matcher.match( 1 ) - 1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail ) + true diff --git a/tests/SelfTest/UsageTests/Matchers.tests.cpp b/tests/SelfTest/UsageTests/Matchers.tests.cpp index 8276cf84..b627d4a9 100644 --- a/tests/SelfTest/UsageTests/Matchers.tests.cpp +++ b/tests/SelfTest/UsageTests/Matchers.tests.cpp @@ -638,22 +638,24 @@ namespace { namespace MatchersTests { TEST_CASE("Composed matchers shortcircuit", "[matchers][composed]") { // Check that if first returns false, second is not touched CheckedTestingMatcher first, second; - SECTION("&&") { + SECTION("MatchAllOf") { first.matchSucceeds = false; - // This assertion doesn't actually test anything, we just - // want the composed matcher's `match` being called. - CHECK_THAT(1, !(first && second)); + + Detail::MatchAllOf matcher = + Detail::MatchAllOf{} && 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("||") { + SECTION("MatchAnyOf") { first.matchSucceeds = true; - // This assertion doesn't actually test anything, we just - // want the composed matcher's `match` being called. - CHECK_THAT(1, first || second); + + Detail::MatchAnyOf matcher = + Detail::MatchAnyOf{} || first || second; + CHECK( matcher.match( 1 ) ); // These two assertions are the important ones REQUIRE(first.matchCalled);