code-mx / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Better error reporting for undefined default return values #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Lets say we add the following test in test/gmock-spec-builders_test.cc:
TEST(UninterestingCallTest, FailureOnUndefinedDefaultAction) {
  MockA a;
  Result r = a.ReturnResult(0);
}

2. Or a test like this:
TEST(UnexpectedCallTest, FailyureOnUnderfinedDefaultAction) {
  FLAGS_gmock_verbose = "info";
  MockA a;
  EXPECT_CALL(a, ReturnResult(1)).WillOnce(Return(Result()));
  Result r = a.ReturnResult(0);
}

What is the expected output? What do you see instead?
To my understanding the first one is an Uninteresting call while the second
is an Unexpected call. Both have the same output:

Stack trace:
./include/gmock/gmock-actions.h:73: Failure
Default action undefined for the function return type.
Abort trap

What version of the product are you using? On what operating system?
1.0
Mac OS X

Please provide any additional information below.
I would like to see test output like this:

Uninteresting mock function call - returning default value.
    Function call: ReturnResult(0)
    Undefined default return value.
Abort trap

And like this:

Unexpected mock function call - returning default value.
    Function call: ReturnResult(0)
    Undefined default return value.
Abort trap

This is caused because we are trying do a
BuiltInDefaultValue<Result>::Get() which dies since Result has no default
value. I suggest we add a way to check whether we have a defined default
value before we call FunctionMockerBase::PerformDefaultAction(...)

I have a patch which does this.

Original issue reported on code.google.com by sunds...@gmail.com on 18 Dec 2008 at 9:07

GoogleCodeExporter commented 9 years ago
In case 2. above I want to get extra information about what didn't match. Like 
this:
Stack trace:

Google Mock tried the following 1 expectation, but it didn't match:

test/gmock-spec-builders_test.cc:XXX: 
  Expected arg #0: is equal to 1
           Actual: 0
         Expected: to be called once
           Actual: never called - unsatisfied and active

Original comment by sunds...@gmail.com on 18 Dec 2008 at 9:09

GoogleCodeExporter commented 9 years ago

Original comment by shiq...@gmail.com on 22 Dec 2008 at 8:02

GoogleCodeExporter commented 9 years ago
Fixed in r88

Original comment by sunds...@gmail.com on 1 Feb 2009 at 12:00

GoogleCodeExporter commented 9 years ago
This is in the trunk and will be part of the next release.

Original comment by zhanyong...@gmail.com on 6 Feb 2009 at 7:43