diff options
| author | Martin Hořeňovský | 2020-07-26 21:22:13 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-07-26 21:24:05 +0200 |
| commit | ac54ba7e12b77a4d88a42ee19cb193c4bd3c33ad (patch) | |
| tree | ca0f8bc12a9471c4dcfab8e51c02816a04a5e36f /tests/SelfTest/UsageTests/Matchers.tests.cpp | |
| parent | 95c0c88d84e61121d3f5a725584695d44ded13bc (diff) | |
| download | catch3-ac54ba7e12b77a4d88a42ee19cb193c4bd3c33ad.tar.gz | |
Add test for shortcircuiting behaviour of generic matcher combinators
Diffstat (limited to 'tests/SelfTest/UsageTests/Matchers.tests.cpp')
| -rw-r--r-- | tests/SelfTest/UsageTests/Matchers.tests.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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<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> |