Skip to content

Commit

Permalink
gotooltest: move default GOPATH out of the main module
Browse files Browse the repository at this point in the history
Otherwise, commands like `go mod tidy` will try to walk into the default
GOPATH directory. At best, that's a waste of resources, since
directories like GOMODPATH may contain lots of files. At worst, it
results in errors, as directories in GOMODPATH are not valid import paths:

	--- FAIL: TestScripts/list (0.01s)
		testscript.go:413:
			[...]
			> go mod tidy
			[stderr]
			mod/gopath/pkg/mod/fruit.com@v1.1.0/fruit: import path "mod/gopath/pkg/mod/fruit.com@v1.1.0/fruit" should not have @Version

We add the test in goproxytest, as goproxytest already uses gotooltest,
and we need an external module to reproduce the error.
  • Loading branch information
mvdan committed Apr 22, 2022
1 parent 3461ca1 commit 8a06f37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions goproxytest/testdata/list.txt
Expand Up @@ -7,6 +7,13 @@ stdout 'v1.0.0 v1.1.0'
go get -d fruit.com@v1.0.0
go get -d fruit.com@v1.1.0

# On Go 1.18 and later, this will error out if GOPATH is ${WORK}/gopath,
# as that places GOMODCACHE inside the Go module and "mod tidy" walks it.
# "mod tidy" then complains about invalid import paths such as
# "mod/gopath/pkg/mod/fruit.com@v1.1.0/fruit".
# It's for that reason that we moved the default GOPATH to ${WORK}/.gopath.
go mod tidy

-- go.mod --
module mod

2 changes: 1 addition & 1 deletion gotooltest/setup.go
Expand Up @@ -110,7 +110,7 @@ func goEnviron(env0 []string) []string {
env := environ(env0)
workdir := env.get("WORK")
return append(env, []string{
"GOPATH=" + filepath.Join(workdir, "gopath"),
"GOPATH=" + filepath.Join(workdir, ".gopath"),
"CCACHE_DISABLE=1", // ccache breaks with non-existent HOME
"GOARCH=" + runtime.GOARCH,
"GOOS=" + runtime.GOOS,
Expand Down

0 comments on commit 8a06f37

Please sign in to comment.