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. |
|
@LandonTClipp that's aggravating. For what it's worth, I'd support merging this with some sort of experimental tag/designation: I (and I suspect many others) don't need ongoing compatibility with go-mock, I just need an off-ramp that lets me convert to something that won't waste hours of cpu time per day in my CI pipeline. |
|
Doing it as an experiment is totally fine. Give me a few days to revisit this and maybe we can get it merged. Ping me if I don't respond in a week. |
|
After looking at this PR again, I want to merge the gomock bits but there are many irrelevant changes that need to be taken out before we can do this. For example:
Touching such a large number of pieces of the project in one PR is dangerous. I'm not opposed in principle to the changes, just not all in one PR. @kszafran what do you think? Can you reduce the changes being proposed in this PR to just what is relevant to make gomock work? |
Commits in this PR are mostly self-contained, so we could e.g. pull a few initial commits into a separate PR. That would make sense if you squash the commits on merge. But it seems to me that this isn't the case in this repository. Since individual commits would be preserved after merge, I'm not sure what the benefit would be? I can try to split off some commits anyway. |
|
It's more for reviewers like me, not git history. It's harder to give attention to so many changes in one PR. |
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