MATCHERs vs ACTIONs for printing details about large structures that didn't match

50 views
Skip to first unread message

Maurice van der Pot

unread,
Aug 10, 2016, 10:48:30 AM8/10/16
to Google C++ Mocking Framework
In some of our tests we expect a single call to a function that has a large structure as an input parameter. We want to test if a subset of the members of this structure are set to certain values. Because the structure is so large, we are interested in knowing which fields differed if the expectation didn't match.

We could create a matcher with the MATCHER macro, but if the expectation is not matched we can only see the generic message for this matcher.
We could add prints to the matcher (and it will work in our case), but matchers are not supposed to have side-effects because they may be evaluated multiple times.
Alternatively we could accept any value for the structure in the expectation (testing::_) and define an ACTION that prints how the actual structure differs from the one we expect.
Maybe there are other options that I haven't considered.

What would be the best way to deal with this situation?

Best regards,
Maurice.

Samuel Benzaquen

unread,
Aug 10, 2016, 3:29:56 PM8/10/16
to Maurice van der Pot, Google C++ Mocking Framework
Matchers can return textual results on failure.
The MATCHER* macros provide an implicit argument 'result_listener' of type std::ostream*

_Sam


Best regards,
Maurice.

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/0c8df730-cbfb-4ef5-96ab-818c385e644d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages