Open benma opened 8 years ago
@benma the bigger issue is with mixing two packages (main
and main_test
) in the same directory. Even if the generated code was OK, once it is generated go generate
will fail from then on because it expects one package per folder.
$ ls
main.go
$ cat main.go
package main
type Foo struct{}
//go:generate goautomock -mock-name fooMock -mock-pkg main_test -o mock.auto_test.go fooInterface
type fooInterface interface {
Foo() Foo
}
func main() {}
$ go generate
Generating mock for fooInterface in mock.auto_test.go
$ go generate
/Users/ernesto/Projects/go/src/github.com/ernesto-jimenez/test/mock.auto_test.go:6:1: package main_test; expected main
main.go:5: running "goautomock": exit status 1
Do you want to look into the code to add support for folders with two packages?
Thanks for the quick response.
This is a _test
package, which should be in the same folder (black box testing). I am using the generated mock only in the unit tests, which is why I assumed I should generate it like that.
Maybe this is the bug then? The tool should allow the unit test package to be in the same folder, and correctly import the types from (main.Foo).
Yes, the bigger bug is allowing a _test
package alongside a package. Right now the tool expects just one package per folder.
I never use _test
packages myself, so never ran into the issue.
I confirm that it works if the generated file of a different package lives in another folder.
Do you plan on fixing the bug to enable _test
packages? I can try to take care of it if you don't have the time, but I figure it you would be faster because I don't know the code yet.
I'm travelling the next few weeks, so it will take some time for me to be able to review it.
If you want to give it a try, I will be happy to answer questions and review the PR :)
Thanks. I made a PR.
@ernesto-jimenez, what is the status of this?
Bump :)
Hi
Example input:
After running
go generate ./...
, this file is generated:In the generated file, the main package is imported, but the mock of Foo has an error:
func (m *fooMock) Foo() Foo
should befunc (m *fooMock) Foo() main.Foo
.