-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: generic matchers #1843
Conversation
Codecov Report
@@ Coverage Diff @@
## dev-v3 #1843 +/- ##
==========================================
+ Coverage 89.12% 89.24% +0.12%
==========================================
Files 142 144 +2
Lines 6037 6133 +96
==========================================
+ Hits 5380 5473 +93
- Misses 657 660 +3 |
I fixed it up a bit. |
EvilMatcher const* operator& () const { | ||
throw EvilAddressOfOperatorUsed(); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about operator,
? 😈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anything here is vulnerable to that right now, but it can't hurt :)
TEST_CASE("Overloaded address-of operator is not used", "[matchers][templated]") { | ||
REQUIRE_NOTHROW(EvilMatcher() || EvilMatcher()); | ||
REQUIRE_NOTHROW(EvilMatcher() && EvilMatcher()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add !
just to be thorough.
Cool, thanks. |
#include <string> | ||
#include <type_traits> | ||
#include <utility> | ||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include should not be needed (I am also not sure what is used for, but I did not look hard)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to remove the include.
...and avoid copying their internal vectors. Also check that new operator templates are not used with old matchers.
... and pass by reference to matcher, to allow matchers capturing by mutable reference
Move most of the implementation which doesn't depend on template arguments to .cpp file. Address review comments: - use StringRef for combine argument - calculate correct amount of space to reserve
remove index_sequence using declarations replace last address-of operator use with std::addressof
Sorry, rebased again. |
Description
Currently, composable matchers are based on
MatcherBase<T>
, likeEqualsMatcher<T>
.EqualsMatcher<T>
can compare twostd::vector<T>
s for equality, but not astd::vector
and astd::array
, for example.This can make writing tests cumbersome somtimes, as you either need to write your own matcher
for whatever containers you need to work with, or convert everything to
std::vector
.This PR aims to implement support for matchers that can be generic in their argument types, while also:
Here is a motivating example:
While it's easy to write your own custom
EqualsRange
matcher, making it composable with other matchers using &&, ||, ! is not, since that requires deriving from a sharedMatcherBase<T>
.With the changes from this PR, an implementation of
EqualsRange
could look like this: