dsymonds/gomock — Issue #8: Use reflection for mockgen?
Author: jacobsa
Created: 2012-01-10 04:17:22+00:00
State: open

I've hacked together a version of mockgen that uses reflection to operate on installed packages (actually anything `go build` can find, including source cloned into `$GOPATH`):

https://github.com/jacobsa/gomock/compare/master...reflect

It's a lot easier to use for complicated cases because you don't have to give it a bunch of source-level info. Compare:

# Before
mockgen --source=user.go --aux_files=imp1=imp1/imp1.go --imports=.=github.com/dsymonds/gomock/sample/imp3,imp_four=github.com/dsymonds/gomock/sample/imp4

# After
mockgen github.com/dsymonds/gomock/sample Index Embed

The implementation is slightly simpler too, but maybe not by a lot? Anyway, I think the user-facing complexity is more important. The biggest downside I can see is that it's harder to present good errors, e.g. in the case of a misspelled interface name. But with some polishing work I think that could be done.

Dave, what do you think of this?