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

     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 -m all
    27  stdout m
    28  ! go list -x -export .
    29  stderr '^go: creating work dir: \w+ '$GOTMPDIR
    30  
    31  # 'go clean -cache' and 'go clean -modcache' should not fail.
    32  go clean -x -cache
    33  ! stderr 'creating work dir'
    34  go 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
    41  stderr '^go: creating work dir: \w+ '$GOTMPDIR
    42  go env GOROOT
    43  
    44  -- go.mod --
    45  module m
    46  
    47  go 1.15
    48  -- hello.go --
    49  package main
    50  func main() { println("hello") }
    51  

View as plain text