Skip to content

cmd/go: document that packages with paths that contain "/testdata/" are importable #60296

@adg

Description

@adg

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.GoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions