golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

feat: support embedded generic interfaces #669

Closed tra4less closed 6 months ago

tra4less commented 1 year ago

fixes #668 #658 #700

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

codyoss commented 1 year ago

@n0trace Thanks for the PR! Would you be willing to expand support for this test case as well:

type EmbeddingIface interface {
    TwentyOne[other.Three]
    other.Twenty[StructType]
    Foo() error
}

If you don't have the time I can review this as is and this could be done in another PR.

tra4less commented 1 year ago

@n0trace Thanks for the PR! Would you be willing to expand support for this test case as well:

type EmbeddingIface interface {
  TwentyOne[other.Three]
  other.Twenty[StructType]
  Foo() error
}

If you don't have the time I can review this as is and this could be done in another PR.

done @codyoss

codyoss commented 1 year ago

@n0trace Sorry if I was not clear, I meant just copy paste that code literally into generics.go. I don't think this solution covers the case where the outer interface does not contain type parameters, but the inner impl does.

tra4less commented 1 year ago

cases are complex than I have imagined, but done. please review. @codyoss

tra4less commented 1 year ago

fixes #658

codyoss commented 1 year ago

@n0trace I will take a look over the weekend, thank you!

alexandreLamarre commented 1 year ago

As a heads up I verified this also fixes the same issue we were seeing in #658

codyoss commented 1 year ago

Reviewing this today, sorry. Had gotten pulled away from this project for awhile!

codyoss commented 1 year ago

@n0trace I am still digging through the code, but would you mind adding some docs around the new types/fields/methods you added. I know parsing code is lacking this in general right now, but since this adds a bit of complexity it would be nice to have so details of what/how things are being used.

lennycampino commented 1 year ago

@n0trace @codyoss Is there any update on this? :)

hirikarate commented 1 year ago

I'm having the same issue and I'm hoping this fix could make it to official as soon as possible. Thank you all for the great work.

chkp-omris commented 1 year ago

I'm also having the same issue, could you please review this?

tofluid commented 1 year ago

This is needed, please review. Thanks!

tra4less commented 1 year ago

@codyoss we need a resolution for mock generics. please review.

paprikati commented 1 year ago

We are also blocked on this - would love if we could use this ❤️

AyushG3112 commented 1 year ago

@n0trace @codyoss any update on this please?

samvdb commented 1 year ago

Thanks for the pull request. Support for generics would be most welcome! Any update?

samvdb commented 1 year ago

I tested this PR with go version go1.20.1 linux/amd64 and can confirm generics are working.

tofluid commented 1 year ago

@codyoss or anyone else that can approve this PR. My team is really getting hamstrung and we're now starting to consider a different mocking library for go but then that'll be two testing standards which I do not want.

Please get this approved!

colinschoen commented 1 year ago

@codyoss Can you please have a look at this

tedkornish commented 1 year ago

Also eagerly awaiting this.

maestre3d commented 1 year ago

Just looked at Cody's LinkedIn profile. Looks like he got promoted and is no longer part of Google's Golang Developer Relations team.

I think we should ping another person to get this PR merged.

ShiningRush commented 1 year ago

@n0trace hi, I get a error when mock the interface which embedded a another package's pointer and generic types (mockgen is build from your branch): Loading input failed: unable to parse interface type parameters: Repo

test demo like below:

package a

type ChildRepo interface {
    b.Repo[*b.SomeStruct]
}
package b

type Repo[T any] interface {
}

type SomeStruct struct {
}

It will be ok when I use struct to instead of pointer

type ChildRepo interface {
    b.Repo[b.SomeStruct]
}
tra4less commented 1 year ago

@ShiningRush fixed it

@codyoss I've refactored my implementation, and now it's easy to understand and maintain. I'd appreciate it if you could take some time to review it