golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.09k stars 17.68k forks source link

x/tools/go/expect: test fails when run from the module cache #40309

Open bcmills opened 4 years ago

bcmills commented 4 years ago

The test for golang.org/x/tools/go/expect fails when run from another module.

A go.mod file was added to the package's testdata directory in CL 216838. However, that cuts off the testdata directory from the rest of the module: there is no special handling for go.mod files in testdata directories (see #27852). The missing testdata directory causes the test to fail when it is run from anywhere other than a clone of the tools repository — notably, including when it is run from the module cache, including as a dependency of any other module.

$ go version
go version devel +0951939f Fri Jul 17 19:09:40 2020 +0000 linux/amd64

$ go test golang.org/x/tools/go/expect
--- FAIL: TestMarker (0.00s)
    --- FAIL: TestMarker/testdata/test.go (0.00s)
        expect_test.go:57: open testdata/test.go: no such file or directory
    --- FAIL: TestMarker/testdata/go.mod (0.00s)
        expect_test.go:57: open testdata/go.mod: no such file or directory
FAIL
FAIL    golang.org/x/tools/go/expect    0.012s
FAIL

-- go.mod --
module example.com

go 1.15

require golang.org/x/tools v0.0.0-20200720150256-cf97b7f4a4c1 // indirect

CC @stamblerre @ridersofrohan @ianthehat

stamblerre commented 4 years ago

Probably the correct fix for this and for #40310 will be to have go.mod.in files in the testdata directories, and then just write them out to the temporary directories during the actual tests.