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: a package that ends with _test
cannot have an internal test package
#45477
Comments
I agree that this is a bug. However, it seems like a low priority to fix, since basically nobody should have a package named (But I do like to test these sorts of edge-cases just for completeness — and thanks for documenting this one!) |
It may be relevant here that it's possible to have a "test-only" package: one that has tests but no code. In that case, the package name can only inferred from package tests. Consider:
In this case, tests work and the package name is considered to be "pkg":
If a_test.go is modified as follows: -package pkg
+package pkg_test That could be interpreted to mean "make the package name
It's an example demonstrating a rare edge-case where it's not possible to specify a package name and whether the test is internal or external without ambiguity as long as normal package names with a "_test" suffix are allowed to exist. (This might be quite irrelevant since the whether a test file is internal or external isn't very meaningful for a package that has only tests but no code.) |
@dmitshur, that's another neat edge-case! I agree that it probably doesn't make much difference which direction we bias in that case, since AFAICT nothing else can import the test-only package. (Or, we could perhaps make some sort of heuristic decision about the likely package name based on the import path.) |
another neat edge-case 😺:
It's result is :
|
@bcmills I have tried to understand the thread. Tried to reproduce in my local based on the steps outlined by yunnian. Can I take this up? |
@bcmills any followup on the above comment? |
…package Fixes golang#45477 Change-Id: I2f1ed281515ec40d31fd07ce9f4901777691bfa7
Change https://golang.org/cl/365534 mentions this issue: |
…package Fixes golang#45477 Change-Id: I2f1ed281515ec40d31fd07ce9f4901777691bfa7
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Prepare this test script in
cmd/go/testdata/script
and run this:What did you expect to see?
No compile error
What did you see instead?
This compile error:
The text was updated successfully, but these errors were encountered: