added ignoring interfaces via -exclude_interfaces flag (#68)#72
added ignoring interfaces via -exclude_interfaces flag (#68)#72r-hang merged 3 commits intouber-go:mainfrom
Conversation
|
Thanks for contribution @tulzke, i'm happy to discuss here or in the ticket but I think the the exclusion list as a mockgen flag parameter is the best approach as (1) command line flags are current mechanism by which mock options are configured and (2) users won't be required to modify their source code to take advantage of the feature. |
|
@r-hang , thanks for reply. Yes, I can do this via the flag parameter. |
01264d0 to
78bb101
Compare
|
@tulzke how about |
|
@r-hang, sounds good. I have already committed this. |
|
@tulzke the core logic looks could to me. However, could we add some tests for the newly added parseExcludeInterfaces function? |
…plementation of the function
|
@r-hang good point. I added a unit test for the function, and then changed the implementation to satisfy the test cases. |
This is a proposal PR to generate mocks without error for following
cases:
```go
type Water[R any, C UnsignedInteger] interface {
Fish(R) []C
}
type UnsignedInteger interface {
~uint | ~uint32 | ~uint64
}
```
Go `types` package seems to wrap interfaces that contain type
constraints by checking a type set literal of the form `~T` and `A|B`.
https://github.com/golang/go/blob/master/src/go/types/decl.go#L668
So gomock can just ignore that pattern to generate mocks safely without
`don't know how to mock method of type` errors. I think this can be a
better solution for custom type constraints than [`-exclude`
flag](#72).
---------
Co-authored-by: Jacob Oaks <jacoboaks.8@gmail.com>
I forgot to do this when I created the last PR #72
The problem is described in the issue. This is one of the solutions to this problem.