You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mockery will generate both mocks, as expected. Note that StringFooer's declaration is an *ast.IndexExpr, which is accepted when parsing as per this line in pkg/parse.go.
However, when there is more than one type parameter:
StringFooer's declaration is now an *ast.IndexListExpr, which is regarded as unacceptable, the interface is ignored and no mock is produced. I discovered the fact by running mockery with --log-level debug.
I tried the naive approach of adding *ast.IndexListExpr to the aforementioned case and produced a custom mockery binary that I then ran on the previous example and a working mock was generated.
I ran mockery e2e and unit tests after the change and all of them passed. I also used the mock generated previously in a (admittedly simple) test with successful results.
Is there a reason *ast.IndexListExpr is not accepted or was it just an overlook? I'm not super familiar with Go's ast package, so I may be missing something. I'd be more than happy to open a PR with the proposed change if it was just a mistake.
Thanks for the report. I think this is indeed an overlook. It's kind of annoying that the Go AST treats this differently but it should be a matter of adding it to the switch statement that controls this, as you probably did. If you could submit a PR that would be great!
Description
Let's consider the following code:
mockery
will generate both mocks, as expected. Note thatStringFooer
's declaration is an*ast.IndexExpr
, which is accepted when parsing as per this line inpkg/parse.go
.However, when there is more than one type parameter:
StringFooer
's declaration is now an*ast.IndexListExpr
, which is regarded as unacceptable, the interface is ignored and no mock is produced. I discovered the fact by running mockery with--log-level debug
.I tried the naive approach of adding
*ast.IndexListExpr
to the aforementioned case and produced a custommockery
binary that I then ran on the previous example and a working mock was generated.I ran mockery e2e and unit tests after the change and all of them passed. I also used the mock generated previously in a (admittedly simple) test with successful results.
Is there a reason
*ast.IndexListExpr
is not accepted or was it just an overlook? I'm not super familiar with Go'sast
package, so I may be missing something. I'd be more than happy to open a PR with the proposed change if it was just a mistake.Mockery Version
v2.49.1
Go Version
1.23.3
Installation Method
Steps to Reproduce
.mockery.yml
file:mockery
Expected Behavior
I'd expect to get mocks for both
Fooer
andStringFooer
.Actual Behavior
Only
Fooer
gets a mock created.The text was updated successfully, but these errors were encountered: