Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-07-26 21:22:13 +0200
committerMartin Hořeňovský2020-07-26 21:24:05 +0200
commitac54ba7e12b77a4d88a42ee19cb193c4bd3c33ad (patch)
treeca0f8bc12a9471c4dcfab8e51c02816a04a5e36f /tests/SelfTest/UsageTests
parent95c0c88d84e61121d3f5a725584695d44ded13bc (diff)
downloadcatch3-ac54ba7e12b77a4d88a42ee19cb193c4bd3c33ad.tar.gz
Add test for shortcircuiting behaviour of generic matcher combinators
Diffstat (limited to 'tests/SelfTest/UsageTests')
-rw-r--r--tests/SelfTest/UsageTests/Matchers.tests.cpp43
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>