Refactor how shortcircuiting of old style matchers is tested

This commit is contained in:
Martin Hořeňovský 2020-07-26 21:31:29 +02:00
parent ac54ba7e12
commit 5ca68829e1
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 32 additions and 32 deletions

View File

@ -435,10 +435,10 @@ Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true
Matchers.tests.cpp:<line number>: passed: matcher.match(1) for: true Matchers.tests.cpp:<line number>: passed: matcher.match(1) for: true
Matchers.tests.cpp:<line number>: passed: first.matchCalled for: true Matchers.tests.cpp:<line number>: passed: first.matchCalled for: true
Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true
Matchers.tests.cpp:<line number>: passed: 1, !(first && second) for: 1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to fail ) Matchers.tests.cpp:<line number>: passed: !(matcher.match( 1 )) for: !false
Matchers.tests.cpp:<line number>: passed: first.matchCalled for: true Matchers.tests.cpp:<line number>: passed: first.matchCalled for: true
Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true
Matchers.tests.cpp:<line number>: passed: 1, first || second for: 1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail ) Matchers.tests.cpp:<line number>: passed: matcher.match( 1 ) for: true
Matchers.tests.cpp:<line number>: passed: first.matchCalled for: true Matchers.tests.cpp:<line number>: passed: first.matchCalled for: true
Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true Matchers.tests.cpp:<line number>: passed: !second.matchCalled for: true
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Contains("not there", Catch::CaseSensitive::No) for: "this string contains 'abc' as a substring" contains: "not there" (case insensitive) Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Contains("not there", Catch::CaseSensitive::No) for: "this string contains 'abc' as a substring" contains: "not there" (case insensitive)

View File

@ -3419,16 +3419,15 @@ with expansion:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Composed matchers shortcircuit Composed matchers shortcircuit
&& MatchAllOf
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Matchers.tests.cpp:<line number> Matchers.tests.cpp:<line number>
............................................................................... ...............................................................................
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( 1, !(first && second) ) CHECK_FALSE( matcher.match( 1 ) )
with expansion: with expansion:
1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to !false
fail )
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( first.matchCalled ) REQUIRE( first.matchCalled )
@ -3442,16 +3441,15 @@ with expansion:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Composed matchers shortcircuit Composed matchers shortcircuit
|| MatchAnyOf
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Matchers.tests.cpp:<line number> Matchers.tests.cpp:<line number>
............................................................................... ...............................................................................
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( 1, first || second ) CHECK( matcher.match( 1 ) )
with expansion: with expansion:
1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail true
)
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( first.matchCalled ) REQUIRE( first.matchCalled )

View File

@ -392,8 +392,8 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Comparisons with int literals don't warn when mixing signed/ unsigned" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Comparisons with int literals don't warn when mixing signed/ unsigned" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Composed generic matchers shortcircuit/MatchAllOf" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Composed generic matchers shortcircuit/MatchAllOf" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Composed generic matchers shortcircuit/MatchAnyOf" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Composed generic matchers shortcircuit/MatchAnyOf" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Composed matchers shortcircuit/&amp;&amp;" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Composed matchers shortcircuit/MatchAllOf" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Composed matchers shortcircuit/||" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Composed matchers shortcircuit/MatchAnyOf" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Contains string matcher" time="{duration}" status="run"> <testcase classname="<exe-name>.global" name="Contains string matcher" time="{duration}" status="run">
<failure message="testStringForMatching(), Contains(&quot;not there&quot;, Catch::CaseSensitive::No)" type="CHECK_THAT"> <failure message="testStringForMatching(), Contains(&quot;not there&quot;, Catch::CaseSensitive::No)" type="CHECK_THAT">
FAILED: FAILED:

View File

@ -959,8 +959,8 @@ Exception.tests.cpp:<line number>
<testCase name="Combining templated matchers" duration="{duration}"/> <testCase name="Combining templated matchers" duration="{duration}"/>
<testCase name="Composed generic matchers shortcircuit/MatchAllOf" duration="{duration}"/> <testCase name="Composed generic matchers shortcircuit/MatchAllOf" duration="{duration}"/>
<testCase name="Composed generic matchers shortcircuit/MatchAnyOf" duration="{duration}"/> <testCase name="Composed generic matchers shortcircuit/MatchAnyOf" duration="{duration}"/>
<testCase name="Composed matchers shortcircuit/&amp;&amp;" duration="{duration}"/> <testCase name="Composed matchers shortcircuit/MatchAllOf" duration="{duration}"/>
<testCase name="Composed matchers shortcircuit/||" duration="{duration}"/> <testCase name="Composed matchers shortcircuit/MatchAnyOf" duration="{duration}"/>
<testCase name="Contains string matcher" duration="{duration}"> <testCase name="Contains string matcher" duration="{duration}">
<failure message="CHECK_THAT(testStringForMatching(), Contains(&quot;not there&quot;, Catch::CaseSensitive::No))"> <failure message="CHECK_THAT(testStringForMatching(), Contains(&quot;not there&quot;, Catch::CaseSensitive::No))">
FAILED: FAILED:

View File

@ -869,13 +869,13 @@ ok {test-number} - first.matchCalled for: true
# Composed generic matchers shortcircuit # Composed generic matchers shortcircuit
ok {test-number} - !second.matchCalled for: true ok {test-number} - !second.matchCalled for: true
# Composed matchers shortcircuit # 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 # Composed matchers shortcircuit
ok {test-number} - first.matchCalled for: true ok {test-number} - first.matchCalled for: true
# Composed matchers shortcircuit # Composed matchers shortcircuit
ok {test-number} - !second.matchCalled for: true ok {test-number} - !second.matchCalled for: true
# Composed matchers shortcircuit # 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 # Composed matchers shortcircuit
ok {test-number} - first.matchCalled for: true ok {test-number} - first.matchCalled for: true
# Composed matchers shortcircuit # Composed matchers shortcircuit

View File

@ -3769,13 +3769,13 @@ Nor would this
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="Composed matchers shortcircuit" tags="[composed][matchers]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <TestCase name="Composed matchers shortcircuit" tags="[composed][matchers]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Section name="&amp;&amp;" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <Section name="MatchAllOf" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK_FALSE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original> <Original>
1, !(first &amp;&amp; second) !(matcher.match( 1 ))
</Original> </Original>
<Expanded> <Expanded>
1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to fail ) !false
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
@ -3796,13 +3796,13 @@ Nor would this
</Expression> </Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/> <OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="||" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <Section name="MatchAnyOf" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original> <Original>
1, first || second matcher.match( 1 )
</Original> </Original>
<Expanded> <Expanded>
1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail ) true
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >

View File

@ -638,22 +638,24 @@ namespace { namespace MatchersTests {
TEST_CASE("Composed matchers shortcircuit", "[matchers][composed]") { TEST_CASE("Composed matchers shortcircuit", "[matchers][composed]") {
// Check that if first returns false, second is not touched // Check that if first returns false, second is not touched
CheckedTestingMatcher first, second; CheckedTestingMatcher first, second;
SECTION("&&") { SECTION("MatchAllOf") {
first.matchSucceeds = false; first.matchSucceeds = false;
// This assertion doesn't actually test anything, we just
// want the composed matcher's `match` being called. Detail::MatchAllOf<int> matcher =
CHECK_THAT(1, !(first && second)); Detail::MatchAllOf<int>{} && first && second;
CHECK_FALSE( matcher.match( 1 ) );
// These two assertions are the important ones // These two assertions are the important ones
REQUIRE(first.matchCalled); REQUIRE(first.matchCalled);
REQUIRE(!second.matchCalled); REQUIRE(!second.matchCalled);
} }
// Check that if first returns true, second is not touched // Check that if first returns true, second is not touched
SECTION("||") { SECTION("MatchAnyOf") {
first.matchSucceeds = true; first.matchSucceeds = true;
// This assertion doesn't actually test anything, we just
// want the composed matcher's `match` being called. Detail::MatchAnyOf<int> matcher =
CHECK_THAT(1, first || second); Detail::MatchAnyOf<int>{} || first || second;
CHECK( matcher.match( 1 ) );
// These two assertions are the important ones // These two assertions are the important ones
REQUIRE(first.matchCalled); REQUIRE(first.matchCalled);