-
Notifications
You must be signed in to change notification settings - Fork 449
Support gomock #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3
Are you sure you want to change the base?
Support gomock #1030
Conversation
|
Wow! That's wonderful! I will take a closer look next week. In the meantime, it's worth opening a dialogue with the gomock maintainers because the question of whether we host the template in this project or not is really a question on whether gomock itself should be forked (as that is effectively what it would mean to host it here). |
|
I couldn't help myself and made two further improvements (two new commits):
I left a comment in my original issue (uber-go/mock#245). To be precise, this would be forking only |
4edd2e7 to
b2dbc5d
Compare
|
Has there been any further movement on getting this merged / coordinating with the gomock team? An order-of-magnitude improvement in mockgen time is something I'd very much like to see, and I suspect I'm far from alone! |
@n-oden no they seem unresponsive. The likelihood they will support something like this is very very low. I'd be open to the idea of merging this as an experiment but without explicit support on their side, I cannot guarantee the correctness of it. |
Description
This PR adds support for generating gomock mocks. It's a follow-up to a PR I created directly to gomock, trying to add a batch mode in order to reduce generation time.
Using mockery, I got an even better improvement in generation time. Calling mockgen on 78 packages in my project sequentially:
Running mockery to generate them all at once:
which is almost 30x reduction in real time (40x in CPU time).
This PR also includes a few small improvements:
SignatureNoName()will now avoid wrapping single return arg in parentheses —(string)->string(a int, b int, c int)->(a, b, c int).SrcPkgName,.SrcPkgPath,.Interfaces.NameList,listandappendfunctionsI tried to keep the template file close in structure to the original
mockgencode, so that it's easy to update in the future to reflect changes inmockgen.Type of change
Version of Go used when building/testing:
How Has This Been Tested?
I regenerated mocks using mockery in my private project. The output is pretty faithful to the code generated by
mockgen.The differences I noticed are:
mockgen:mockery:mockgenalways uses aliases likegomock "go.uber.org/mock/gomock").mockeryalways suggests some nice arg names inDo,Return,DoAndReturn(these functions take the return args of the mocked method), whilemockgenusesarg0,arg1, ...mockerykeeps arg names in function types (f func(projectIDs []string)), whilemockgendrops them (f func([]string))Checklist