Skip to content
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

Fix generating into same package #135

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nkovacs
Copy link
Contributor

@nkovacs nkovacs commented Jul 12, 2019

This is a work in progress, but I wanted to get some feedback on it.

One question is how to allow generating into a "$GOPACKAGE_test" package in the same directory. I previously implemented this in my fork and simply added a package name argument, however, the problem with that is that when you're generating into a different directory, being able to explicitly specify the package name instead of counterfeiter deriving it from the directory name is not incredibly useful, and when generating into the same package, it has to be "$GOPACKAGE_test", so there's only one valid value you can specify for the argument. Alternatively, there could a boolean argument that makes it "$GOPACKAGE_test" if generating into the same directory, but that argument wouldn't be useful when generating into a different directory.

Also, I still need to understand what package mode is and how it should work in this case.

Fixes #103

@nkovacs
Copy link
Contributor Author

nkovacs commented Jul 12, 2019

Also, regarding tests, I don't fully understand how they work, do i have to add my new fixtures to roundtrip_test.go?scripts/ci.sh runs go generate on the fixtures and then checks if the generated files changed with git diff, so it will detect any breakage.

@joefitzgerald
Copy link
Collaborator

Also, regarding tests, I don't fully understand how they work, do i have to add my new fixtures to roundtrip_test.go? scripts/ci.sh runs go generate on the fixtures and then checks if the generated files changed with git diff, so it will detect any breakage.

roundtrip_test.go contains integration tests that can be used to evaluate the output for a given test case, or assert on the file contents. This mostly helps during development but can also be used to prevent regressions.

@joefitzgerald
Copy link
Collaborator

joefitzgerald commented Jul 14, 2019

One question is how to allow generating into a "$GOPACKAGE_test" package in the same directory. I previously implemented this in my fork and simply added a package name argument, however, the problem with that is that when you're generating into a different directory, being able to explicitly specify the package name instead of counterfeiter deriving it from the directory name is not incredibly useful, and when generating into the same package, it has to be "$GOPACKAGE_test", so there's only one valid value you can specify for the argument. Alternatively, there could a boolean argument that makes it "$GOPACKAGE_test" if generating into the same directory, but that argument wouldn't be useful when generating into a different directory.

I tend to agree that a boolean flag seems like the best solution for indicating that you want the fake to be generated into $GOPACKAGE_test.

@nkovacs nkovacs force-pushed the same-package-v2 branch 2 times, most recently from 2602de1 to 3f49db4 Compare July 19, 2019 18:31
@chrisdostert
Copy link

is this getting merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interface fakes generated in the same package as the interface cause an import cycle
3 participants