Skip to content

Commit 009359f

Browse files
committed
gotooltest: move default GOPATH out of the main module
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/[email protected]/fruit: import path "mod/gopath/pkg/mod/[email protected]/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.
1 parent 3461ca1 commit 009359f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

cmd/testscript/testdata/env_var_with_go.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ unquote withproxy.txt
1212
# Baseline
1313
testscript -v noproxy.txt
1414
stdout ^BANANA=$
15-
stdout '^GOPATH=\$WORK[/\\]gopath'$
15+
stdout '^GOPATH=\$WORK[/\\]\.gopath'$
1616
[!go1.13] stdout ^GOPROXY=$
1717
[go1.13] stdout ^GOPROXY=https://proxy.golang.org,direct$
1818
! stderr .+
@@ -25,15 +25,15 @@ env GOPROXY=
2525
# no GOPROXY, no pass-through, no proxy
2626
testscript -v noproxy.txt
2727
stdout ^BANANA=$
28-
stdout '^GOPATH=\$WORK[/\\]gopath'$
28+
stdout '^GOPATH=\$WORK[/\\]\.gopath'$
2929
[!go1.13] stdout ^GOPROXY=$
3030
[go1.13] stdout ^GOPROXY=https://proxy.golang.org,direct$
3131
! stderr .+
3232

3333
# no GOPROXY, no pass-through, with proxy
3434
testscript -v withproxy.txt
3535
stdout ^BANANA=$
36-
stdout '^GOPATH=\$WORK[/\\]gopath'$
36+
stdout '^GOPATH=\$WORK[/\\]\.gopath'$
3737
stdout ^GOPROXY=http://.*/mod$
3838
! stderr .+
3939

@@ -56,14 +56,14 @@ setfilegoproxy $WORK/proxy
5656
# with GOPROXY, no pass-through, no proxy
5757
testscript -v noproxy.txt
5858
stdout ^BANANA=$
59-
stdout '^GOPATH=\$WORK[/\\]gopath'$
59+
stdout '^GOPATH=\$WORK[/\\]\.gopath'$
6060
stdout ^GOPROXY=$GOPROXY$
6161
! stderr .+
6262

6363
# with GOPROXY, no pass-through, with proxy
6464
testscript -v withproxy.txt
6565
stdout ^BANANA=$
66-
stdout '^GOPATH=\$WORK[/\\]gopath'$
66+
stdout '^GOPATH=\$WORK[/\\]\.gopath'$
6767
stdout ^GOPROXY=http://.*/mod$
6868
! stderr .+
6969

goproxytest/testdata/list.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ stdout 'v1.0.0 v1.1.0'
77
88
99

10+
# On Go 1.18 and later, this will error out if GOPATH is ${WORK}/gopath,
11+
# as that places GOMODCACHE inside the Go module and "mod tidy" walks it.
12+
# "mod tidy" then complains about invalid import paths such as
13+
# "mod/gopath/pkg/mod/[email protected]/fruit".
14+
# It's for that reason that we moved the default GOPATH to ${WORK}/.gopath.
15+
go mod tidy
16+
1017
-- go.mod --
1118
module mod
1219

gotooltest/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func goEnviron(env0 []string) []string {
110110
env := environ(env0)
111111
workdir := env.get("WORK")
112112
return append(env, []string{
113-
"GOPATH=" + filepath.Join(workdir, "gopath"),
113+
"GOPATH=" + filepath.Join(workdir, ".gopath"),
114114
"CCACHE_DISABLE=1", // ccache breaks with non-existent HOME
115115
"GOARCH=" + runtime.GOARCH,
116116
"GOOS=" + runtime.GOOS,

0 commit comments

Comments
 (0)