mock icon indicating copy to clipboard operation
mock copied to clipboard

feat: support embedded generic interfaces

Open tra4less opened this issue 3 years ago • 12 comments

fixes #668

tra4less avatar Aug 08 '22 07:08 tra4less

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.

google-cla[bot] avatar Aug 08 '22 07:08 google-cla[bot]

@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.

codyoss avatar Aug 11 '22 20:08 codyoss

@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

tra4less avatar Aug 12 '22 03:08 tra4less

@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.

codyoss avatar Aug 12 '22 15:08 codyoss

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

tra4less avatar Aug 15 '22 07:08 tra4less

fixes #658

tra4less avatar Aug 16 '22 11:08 tra4less

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

codyoss avatar Aug 19 '22 16:08 codyoss

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

cc @codyoss

tra4less avatar Sep 02 '22 04:09 tra4less

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

alexandreLamarre avatar Sep 20 '22 23:09 alexandreLamarre

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

codyoss avatar Oct 07 '22 14:10 codyoss

@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.

codyoss avatar Oct 07 '22 15:10 codyoss

@codyoss added some comments.

tra4less avatar Oct 10 '22 06:10 tra4less

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

lennycampino avatar Dec 02 '22 16:12 lennycampino

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.

hirikarate avatar Dec 06 '22 17:12 hirikarate

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

chkp-omris avatar Dec 29 '22 11:12 chkp-omris

This is needed, please review. Thanks!

tofluid avatar Jan 10 '23 17:01 tofluid

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

tra4less avatar Jan 17 '23 03:01 tra4less

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

paprikati avatar Jan 17 '23 20:01 paprikati

@n0trace @codyoss any update on this please?

AyushG3112 avatar Feb 13 '23 05:02 AyushG3112

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

samvdb avatar Mar 09 '23 13:03 samvdb

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

samvdb avatar Mar 10 '23 08:03 samvdb

@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!

tofluid avatar Apr 07 '23 21:04 tofluid

@codyoss Can you please have a look at this

colinschoen avatar Apr 10 '23 05:04 colinschoen

Also eagerly awaiting this.

tedkornish avatar Apr 27 '23 04:04 tedkornish

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.

aruizeac avatar May 02 '23 06:05 aruizeac

@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]
}

ShiningRush avatar May 04 '23 13:05 ShiningRush

@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

tra4less avatar Jun 25 '23 05:06 tra4less