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

Make the parser accept index list expressions #857

Merged
merged 5 commits into from
Dec 4, 2024

Conversation

volmedo
Copy link
Contributor

@volmedo volmedo commented Dec 3, 2024

Description

Interfaces defined as instantiation of generic interfaces with more than one type parameter (example) are described as *ast.IndexListExpr by Go's AST library.

These interfaces were not accepted by the parser. This PR solves the issue by adding index list expressions as an accepted expression type.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Version of Go used when building/testing:

  • 1.22
  • 1.23

How Has This Been Tested?

Added a new fixture illustrating the case and ran custom builds against it before and after the change, confirming the mock was produced as expected after the fix.

I also added a generator test for this specific case.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • (N/A) I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Collaborator

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks mostly good. Can you just change the tests to follow the pattern here: https://github.com/vektra/mockery/tree/master/pkg/fixtures/type_alias

Basically:

  1. Create subpackage in fixtures directory
  2. Create interface
  3. Change .mockery.yaml to place mocks in that directory.
  4. Add tests in that directory.

This is the model I'm moving towards. If you can do that I'll merge. Thanks!

@volmedo
Copy link
Contributor Author

volmedo commented Dec 4, 2024

I moved the fixtures and mocks to a subpackage and added some tests there as per the instructions. Let me know if I missed something.

On a side note, having actual tests in a folder called "fixtures" feels a bit weird. I'd create a new "tests" folder and move subpackages with test code in the "fixtures" folder there. Just a nitpick, feel free to disregard 🙂.

Copy link
Collaborator

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! Yeah the naming is hard, there is a lot of historical cruft in this repo that I haven't been able to clean up. Maybe soon.

@LandonTClipp LandonTClipp merged commit 0ba6fad into vektra:master Dec 4, 2024
4 checks passed
@volmedo volmedo deleted the index-list-expr branch December 4, 2024 16:37
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

Successfully merging this pull request may close these issues.

Type declarations that are *ast.IndexListExpr are not accepted
2 participants