This repository was archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 608
calling Recorder methods with numbers causes misses due to Go's untyped constant rules #16
Comments
Sorry, had a bug in the test case. Fixed it up. |
Ugh, this also occurs with constants called on the recorder that will never change. I'm mocking out a statsd wrapper that always passes |
jmhodges
added a commit
to jmhodges/mock
that referenced
this issue
Dec 13, 2015
This uses the exact types needed in the Recorder methods. It avoids spurious expectation misses caused by Go converting untyped constants to types that do not match the interface generated for. One example is float literals passed to a `float32` argument were being converted on x86_64 machines to `float64` because the Recoder methods had a `interface{}` arg instead of a `float32` arg. Fixes golang#16
The arg types to Recorder methods are interface{} so that Matcher values may be passed (e.g. This is just an unfortunate consequence of trying to squeeze this kind of mocking into Go's type system. |
Of course. How silly of me. Sorry! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
With an interface
the code generated for the MockAdder has the correct int type:
while the Recorder has
interface{}
s for the argument:This, unfortunately, causes spurious missed expectation in the test case below. This is because the "2" is handed to the AdderRecorder as an
int
. This is Go's untyped int handling code choosingint
instead ofint64
as its default type since none is provided explicitly.It looks plausible from the code to generate the
Recorder
methods with the right argument types and convert them down as the call method one does. (But maybe I haven't seen the bug that prevented that in the first place.)One workaround is to just use the same variable in both places and another is to explicitly convert it to the right type, but it might nice for small tests to just make the right type.
The text was updated successfully, but these errors were encountered: