golang / mock

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

Does not work without -self_package outside of GOPATH #310

Closed powerman closed 4 years ago

powerman commented 5 years ago

Both source and reflect mode fail in different cases outside of GOPATH. One case is type aliases (already mentioned in #144 and #244), another is using type defined in same package. Inside GOPATH all cases works (both with and without -self_package). Outside GOPATH all cases works only with -self_package. Here is test case and matrix of working/broken cases when used outside GOPATH without -self_package:

type Ctx = context.Context
type Nothing struct{}
type nothing struct{}
type App interface {
    // Noop(Ctx)             // source: doesn't work, reflect: works
    // Noop(context.Context) // source: works,        reflect: works
    // Noop(Nothing)         // source: doesn't work, reflect: doesn't work
    // Noop(nothing)         // source: works,        reflect: doesn't work
}

Full example available in https://github.com/powerman/bug-gomock

Maybe it makes sense to set default value for -self_package as a workaround to make it work everywhere out of box?

codyoss commented 4 years ago

@powerman is this that modules might have solved?

powerman commented 4 years ago

Nope, nothing changed, issue still actual in current master.

kirk91 commented 4 years ago

I also have the same problem, and use -self_package parameter to solve temporarily.

codyoss commented 4 years ago

Thanks, I will look more into this.

codyoss commented 4 years ago

Sorry I slipped on following up on this. I will check it out soon.

codyoss commented 4 years ago

So there are four test cases here. Here are my thoughts on each. Example commands run. Each run with the file contents you provided. Also, the folder is a module example.com/gm310. Also also, I have gomock built off master which does have some more fixes in it around self_package:

  1. To me source works and reflect does not. Alias should not be followed as that is the point of an alias, hide the fact that an identifier has really moved. I want to keep this out of scope for this issue as it will be solved in #244. 2.Yup, both work.
  2. Both work.
  3. Both work.

Closing this issue as the only real problem here is the alias stuff, which is being handled as another issue. Thanks.

powerman commented 4 years ago

@codyoss I'm not sure I get it. I've reported issue when running without -self_package. You've tested with -self_package and closed the issue. What's the point? Is it means running without -self_package is not supported/recommended outside of GOPATH? Why don't set default value for -self_package?

codyoss commented 4 years ago

Sorry you are right, I did get a little mixed up here. I still do think the only real issue is the first case though. I also agree it would be great if self_package was not needed, but right now it is. That is why it does exist. I do have plans in the future to obsolete this flag, but for now it is around for a reason.