I'm curious where sentiments lie on the use of GMock in general, and in the use of GMock's matchers in particular, and to see how that applies to our coding style and our testing style. That is, do we hold that GoogleTest's upstream guidance is on the same level, of say, Google Coding Style guidance? Do we want that to be reflected in Chromium or diverge from it? As reviewers, should we encourage people to use EXPECT_THAT? Or, as reviewers, should we discourage people from using MATCHER_P?
Does this guidance from the googletest folks match how Google internally is now guided and is shifting use? I would say following Google recommended practice is probably more important than following the googletest recommended practice, if the two differ.
The FAQ does not say in detail why there's a recommendation for matchers over EXPECT_XX macros, other than that matchers can be combined (e.g. AnyOf() in your example). It would be nice to know what other pros and cons they would cite.
I think while there may be knee-jerk reluctance to use GMock because GMock, in this case there aren't many problems;
On Tue, Sep 13, 2016 at 1:35 PM, Peter Kasting <pkas...@chromium.org> wrote:Does this guidance from the googletest folks match how Google internally is now guided and is shifting use? I would say following Google recommended practice is probably more important than following the googletest recommended practice, if the two differ.This is an area where it's not readily clear that there is any Google advice other than the GoogleTest/GTest advice.
The FAQ does not say in detail why there's a recommendation for matchers over EXPECT_XX macros, other than that matchers can be combined (e.g. AnyOf() in your example). It would be nice to know what other pros and cons they would cite.Agreed. Of course, it'd also be useful if anyone on chromium-dev@ would cite examples too :)I think while there may be knee-jerk reluctance to use GMock because GMock, in this case there aren't many problems;I would disagree when you consider what the implementation of a matcher needs to look like.If we use the MATCHER_P syntax, my convoluted example of net::IsError becomesMATCHER_P(IsError, expected, std::string(negation ? "not " : "") + net::ErrorToString(expected)) {if (arg <= 0)*result_listener << net::ErrorToString(arg);return arg == expected;}As a reader, I'm not sure if this code is clear - |arg| and |*result_listener| being hidden variables are loosely documented in https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#writing-new-matchers-quickly (and slightly more thoroughly in https://github.com/google/googletest/blob/d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0/googlemock/include/gmock/gmock-generated-matchers.h#L1166 ). However, note how for matchers, the code needs to be all inlined.Of course, using MATCHER_P is actively discouraged, per https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#writing-new-parameterized-matchers-quickly , with the advice "While it's tempting to always use the MATCHER* macros when defining a new matcher, you should also consider implementing MatcherInterface or using MakePolymorphicMatcher() instead (see the recipes that follow), especially if you need to use the matcher a lot. While these approaches require more work,"For the above 'simple' case I gave, if you wanted to handle both int and net::Error results (since we pass net::Errors as ints if they can also be sizes), you'd have to implement a polymorphic matcher to handle the type coercions, including printing the output (GTest/GMock's pretty-printer is in the internal namespace, with strong admonitions not to use)That's perhaps a longer explanation over the concern. Having looked at GMock matchers several times, I'm not sure if they help readability/maintainability. I'd be especially curious if there were things that GTest made harder than GMock, since I've generally seen "Have to dig in for 30 minutes in GMock docs & headers & look at how Google is using it to make sense of how this code being submitted is using it, and still not be sure if it's the Right Way"
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
I'd be especially curious if there were things that GTest made harder than GMock,
So tests end up being much more readable than writable.
--