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
cmd/go: poor error message when non-test Go file is in a xx_test package other than the directory name #24895
Comments
Can you please create a git repo somewhere with broken and non broken versions of the packages as a reproduction. Thanks |
@davecheney https://github.com/stevenroose/testing Non-broken is by renaming |
A file in a xx_test package should always be named yy_test.go. The go tool decides which files are in a test based on the name of the file, not on the package clause. Since you had a non test file, the go tool expected it to have a package clause that matched the directory name. But I agree that the error message could perhaps be clearer. |
Wait, non-test files don't need to have a package that matches the directory, right? I do understand that in this case, as |
I've just got bitten by this. The behaviour is counterintuitive and the error message is misleading. |
me too, I might can have a look at my weekend |
What version of Go are you using?
Does this issue reproduce with the latest release?
I guess this is the latest release.
What operating system and processor architecture are you using?
What did you do?
Using the ginkgo cli tool, I created a test suite bootstrap. The folder name is
testsuite
, so the tool defaulted to a package nametestsuite_test
.I changed the package name in all files to
cbsproxy_test
, the package I'm testing, which is itself located in a different subdirectory on the same level astestsuite
.I ran both
go build
andgo test
.What did you expect to see?
go build
to succeed normally andgo test
to produce test results for 0 tests.What did you see instead?
(newlines mine)
Just to proof that all packages are named
cbsproxy_test
:What solved the issue?
Renaming
common.go
tocommon_test.go
resolved the issue. The error message was however not clear. As should it be possible to have both normal Go files and_test
Go files with the same package name (as with any normal package that does not end in_test
).The text was updated successfully, but these errors were encountered: