-
Notifications
You must be signed in to change notification settings - Fork 606
Conversation
3c6dd7e
to
4fc27f1
Compare
Open question about this PR: Note: This PR verifies the return args for both |
4fc27f1
to
7d8f57b
Compare
@@ -1,6 +1,7 @@ | |||
package gomock | |||
|
|||
import ( | |||
"reflect" |
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.
Could you add the copyright to this file. Eventually we need to go and get all the files caught up.
I did some brief testing and found that gomock currently allows arguments to However, gomock raises an obscure error when arguments to |
0501097
to
5aae07b
Compare
67f48ca
to
dbb6401
Compare
panic(fmt.Sprintf("DoAndReturn: %s", err)) | ||
} | ||
default: | ||
panic("DoAndReturn: argument must be a function") |
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.
Since we are now explicitly panicing I think we should update the doc string.
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.
Updated
} | ||
|
||
func interfaceArg(actualArg, expectedArg reflect.Type) error { | ||
if !actualArg.ConvertibleTo(expectedArg) { |
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.
Honest question: Does this cover the implements?
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.
Yes it does, if expectedArg is something like Stringer
and actualArg
is an instance of some type Foo
which implements Stringer
this line will evaluate to true.
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.
I added another test case to make that more clear
Update the error handling for Call.Do and Call.DoAndReturn in the case where the argument passed does not match expectations. * panic if the argument is not a function * panic if the number of input arguments do not match those expected by Call * panic if the types of the input arguments do not match those expected by Call Call.DoAndReturn has additional validations on the return signature * panic if the number of return arguments do not match those expected by Call * panic if the types of return arguments do not match those expected by Call
dbb6401
to
e3d5d28
Compare
I was just reading over this issue. Made me question if we should be using panics at all. #158 (comment) This PR is just making panics in this case more explicit. I wonder in the future if we should recover all of them and t.Fatal with the TestReporter we should have access to in the controller. |
I think that is totally valid but brings up back to the question of what to do for code executing outside of the main goroutine where we can't call |
BTW this change was released as 1.4.2, changing only minor version. It breaks the current code. I think it should be released at least as 1.5.0. |
Can confirm that this is a breaking change. Gomock now interprets basic types wrong and complains that it wants an interface. |
Thank you for bring this up, that behavior was not intentional. Can you please provide a small example of code this breaks so we can add a better test. |
mock.EXPECT().Foo(gomock.Any()).DoAndReturn(func(...interface{}) error {return nil}) We didn't care about parameters so we left |
@Linus-Boehm was this a similar use case for you. I will be reverting for now and creating a new tag 1.4.3 until I have more time to evaluate how we want to move forward this this. |
New release with the change reverted: v1.4.3 |
It panics becuase "some-expected-string" is not an interface, so yeah that should be the same reason. |
@Linus-Boehm for clarity, what is the signature of method |
Fixes #71
Description
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.
by Call
Call.DoAndReturn has additional validations on the return signature
Call
Call
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
Reviewer Notes
Release Notes
Describe any changes here so maintainer can include it in the release notes, or delete this block.