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

     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
    10  mkdir $GOTMPDIR
    11  go build -x hello.go
    12  stderr ^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.
    17  rm $GOTMPDIR
    18  cp hello.go $GOTMPDIR # any file will do
    19  
    20  # 'go build' should fail if GOTMPDIR is read-only.
    21  ! go build -x .
    22  stderr '^go: creating work dir: \w+ '$GOTMPDIR
    23  
    24  # 'go list' should only fail if it needs to build something.
    25  go list -x .
    26  ! stderr 'creating work dir'
    27  stdout m
    28  go list -m all
    29  stdout m
    30  ! go list -x -export .
    31  stderr '^go: creating work dir: \w+ '$GOTMPDIR
    32  
    33  # 'go clean -cache' and 'go clean -modcache' should not fail.
    34  go clean -x -cache
    35  ! stderr 'creating work dir'
    36  go 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
    43  stderr '^go: creating work dir: \w+ '$GOTMPDIR
    44  go env GOROOT
    45  
    46  -- go.mod --
    47  module m
    48  
    49  go 1.15
    50  -- hello.go --
    51  package main
    52  func main() { println("hello") }
    53  

View as plain text