-
Notifications
You must be signed in to change notification settings - Fork 606
Error output is ambiguous for equivalent values with different types #190
Comments
I agree that this seems like something we should do. I would be willing to look at PR for this. Types might add a bit of noise if always there. Could hide that info behind a verbose flag as well... If you liked this issue feel free to share your thoughts. |
Another usecase from #267
Example: --- FAIL: TestNilVsEmpty (0.00s)
example_test.go:24: Unexpected call to *mock_example.MockThing.Apply([0xc0000900a0]) at /usr/local/google/home/briankennedy/golang/work/src/github.com/briantkennedy/mockbug/pkg/mock_example/mock_thing.go:39 because:
Expected call at /usr/local/google/home/briankennedy/golang/work/src/github.com/briantkennedy/mockbug/pkg/example/example_test.go:19 doesn't match the argument at index 0.
Got: &{[]}
Want: is equal to &{[]}
asm_amd64.s:522: missing call(s) to *mock_example.MockThing.Apply(is equal to &{[]}) /usr/local/google/home/briankennedy/golang/work/src/github.com/briantkennedy/mockbug/pkg/example/example_test.go:19
asm_amd64.s:522: aborting test due to missing call(s)
FAIL
FAIL github.com/briantkennedy/mockbug/pkg/example 0.021s
? github.com/briantkennedy/mockbug/pkg/mock_example [no test files] repository with code that reproduces issue: https://github.com/briantkennedy/mockbug cc: @briantkennedy |
I hit this exact issue today. In my case, I was using a simple type alias
As someone fairly new to go mocking, this really stumped me for awhile Maybe the answer to this, before printing the statement, is to check the value string representations, and if they are equal, print the types of the got and expected? |
Got the same issue
Any update? For those looking for a temp fix, changing the autogenerated mock file's method input param type from "interface{}" to desired type fixed is for me. |
@xapatjb4 The same problem, any good workaround? I use the following methods to fix it, but looks like a bad one:
|
- Adds type information to the default got formatter. - Adds type to default want formatter. This happens to be gomock.Eq. Adding more information for debugging seems like a good idea in this case as well. Fixes: #190
Same issue here :( Not matching equivalent values with different types |
@iurydias Are you using |
Edit: I updated and now we can see the type on output, so much better! |
I just got the same error here:
version: @codyoss, can you help me? Am I doing something wrong? |
I just got the same error here |
Please open a new issue with code to reproduce. |
mock/gomock/matchers.go
Line 53 in 22bbf0d
When printing output for matched errors, if the expected and actual value have different types, either a special message should be printed (ie. expected value type does not match actual value type), or simply print the type with the output.
My confusing error output:
In this case, I was using a
const val = 8
which is resolved to anint
. The const is used in the innards of a struct that expects anint32
(so the const is correctly casted). The const is then passed as the parameter to a method mocked byEXPECT()
that originally takes anint32
, but the mock version of the method takes aninterface{}
. Therefore, in the second case, the const is never casted correctly to int32 and causes a type mismatch further down the call path.The long story short is, it's possible for gomock to print equivalent values without type information.
The text was updated successfully, but these errors were encountered: