...

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

Documentation: cmd/go/testdata/script

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

View as plain text