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?
The
cmd/godocs explicitly say: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?