gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
574 stars 38 forks source link

Interface from same package name as dependency broken since v3.2.1 #87

Open jeanschmitt opened 5 months ago

jeanschmitt commented 5 months ago

Hello,

Since v3.2.1, minimock generates import groups that don't compile, for interfaces importing types from other packages with the same name as the interface's package.

Steps to reproduce

Consider this directory structure:

├── pb
│   └── interface.go
├── dependency
│   └── pb
│       └── dep.go
└── gen.go

With the following contents:

// dependency/pb/dep.go
package pb

type Item struct {
    A string
}
// pb/interface.go
package pb

import (
    "mymodule/dependency/pb"
)

type Interface interface {
    A() pb.Item
}
// gen.go
package mymodule

//go:generate minimock -i ./pb.Interface -g

Generated import group in v3.2.0

import (
    "mymodule/dependency/pb"
    mm_atomic "sync/atomic"
    mm_time "time"

    "github.com/gojuno/minimock/v3"
)

Generated import group in v3.2.1

import (
    "mymodule/pb"

    "mymodule/dependency/pb"
    mm_atomic "sync/atomic"
    mm_time "time"

    "github.com/gojuno/minimock/v3"
)

Which raises the error 'pb' redeclared as the imported package name

zcolleen commented 1 month ago

Hey @jeanschmitt thanks for issue! I started another issue in gowrap https://github.com/hexdigest/gowrap/issues/87 as this bug is connected with gowrap update.