1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-16 15:18:00 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Martin Hořeňovský
5f6990d746
Only start Section's timer if the duration will be used
This is a small potential runtime optimization on systems with
virtual syscalls, and a significant runtime optimization on systems
without.
2020-07-26 21:33:49 +02:00
Martin Hořeňovský
5ca68829e1
Refactor how shortcircuiting of old style matchers is tested 2020-07-26 21:31:29 +02:00
Martin Hořeňovský
ac54ba7e12
Add test for shortcircuiting behaviour of generic matcher combinators 2020-07-26 21:24:05 +02:00
11 changed files with 218 additions and 45 deletions

View File

@ -16,7 +16,11 @@ namespace Catch {
: m_info( info ),
m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
{
m_timer.start();
// Non-"included" sections will not use the timing information
// anyway, so don't bother with the potential syscall.
if (m_sectionIncluded) {
m_timer.start();
}
}
Section::~Section() {

View File

@ -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

View File

@ -429,10 +429,16 @@ Condition.tests.cpp:<line number>: passed: 4 == ul for: 4 == 4
Condition.tests.cpp:<line number>: passed: 5 == c for: 5 == 5
Condition.tests.cpp:<line number>: passed: 6 == uc for: 6 == 6
Condition.tests.cpp:<line number>: passed: (std::numeric_limits<uint32_t>::max)() > ul for: 4294967295 (0x<hex digits>) > 4
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: !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: !second.matchCalled for: true
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: !second.matchCalled 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: !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)

View File

@ -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

View File

@ -3374,17 +3374,38 @@ with expansion:
4294967295 (0x<hex digits>) > 4
-------------------------------------------------------------------------------
Composed matchers shortcircuit
&&
Composed generic matchers shortcircuit
MatchAllOf
-------------------------------------------------------------------------------
Matchers.tests.cpp:<line number>
...............................................................................
Matchers.tests.cpp:<line number>: 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:<line number>: PASSED:
REQUIRE( first.matchCalled )
with expansion:
true
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( !second.matchCalled )
with expansion:
true
-------------------------------------------------------------------------------
Composed generic matchers shortcircuit
MatchAnyOf
-------------------------------------------------------------------------------
Matchers.tests.cpp:<line number>
...............................................................................
Matchers.tests.cpp:<line number>: PASSED:
CHECK( matcher.match(1) )
with expansion:
true
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( first.matchCalled )
@ -3398,16 +3419,37 @@ with expansion:
-------------------------------------------------------------------------------
Composed matchers shortcircuit
||
MatchAllOf
-------------------------------------------------------------------------------
Matchers.tests.cpp:<line number>
...............................................................................
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( 1, first || second )
CHECK_FALSE( matcher.match( 1 ) )
with expansion:
1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail
)
!false
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( first.matchCalled )
with expansion:
true
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( !second.matchCalled )
with expansion:
true
-------------------------------------------------------------------------------
Composed matchers shortcircuit
MatchAnyOf
-------------------------------------------------------------------------------
Matchers.tests.cpp:<line number>
...............................................................................
Matchers.tests.cpp:<line number>: PASSED:
CHECK( matcher.match( 1 ) )
with expansion:
true
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE( first.matchCalled )
@ -15612,6 +15654,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="132" tests="2001" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="132" tests="2007" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/>
@ -390,8 +390,10 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Comparisons between ints where one side is computed" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" 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 matchers shortcircuit/&amp;&amp;" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Composed matchers shortcircuit/||" 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 matchers shortcircuit/MatchAllOf" 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">
<failure message="testStringForMatching(), Contains(&quot;not there&quot;, Catch::CaseSensitive::No)" type="CHECK_THAT">
FAILED:

View File

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

View File

@ -856,14 +856,26 @@ 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<uint32_t>::max)() > ul for: 4294967295 (0x<hex digits>) > 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 )
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
@ -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

View File

@ -259,6 +259,8 @@ Exception.tests.cpp:<line number>|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']

View File

@ -3711,14 +3711,14 @@ Nor would this
</Expression>
<OverallResult success="true"/>
</TestCase>
<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" >
<Expression success="true" type="CHECK_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<TestCase name="Composed generic matchers shortcircuit" tags="[composed][generic][matchers]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Section name="MatchAllOf" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_FALSE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
1, !(first &amp;&amp; second)
!(matcher.match( 1 ))
</Original>
<Expanded>
1 not ( CheckedTestingMatcher set to fail and CheckedTestingMatcher set to fail )
!false
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
@ -3739,13 +3739,70 @@ Nor would this
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<Section name="||" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Section name="MatchAnyOf" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
1, first || second
matcher.match(1)
</Original>
<Expanded>
1 ( CheckedTestingMatcher set to succeed or CheckedTestingMatcher set to fail )
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
first.matchCalled
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
!second.matchCalled
</Original>
<Expanded>
true
</Expanded>
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Composed matchers shortcircuit" tags="[composed][matchers]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Section name="MatchAllOf" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_FALSE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
!(matcher.match( 1 ))
</Original>
<Expanded>
!false
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
first.matchCalled
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
!second.matchCalled
</Original>
<Expanded>
true
</Expanded>
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<Section name="MatchAnyOf" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
matcher.match( 1 )
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
@ -18511,9 +18568,9 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1831" failures="149" expectedFailures="21"/>
<OverallResultsCases successes="258" failures="86" expectedFailures="4"/>
<OverallResults successes="1837" failures="149" expectedFailures="21"/>
<OverallResultsCases successes="259" failures="86" expectedFailures="4"/>
</Group>
<OverallResults successes="1831" failures="148" expectedFailures="21"/>
<OverallResultsCases successes="258" failures="86" expectedFailures="4"/>
<OverallResults successes="1837" failures="148" expectedFailures="21"/>
<OverallResultsCases successes="259" failures="86" expectedFailures="4"/>
</Catch>

View File

@ -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<int> matcher =
Detail::MatchAllOf<int>{} && 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<int> matcher =
Detail::MatchAnyOf<int>{} || first || second;
CHECK( matcher.match( 1 ) );
// These two assertions are the important ones
REQUIRE(first.matchCalled);
@ -661,6 +663,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<CheckedTestingGenericMatcher,
CheckedTestingGenericMatcher>
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<CheckedTestingGenericMatcher,
CheckedTestingGenericMatcher>
matcher{ first, second };
CHECK(matcher.match(1));
// These two assertions are the important ones
REQUIRE(first.matchCalled);
REQUIRE(!second.matchCalled);
}
}
template<typename Range>