...

Text file src/cmd/go/testdata/script/build_GOTMPDIR.txt

Documentation: cmd/go/testdata/script

     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
     8mkdir $GOTMPDIR
     9go build -x hello.go
    10stderr ^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.
    15rm $GOTMPDIR
    16cp hello.go $GOTMPDIR # any file will do
    17
    18# 'go build' should fail if GOTMPDIR is read-only.
    19! go build -x .
    20stderr '^go: creating work dir: \w+ '$GOTMPDIR
    21
    22# 'go list' should only fail if it needs to build something.
    23go list -x .
    24! stderr 'creating work dir'
    25stdout m
    26go list -m all
    27stdout m
    28! go list -x -export .
    29stderr '^go: creating work dir: \w+ '$GOTMPDIR
    30
    31# 'go clean -cache' and 'go clean -modcache' should not fail.
    32go clean -x -cache
    33! stderr 'creating work dir'
    34go clean -x -modcache
    35! stderr 'creating work dir'
    36
    37# 'go env' should not fail for specific variables.
    38# Without arguments, it needs to initialize a builder to load cgo flags, and
    39# that uses a temporary directory.
    40! go env
    41stderr '^go: creating work dir: \w+ '$GOTMPDIR
    42go env GOROOT
    43
    44-- go.mod --
    45module m
    46
    47go 1.15
    48-- hello.go --
    49package main
    50func main() { println("hello") }

View as plain text