maxbrunsfeld/counterfeiter

Counterfeiter does not work when other tools are used in `go generate`

ironsmile opened this issue · 1 comments

It seems that counterfeiter fails to work when there are other go generate tools used in the same package as it. Take for example this simple file:

package main

//go:generate counterfeiter . Intf

type Intf interface {
    Foo()
}

//go:generate  stringer -type=Enum

type Enum int

const (
    First Enum = iota
    Second
)

func main() {

}

If you run go generate ./... in its directory you will get the following error:

$ go generate ./...
Writing `FakeIntf` to `cfbugfakes/fake_intf.go`... Done

No such file/directory/package [/home/iron4o/workspace/gopath/src/cfbug/stringer]: lstat /home/iron4o/workspace/gopath/src/cfbug/stringer: no such file or directory
main.go:3: running "counterfeiter": exit status 1

It seems that counterfeiter is reading the other go generate comments and confuses itself.

The latest version I found which do not have this bug is v6.0.2. So if you are experiencing this issue you can always use it.

The regexp is wrong: https://play.golang.org/p/suxp_exRu5G

The problem is that you can either have go:generate counterfeiter or counterfeiter:generate <empty>, but the regexp accepts go:generate <empty>, and assumes it's a counterfeiter:generate, with the stringer -type=Enum all being parameters to it.