1 # Test GOMODCACHE
2 env GO111MODULE=on
3
4 # Explicitly set GOMODCACHE
5 env GOMODCACHE=$WORK/modcache
6 go env GOMODCACHE
7 stdout $WORK[/\\]modcache
8 go get -d rsc.io/quote@v1.0.0
9 exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
10 grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
11
12 # Ensure GOMODCACHE doesn't affect location of sumdb, but $GOMODCACHE/cache/download/sumdb is still written
13 exists $GOPATH/pkg/sumdb
14 ! exists $WORK/modcache/sumdb
15 exists $WORK/modcache/cache/download/sumdb
16
17 # Test that the default GOMODCACHE is $GOPATH[0]/pkg/mod
18 env GOMODCACHE=
19 go env GOMODCACHE
20 stdout $GOPATH[/\\]pkg[/\\]mod
21 go get -d rsc.io/quote@v1.0.0
22 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info
23 grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info
24
25 # If neither GOMODCACHE or GOPATH are set, GOPATH defaults to the user's $HOME/go, so GOMODCACHE becomes $HOME/go/pkg/mod
26 [windows] env USERPROFILE=$WORK/home # Ensure USERPROFILE is a valid path (rather than /no-home/ so we don't run into the logic that "uninfers" GOPATH in cmd/go/main.go
27 [plan9] env home=$WORK/home
28 [!windows] [!plan9] env HOME=$WORK/home
29 env GOMODCACHE=
30 env GOPATH=
31 go env GOMODCACHE
32 stdout $HOME[/\\]go[/\\]pkg[/\\]mod
33
34 # If GOMODCACHE isn't set and GOPATH starts with the path list separator, it's an error.
35 env GOMODCACHE=
36 env GOPATH=${:}$WORK/this/is/ignored
37 ! go env GOMODCACHE
38 stderr 'missing \$GOPATH'
39
40 # If GOMODCACHE isn't set and GOPATH has multiple elements only the first is used.
41 env GOMODCACHE=
42 env GOPATH=$WORK/first/path${:}$WORK/this/is/ignored
43 go env GOMODCACHE
44 stdout $WORK[/\\]first[/\\]path[/\\]pkg[/\\]mod
45
46 env GOMODCACHE=$WORK/modcache
47 go mod download rsc.io/quote@v1.0.0
48 exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
49
50 # Test error when cannot create GOMODCACHE directory
51 env GOMODCACHE=$WORK/modcachefile
52 ! go install example.com/cmd/a@v1.0.0
53 stderr 'go: could not create module cache'
54
55 # Test that the following work even with GO111MODULE=off
56 env GO111MODULE=off
57
58 # Cleaning modcache
59 exists $WORK/modcache
60 env GOMODCACHE=$WORK/modcache
61 go clean -modcache
62 ! exists $WORK/modcache
63
64 -- go.mod --
65 module m
66
67 -- $WORK/modcachefile --
68
View as plain text