uber-go / mock

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

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

Open a-canya opened 5 months ago

a-canya commented 5 months ago

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

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