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

     1  # Test GOMODCACHE
     2  env GO111MODULE=on
     3  
     4  # Explicitly set GOMODCACHE
     5  env GOMODCACHE=$WORK/modcache
     6  go env GOMODCACHE
     7  stdout $WORK[/\\]modcache
     8  go get rsc.io/quote@v1.0.0
     9  exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
    10  grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
    11  
    12  # Ensure GOMODCACHE doesn't affect location of sumdb, but $GOMODCACHE/cache/download/sumdb is still written
    13  exists $GOPATH/pkg/sumdb
    14  ! exists $WORK/modcache/sumdb
    15  exists $WORK/modcache/cache/download/sumdb
    16  
    17  # Test that the default GOMODCACHE is $GOPATH[0]/pkg/mod
    18  env GOMODCACHE=
    19  go env GOMODCACHE
    20  stdout $GOPATH[/\\]pkg[/\\]mod
    21  go get rsc.io/quote@v1.0.0
    22  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info
    23  grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info
    24  
    25  # If neither GOMODCACHE or GOPATH are set, GOPATH defaults to the user's $HOME/go, so GOMODCACHE becomes $HOME/go/pkg/mod
    26  [GOOS:windows] env USERPROFILE=$WORK/home # Ensure USERPROFILE is a valid path (rather than /no-home/ so we don't run into the logic that "uninfers" GOPATH in cmd/go/main.go
    27  [GOOS:plan9] env home=$WORK/home
    28  [!GOOS:windows] [!GOOS:plan9] env HOME=$WORK/home
    29  env GOMODCACHE=
    30  env GOPATH=
    31  go env GOMODCACHE
    32  stdout $HOME[/\\]go[/\\]pkg[/\\]mod
    33  
    34  # If GOMODCACHE isn't set and GOPATH starts with the path list separator,
    35  # GOMODCACHE is empty and any command that needs it errors out.
    36  env GOMODCACHE=
    37  env GOPATH=${:}$WORK/this/is/ignored
    38  
    39  go env GOMODCACHE
    40  stdout '^$'
    41  ! stdout .
    42  ! stderr .
    43  
    44  ! go mod download rsc.io/quote@v1.0.0
    45  stderr '^go: module cache not found: neither GOMODCACHE nor GOPATH is set$'
    46  
    47  # If GOMODCACHE isn't set and GOPATH has multiple elements only the first is used.
    48  env GOMODCACHE=
    49  env GOPATH=$WORK/first/path${:}$WORK/this/is/ignored
    50  go env GOMODCACHE
    51  stdout $WORK[/\\]first[/\\]path[/\\]pkg[/\\]mod
    52  
    53  env GOMODCACHE=$WORK/modcache
    54  go mod download rsc.io/quote@v1.0.0
    55  exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
    56  
    57  # Test error when cannot create GOMODCACHE directory
    58  env GOMODCACHE=$WORK/modcachefile
    59  ! go install example.com/cmd/a@v1.0.0
    60  stderr 'go: could not create module cache'
    61  
    62  # Test that the following work even with GO111MODULE=off
    63  env GO111MODULE=off
    64  
    65  # Cleaning modcache
    66  exists $WORK/modcache
    67  env GOMODCACHE=$WORK/modcache
    68  go clean -modcache
    69  ! exists $WORK/modcache
    70  
    71  -- go.mod --
    72  module m
    73  
    74  -- $WORK/modcachefile --
    75  

View as plain text