...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=off
     2
     3# go env should default to the right places
     4env AppData=$HOME/windowsappdata
     5env home=$HOME/plan9home
     6go env GOENV
     7[GOOS:aix] stdout $HOME/.config/go/env
     8[GOOS:darwin] stdout $HOME'/Library/Application Support/go/env'
     9[GOOS:freebsd] stdout $HOME/.config/go/env
    10[GOOS:linux] stdout $HOME/.config/go/env
    11[GOOS:netbsd] stdout $HOME/.config/go/env
    12[GOOS:openbsd] stdout $HOME/.config/go/env
    13[GOOS:plan9] stdout $HOME/plan9home/lib/go/env
    14[GOOS:windows] stdout $HOME\\windowsappdata\\go\\env
    15
    16# Now override it to something writable.
    17env GOENV=$WORK/envdir/go/env
    18go env GOENV
    19stdout envdir[\\/]go[\\/]env
    20
    21# go env shows all variables
    22go env
    23stdout GOARCH=
    24stdout GOOS=
    25stdout GOROOT=
    26
    27# go env ignores invalid flag in GOFLAGS environment variable
    28env GOFLAGS='=true'
    29go env
    30
    31# checking errors
    32! go env -w
    33stderr 'go: no KEY=VALUE arguments given'
    34! go env -u
    35stderr 'go: ''go env -u'' requires an argument'
    36
    37# go env -w changes default setting
    38env root=
    39[GOOS:windows] env root=c:
    40env GOPATH=
    41go env -w GOPATH=$root/non-exist/gopath
    42! stderr .+
    43grep GOPATH=$root/non-exist/gopath $WORK/envdir/go/env
    44go env GOPATH
    45stdout /non-exist/gopath
    46
    47# go env -w does not override OS environment, and warns about that
    48env GOPATH=$root/other
    49go env -w GOPATH=$root/non-exist/gopath2
    50stderr 'warning: go env -w GOPATH=... does not override conflicting OS environment variable'
    51go env GOPATH
    52stdout $root/other
    53
    54# but go env -w does do the update, and unsetting the env var exposes the change
    55env GOPATH=
    56go env GOPATH
    57stdout $root/non-exist/gopath2
    58
    59# unsetting with go env -u does not warn about OS environment overrides,
    60# nor does it warn about variables that haven't been set by go env -w.
    61env GOPATH=$root/other
    62go env -u GOPATH
    63! stderr .+
    64go env -u GOPATH
    65! stderr .+
    66
    67# go env -w rejects unknown or bad variables
    68! go env -w GOGC=off
    69stderr 'unknown go command variable GOGC'
    70! go env -w GOEXE=.bat
    71stderr 'GOEXE cannot be modified'
    72! go env -w GOVERSION=customversion
    73stderr 'GOVERSION cannot be modified'
    74! go env -w GOENV=/env
    75stderr 'GOENV can only be set using the OS environment'
    76! go env -w GODEBUG=gctrace=1
    77stderr 'GODEBUG can only be set using the OS environment'
    78
    79# go env -w can set multiple variables
    80env CC=
    81go env CC
    82! stdout ^xyc$
    83go env -w GOOS=$GOOS CC=xyc
    84grep CC=xyc $GOENV
    85# file is maintained in sorted order
    86grep 'CC=xyc\nGOOS=' $GOENV
    87go env CC
    88stdout ^xyc$
    89
    90# go env -u unsets effect of go env -w.
    91go env -u CC
    92go env CC
    93! stdout ^xyc$
    94
    95# go env -w rejects double-set variables
    96! go env -w GOOS=$GOOS GOOS=$GOOS
    97stderr 'multiple values for key: GOOS'
    98
    99# go env -w rejects missing variables
   100! go env -w GOOS
   101stderr 'arguments must be KEY=VALUE: invalid argument: GOOS'
   102
   103# go env -w rejects invalid GO111MODULE values, as otherwise cmd/go would break
   104! go env -w GO111MODULE=badvalue
   105stderr 'invalid GO111MODULE value "badvalue"'
   106
   107# go env -w rejects invalid GOPATH values
   108! go env -w GOPATH=~/go
   109stderr 'GOPATH entry cannot start with shell metacharacter'
   110
   111! go env -w GOPATH=./go
   112stderr 'GOPATH entry is relative; must be absolute path'
   113
   114# go env -w rejects invalid GOTMPDIR values
   115! go env -w GOTMPDIR=x
   116stderr 'go: GOTMPDIR must be an absolute path'
   117
   118# go env -w should accept absolute GOTMPDIR value
   119# and should not create it
   120[GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z
   121[!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z
   122! exists $WORK/x/y/z
   123# we should be able to clear an env
   124go env -u GOTMPDIR
   125go env GOTMPDIR
   126stdout ^$
   127
   128[GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z
   129[!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z
   130go env -w GOTMPDIR=
   131go env GOTMPDIR
   132stdout ^$
   133
   134# go env -w rejects relative CC values
   135[!GOOS:windows] go env -w CC=/usr/bin/clang
   136go env -w CC=clang
   137[!GOOS:windows] ! go env -w CC=./clang
   138[!GOOS:windows] ! go env -w CC=bin/clang
   139[!GOOS:windows] stderr 'go: CC entry is relative; must be absolute path'
   140
   141[GOOS:windows] go env -w CC=$WORK\bin\clang
   142[GOOS:windows] ! go env -w CC=.\clang
   143[GOOS:windows] ! go env -w CC=bin\clang
   144[GOOS:windows] stderr 'go: CC entry is relative; must be absolute path'
   145
   146# go env -w rejects relative CXX values
   147[!GOOS:windows] go env -w CC=/usr/bin/cpp
   148go env -w CXX=cpp
   149[!GOOS:windows] ! go env -w CXX=./cpp
   150[!GOOS:windows] ! go env -w CXX=bin/cpp
   151[!GOOS:windows] stderr 'go: CXX entry is relative; must be absolute path'
   152
   153[GOOS:windows] go env -w CXX=$WORK\bin\cpp
   154[GOOS:windows] ! go env -w CXX=.\cpp
   155[GOOS:windows] ! go env -w CXX=bin\cpp
   156[GOOS:windows] stderr 'go: CXX entry is relative; must be absolute path'
   157
   158# go env -w/-u checks validity of GOOS/ARCH combinations
   159env GOOS=
   160env GOARCH=
   161# check -w doesn't allow invalid GOOS
   162! go env -w GOOS=linuxx
   163stderr 'unsupported GOOS/GOARCH pair linuxx'
   164# check -w doesn't allow invalid GOARCH
   165! go env -w GOARCH=amd644
   166stderr 'unsupported GOOS/GOARCH.*/amd644$'
   167# check -w doesn't allow invalid GOOS with valid GOARCH
   168! go env -w GOOS=linuxx GOARCH=amd64
   169stderr 'unsupported GOOS/GOARCH pair linuxx'
   170# check a valid GOOS and GOARCH values but an incompatible combinations
   171! go env -w GOOS=android GOARCH=s390x
   172stderr 'unsupported GOOS/GOARCH pair android/s390x'
   173# check that -u considers explicit envs
   174go env -w GOOS=linux GOARCH=mips
   175env GOOS=windows
   176! go env -u GOOS
   177stderr 'unsupported GOOS/GOARCH.*windows/mips$'
   178env GOOS=
   179
   180# go env -w should reject relative paths in GOMODCACHE environment.
   181! go env -w GOMODCACHE=~/test
   182stderr 'go: GOMODCACHE entry is relative; must be absolute path: "~/test"'
   183! go env -w GOMODCACHE=./test
   184stderr 'go: GOMODCACHE entry is relative; must be absolute path: "./test"'
   185
   186# go env -w checks validity of GOEXPERIMENT
   187env GOEXPERIMENT=
   188! go env -w GOEXPERIMENT=badexp
   189stderr 'unknown GOEXPERIMENT badexp'
   190go env -w GOEXPERIMENT=fieldtrack
   191
   192# go env -w and go env -u work on unknown fields already in the go/env file
   193cp bad.env $GOENV
   194go env GOENV
   195cat $GOENV
   196go env
   197! stdout UNKNOWN
   198go env UNKNOWN
   199stdout yes
   200go env -w UNKNOWN=maybe
   201go env UNKNOWN
   202stdout maybe
   203go env -u UNKNOWN
   204go env UNKNOWN
   205! stdout . # gone
   206
   207-- bad.env --
   208UNKNOWN=yes

View as plain text