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

cmd/go: should packages with paths that contain "/testdata/" be importable? #60296

Open
adg opened this issue May 19, 2023 · 3 comments
Open
Labels
Documentation GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@adg
Copy link
Contributor

adg commented May 19, 2023

The cmd/go docs explicitly say:

Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata".

so it was very surprising to me to find that package golang.org/x/crypto/ssh has an import of package golang.org/x/crypto/ssh/testdata, and that this passes tests!

~/src/crypto/ssh $ go list -f '{{range .TestImports}}{{printf "%s\n" .}}{{end}}' | grep testdata
golang.org/x/crypto/ssh/testdata
~/src/crypto/ssh $ go list -json ./testdata
{
	"Dir": "/Users/adg/src/crypto/ssh/testdata",
	"ImportPath": "golang.org/x/crypto/ssh/testdata",
	"Name": "testdata",
	"Doc": "This package contains test data shared between the various subpackages of the golang.org/x/crypto/ssh package.",
	"Root": "/Users/adg/src/crypto",
	"Module": {
		"Path": "golang.org/x/crypto",
		"Main": true,
		"Dir": "/Users/adg/src/crypto",
		"GoMod": "/Users/adg/src/crypto/go.mod",
		"GoVersion": "1.17"
	},
	"Match": [
		"./testdata"
	],
	"GoFiles": [
		"doc.go",
		"keys.go"
	]
}

What's going on here? Did this sneak in by mistake? If so, we're stuck with it I suppose. Should the cmd/go docs be updated? What should the official rule be?

@ianlancetaylor ianlancetaylor added the GoCommand cmd/go label May 19, 2023
@ianlancetaylor
Copy link
Contributor

CC @bcmills @matloob

@seankhliao
Copy link
Member

My understanding was that like with #34992 and #43985 , go will ignore it in local listings, but it can still be part of import path.

@bcmills
Copy link
Contributor

bcmills commented May 19, 2023

Yes: testdata packages should be excluded from patterns like ./..., but should be importable. (They have syntactically valid import paths, and it's convenient to, say, put a command in testdata/cmd/foo and be able to go build that command to use it in a test.)

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Documentation labels May 19, 2023
@bcmills bcmills added this to the Backlog milestone May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants