-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add support for std::function in MockFunction (#2277) #2350
Add support for std::function in MockFunction (#2277) #2350
Conversation
e51f252
to
b9b50e3
Compare
b9b50e3
to
75c17f9
Compare
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.
Nice style, that's a very clean piece of code. I like the cleverness of how you approached writing unit tests as you employ a compiler to do most of the work.
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.
One thing I forgot to ask you is whether the diff in googlemock/include/gmock/gmock-spec-builders.h has to be so huge :)
I don't know how to make it smaller. The change is simple - added part around |
Yes, sometimes the diff algorithm gets crazy. Thanks and keep up the good work :) |
d971444
to
6892c20
Compare
@gennadiycivil this was split out from #2319, would you mind taking a look? I was looking for something like this today and realized @adambadura had already written it in OSS land. |
985ba25
to
b536866
Compare
b536866
to
4d48d6b
Compare
4d48d6b
to
30f54af
Compare
@adambadura Thank you for the PR! After discussing this with the other owners, we're not interested in changing the "meaning" of the name MockFunction (from class template to alias template). That said, we would be willing to consider a new name for this exact behavior. The new name would be an alias template out the gate. Is that a change you'd be open to? |
@CJ-Johnson Sure. I prefer my approach, but I'm fine with your approach as well. And definitely either one is better than none. ;) However, what precisely you want to get?
|
30f54af
to
bc22d86
Compare
Sorry for the delay.
Thanks for the effort! |
519c495
to
ec9081a
Compare
d5d0e9e
to
f028173
Compare
f028173
to
f04d2a0
Compare
f04d2a0
to
334d349
Compare
334d349
to
69de33e
Compare
69de33e
to
363a782
Compare
After testing this change, I found that this breaks valid use cases. Eg, this code:
will not be able to deduce the T anymore when passing an instance of the type. We have to keep
|
363a782
to
8cfb40c
Compare
8cfb40c
to
5ee757d
Compare
@sbenzaquen, I have implemented it the way you suggested. Also, I have added tests that check the property you asked for so that no such error is made in the future. However, I don't know why the verification failed. It did work on my (similar I think) configuration at my end. And I don't know how to get to exact logs of the failure. What can I do about it? |
5ee757d
to
a47a850
Compare
a47a850
to
b73a04a
Compare
The problem is that tests in the different _test.cc files have the same names and are colliding when running the gmock_all test. (they are all linked together and failing then). |
b73a04a
to
0dbed89
Compare
It did help! Thanks! I just couldn't see what is the problem. I tried building on Linux subsystem on my Windows and even on Linux itself at work but got the same and didn't know how to proceed. Now it works. Although I used a different naming approach, to mimic already existing one in those files. However, I wonder why those tests are duplicated in the first place. |
0dbed89
to
dbdc618
Compare
dbdc618
to
5b7a3fb
Compare
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
5b7a3fb
to
53740eb
Compare
@sbenzaquen , can we finally proceed with this change? |
PiperOrigin-RevId: 302677275
MocFunction
is slightly changed to transform its argument through (added in this change)SignatureOf
meta-function. The meta-function extracts the function signature type from the provided type. Thanks to this approachMockFunction<F>
can now be used withF
being both function signature (likebool(int)
) andstd::function
(likestd::function<bool(int)>
).Besides the immediate benefit, extra extensibility is added. Library user can specialize
SignaturOf
for other types (likeboost::function
) to gain the same support level.Note that this PR comes from #2319.