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

Generating mocks on a file with a dot import creates a compilation error #138

Open
a-canya opened this issue Jan 11, 2024 · 0 comments
Open
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@a-canya
Copy link

a-canya commented Jan 11, 2024

Actual behavior When generatinga mock from a source file which contains a dot import, the dot import is copied in the destination file. If the dot import is not actually used, the compiler then fails.

Expected behavior Generated code always compiles, even if someone decides to add a dot import in their code.

To Reproduce I created an example of the issue here.

  1. Have mockgen installed.
  2. Clone this repo or copy the following code into a main.go file:
    import . "fmt"
    
    //go:generate mockgen -source=main.go -destination=mocks/main.go
    type I interface{}
    
    func main() {
        /* fmt. */ Println("Hello world!")
    }
  3. Run go generate ./...
  4. Run go build ./... - the compilation fails with error: mocks/main.go:13:2: "fmt" imported and not used.

Additional Information

  • gomock mode (reflect or source): source (I haven't tried withe reflect, issue might also happen)
  • gomock version or git ref: v0.4.0
  • golang version: 1.21.4

Triage Notes for the Maintainers

Workaround

The easy and sane workaround that I will apply is just to not have dot imports. I thought it was still useful to report the bug though...

@sywhang sywhang added bug Something isn't working documentation Improvements or additions to documentation labels Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants