-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
counterfeiter does not work via go generate if outside PATH #166
Comments
The expansion of environments happens via go's I would recommend using the approach described in the This will result in addition of a
Using this approach, you won't need counterfeiter in your path or a tools path, and instead can use go.mod to control the version of counterfeiter you and the other members of your team use. |
@joefitzgerald This is definitely a bug with counterfeiter itself. I can tell from the debug output of go generate that it is properly executing the command with expansion. But then counterfeiter does nothing. Based upon the recent release notes, my suspicion is that the fix for #137 (or something similar to it) is responsible. Why is counterfeiter even parsing go:generate directives? That makes no sense. |
@rittneje have you tried to use the approach described in the README? This will solve your issues.
I will write a test that replicates your issue and look into a fix, as you are correct that the generate parsing logic should be able to handle this scenario. |
We have installed counterfeiter as a pre-built binary inside a docker container. I don't want to have to save the source code in the image or download it on the fly, so using |
Are you using a |
Also, could you please post the error output (if any) in the case of the failed invocation? |
No, we are not using that flag. We have the following forms:
On occasion, we also use the There is no output at all from the failed invocation. |
If you are not using the
|
I'm running into this issue as well. If I have:
everything works, if I have:
it exits successfully but generates nothing. EDIT: And yes, with a non existent file I get:
|
@joefitzgerald From tracing through the code, the bug was indeed caused by the changes in #137. First, main calls
Because of the regex changes in #137,
Consequently, Now, in terms of fixing this bug, I think counterfeiter should be amended not to have any of this fancy optimization logic under go generate. This is because you are actually violating how go generate is supposed to work. For example, I can pass a specific file path to go generate, and only directives in that file will be executed. Or I can pass a regex via -run, and only matching directives will be executed. But it seems in both cases counterfeiter will go behind my back and attempt to regenerate the entire package. If someone does want to generate all the package fakes at once, they should exclusively use counterfeiter:generate directives, and then invoke counterfeiter itself with some flag that indicates they want that behavior (instead of the classic "one interface at a time" behavior). In short:
I would like to point out that if someone is using the "classic" go:generate directives, I don't think your optimization accomplishes anything, because if there are N directives in the package, counterfeiter is going to be invoked N times by go generate. In fact, it probably makes it worse, since you will actually generate all N fakes N times, for a total of N^2 generations. |
We do not have counterfeiter under our
PATH
env var. Instead, the location is determined by aGOTOOLSPATH
env var. Until recently, the followinggo:generate
directive worked fine://go:generate ${GOTOOLSPATH}/bin/counterfeiter ...
However, with v6.2.3, this line no longer works. It seems counterfeiter is a complete no-op and doesn't return any errors. If I add it to
PATH
explicitly, then the following works as expected.//go:generate counterfeiter ...
The text was updated successfully, but these errors were encountered: