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

fix: define imported package's local name by using flags #41

Merged
merged 16 commits into from
Aug 7, 2023

Conversation

ErfanMomeniii
Copy link
Contributor

fixes #646,
Hi, my friends.
Merging this pull request can fix old bugs related to defining the local names of imported packages by using the -imports flag.
I have also added a test for that, and it works properly.
If you have any ideas or concerns regarding the PR, feel free to tell me.

@OscarVanL
Copy link

OscarVanL commented Jul 19, 2023

I ran into this bug today for the first time (in the old gomock/mockgen package). It's frustrating the import names get broken in the generated mocks when using import aliases or dot imports and it would be great to see this fixed.

@CLAassistant
Copy link

CLAassistant commented Jul 23, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 5 committers have signed the CLA.

✅ ErfanMomeniii
✅ sywhang
❌ Erfan Momeni
❌ tra4less
❌ utgwkk


Erfan Momeni seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.


//go:generate mockgen -package defined_import_local_name -destination mock.go -source input.go -imports b_mock=bytes,c_mock=context

type WithDotImports interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add an additional package to test for stdlib and external imports?

Suggestion: Update the method names to reflect which scenario being tested.


//go:generate mockgen -package defined_import_local_name -destination mock.go -source input.go -imports b_mock=bytes,c_mock=context

type WithDotImports interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is DotImports referring to? In the spec I see three cases

Import declaration          Local name of Sin

import   "lib/math"         math.Sin
import m "lib/math"         m.Sin
import . "lib/math"         Sin

As a reviewer, the DotImport name makes me think this is that last case in the list, but this test seems to be testing named imports (case 2).

@ErfanMomeniii
Copy link
Contributor Author

ErfanMomeniii commented Aug 2, 2023

Dear @r-hang, you are correct. I have renamed it to withImports as these tests are not intended for testing the dot imports feature. Thank you.

mockgen/mockgen.go Outdated Show resolved Hide resolved
@sywhang sywhang merged commit 2417c65 into uber-go:main Aug 7, 2023
2 checks passed
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.

Does -imports work? Package alias is inconsistent, and -imports does not fix it.
7 participants