1 # Set GOCACHE to a clean directory to ensure that 'go build' has work to report.
2 [!GOOS:windows] env GOCACHE=$WORK/gocache
3 [GOOS:windows] env GOCACHE=$WORK\gocache
4
5 # 'go build' should use GOTMPDIR if set.
6 [!GOOS:windows] env GOTMPDIR=$WORK/my-favorite-tmpdir
7 [GOOS:windows] env GOTMPDIR=$WORK\my-favorite-tmpdir
8 mkdir $GOTMPDIR
9 go build -x hello.go
10 stderr ^WORK=.*my-favorite-tmpdir
11
12 # Make GOTMPDIR a regular file. This prevents the creation of work directories,
13 # so we can check that certain commands don't create them.
14 # This simulates running on a full disk or a read-only volume.
15 rm $GOTMPDIR
16 cp hello.go $GOTMPDIR # any file will do
17
18 # 'go build' should fail if GOTMPDIR is read-only.
19 ! go build -x .
20 stderr '^go: creating work dir: \w+ '$GOTMPDIR
21
22 # 'go list' should only fail if it needs to build something.
23 go list -x .
24 ! stderr 'creating work dir'
25 stdout m
26 go list -compiled -x -f '{{.CompiledGoFiles}}' .
27 ! stderr 'creating work dir'
28 stdout '\[hello.go\]'
29 go list -m all
30 stdout m
31 ! go list -x -export .
32 stderr '^go: creating work dir: \w+ '$GOTMPDIR
33
34 # 'go clean -cache' and 'go clean -modcache' should not fail.
35 go clean -x -cache
36 ! stderr 'creating work dir'
37 go clean -x -modcache
38 ! stderr 'creating work dir'
39
40 # 'go env' should not fail for specific variables.
41 # Without arguments, it needs to initialize a builder to load cgo flags, and
42 # that uses a temporary directory.
43 ! go env
44 stderr '^go: creating work dir: \w+ '$GOTMPDIR
45 go env GOROOT
46
47 -- go.mod --
48 module m
49
50 go 1.15
51 -- hello.go --
52 package main
53 func main() { println("hello") }
54
View as plain text