In case of match failure Google mock prints message like the following:
test.cpp:112: EXPECT_CALL(mock_obj, foo( MyMatcher( bar ) ))...
Expected arg #0: is equal to [1,2; 3,4]
Actual: { 1 }
Expected: to be called once
Actual: never called - unsatisfied and active
Using custom matcher MyMatcher I'm able to define a description string which is used to generate the failure message when the match fails. But it defines only Expected arg #0 part of message. Is there any way how I can customize how Actual is printed?
In my case I can't overload operator<< for class of bar as it already overloaded by third party code is not under my control (this library define class of bar and operator<< for it).
As I'm not able to define operator
<<
for my class
, google test have option to define PrintTo
function for it Teaching Google Test How to Print Your Values. Thanks RA for the link.
A user can override this behavior for a class type Foo by defining an overload of PrintTo() in the namespace where Foo is defined. We give the user this option as sometimes defining a << operator for Foo is not desirable (e.g. the coding style may prevent doing it, or there is already a << operator but it doesn't do what the user wants).
void PrintTo(const Bar& value, ::std::ostream* os);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With