golang / mock

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

Methods containing type literals can't be mocked in source mode #8

Closed peterstace closed 8 years ago

peterstace commented 8 years ago

If an interface has a method containing a literal struct type, then mockgen isn't able to generate a mock when using source mode.

E.g. interfaces.go:

type Foo interface {
    Baz(struct{})
}

type Bar interface {
    Baz() struct{}
}

$ mockgen -source=interfaces.go gives the following error: 2015/08/18 15:02:43 Loading input failed: interfaces.go:6:5: failed parsing arguments: don't know how to parse type *ast.StructType.

The mocks can be generated successfully when using mockgen in reflect mode.

dsymonds commented 8 years ago

Yeah, it's in general very hard to handle that. We could treat struct{} as a special case, like we do for interface{}.

dsymonds commented 8 years ago

FYI, you should switch to reflect mode. It's way more reliable.

peterstace commented 8 years ago

Thanks @dsymonds !