Skip to content
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

The mockery project is now including moq-style mocks in an alpha release. #230

Open
LandonTClipp opened this issue Jan 2, 2025 · 1 comment

Comments

@LandonTClipp
Copy link

LandonTClipp commented Jan 2, 2025

As a follow up on #208, I've successfully integrated moq-style mocks into the mockery project, such that users may generate either mockery-style or moq-style mocks.

I've released a number of alpha builds and will begin testing throughout the coming weeks. Documentation here: https://vektra.github.io/mockery/v3/

Some things to note:

  1. It's very very alpha, but it seems to work reliably and without much fuss.
  2. The docs are going to be a living work of art, so expect some cobwebs and skeletons.

The real meat-and-potatoes of this can be seen in the docs here where the exact template can be selected. And, you can even provide your own template!

I drew heavy inspiration from all the contributors here, and even shamefully copy-pasted large swaths of this project because its implementation, especially in regards to source parsing, was just better in many regards. I am working on getting proper git attributions in line if anyone cares (and if not, please say because it would save me a lot of time. However, I can't claim work for myself!).

You may be asking "why fold the two projects together?" Well:

  1. Mockery parsing is way faster for large projects. Any source code parsing project that relies on //go:generate directives is doomed to have terrible big-O speed due to the fact that they re-parse the entire source syntax tree (including all dependencies for each file) for every //go:generate instantiation. mockery v2 and v3 do not do this, which leads to orders of magnitude performance increases.
  2. Mockery has a rich and flexible config scheme that allows controlling code generation for an entire project in an easily grok-able way.
  3. moq-style mocks are actually just better in general due to their simplicity, so it's closer to the Go ethos. I've come to the opinion that moq mocks should be pushed more than mockery mocks.
  4. This effort unlocks a key feature: allowing users of mockery to pass it their own templates. The open source community is vibrant and will no doubt come up with novel ideas. mockery and moq combining forces solves the interface parsing problem (which is not trivial) and allows users to focus on writing their own interface implementations.

I'm happy to add any admin or write-level contributors from moq over to mockery if they are interested. Forward any questions or discussions to the mockery repo. Thanks!

CC: @sudo-suhas @matryer @breml

@sudo-suhas
Copy link
Collaborator

That's great! No write contributions necessary for any of my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants