...
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 GODEBUG=gctrace=1
69stderr 'unknown go command variable GODEBUG'
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
77# go env -w can set multiple variables
78env CC=
79go env CC
80! stdout ^xyc$
81go env -w GOOS=$GOOS CC=xyc
82grep CC=xyc $GOENV
83# file is maintained in sorted order
84grep 'CC=xyc\nGOOS=' $GOENV
85go env CC
86stdout ^xyc$
87
88# go env -u unsets effect of go env -w.
89go env -u CC
90go env CC
91! stdout ^xyc$
92
93# go env -w rejects double-set variables
94! go env -w GOOS=$GOOS GOOS=$GOOS
95stderr 'multiple values for key: GOOS'
96
97# go env -w rejects missing variables
98! go env -w GOOS
99stderr 'arguments must be KEY=VALUE: invalid argument: GOOS'
100
101# go env -w rejects invalid GO111MODULE values, as otherwise cmd/go would break
102! go env -w GO111MODULE=badvalue
103stderr 'invalid GO111MODULE value "badvalue"'
104
105# go env -w rejects invalid GOPATH values
106! go env -w GOPATH=~/go
107stderr 'GOPATH entry cannot start with shell metacharacter'
108
109! go env -w GOPATH=./go
110stderr 'GOPATH entry is relative; must be absolute path'
111
112# go env -w rejects invalid GOTMPDIR values
113! go env -w GOTMPDIR=x
114stderr 'go: GOTMPDIR must be an absolute path'
115
116# go env -w should accept absolute GOTMPDIR value
117# and should not create it
118[GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z
119[!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z
120! exists $WORK/x/y/z
121# we should be able to clear an env
122go env -u GOTMPDIR
123go env GOTMPDIR
124stdout ^$
125
126[GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z
127[!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z
128go env -w GOTMPDIR=
129go env GOTMPDIR
130stdout ^$
131
132# go env -w rejects relative CC values
133[!GOOS:windows] go env -w CC=/usr/bin/clang
134go env -w CC=clang
135[!GOOS:windows] ! go env -w CC=./clang
136[!GOOS:windows] ! go env -w CC=bin/clang
137[!GOOS:windows] stderr 'go: CC entry is relative; must be absolute path'
138
139[GOOS:windows] go env -w CC=$WORK\bin\clang
140[GOOS:windows] ! go env -w CC=.\clang
141[GOOS:windows] ! go env -w CC=bin\clang
142[GOOS:windows] stderr 'go: CC entry is relative; must be absolute path'
143
144# go env -w rejects relative CXX values
145[!GOOS:windows] go env -w CC=/usr/bin/cpp
146go env -w CXX=cpp
147[!GOOS:windows] ! go env -w CXX=./cpp
148[!GOOS:windows] ! go env -w CXX=bin/cpp
149[!GOOS:windows] stderr 'go: CXX entry is relative; must be absolute path'
150
151[GOOS:windows] go env -w CXX=$WORK\bin\cpp
152[GOOS:windows] ! go env -w CXX=.\cpp
153[GOOS:windows] ! go env -w CXX=bin\cpp
154[GOOS:windows] stderr 'go: CXX entry is relative; must be absolute path'
155
156# go env -w/-u checks validity of GOOS/ARCH combinations
157env GOOS=
158env GOARCH=
159# check -w doesn't allow invalid GOOS
160! go env -w GOOS=linuxx
161stderr 'unsupported GOOS/GOARCH pair linuxx'
162# check -w doesn't allow invalid GOARCH
163! go env -w GOARCH=amd644
164stderr 'unsupported GOOS/GOARCH.*/amd644$'
165# check -w doesn't allow invalid GOOS with valid GOARCH
166! go env -w GOOS=linuxx GOARCH=amd64
167stderr 'unsupported GOOS/GOARCH pair linuxx'
168# check a valid GOOS and GOARCH values but an incompatible combinations
169! go env -w GOOS=android GOARCH=s390x
170stderr 'unsupported GOOS/GOARCH pair android/s390x'
171# check that -u considers explicit envs
172go env -w GOOS=linux GOARCH=mips
173env GOOS=windows
174! go env -u GOOS
175stderr 'unsupported GOOS/GOARCH.*windows/mips$'
176env GOOS=
177
178# go env -w should reject relative paths in GOMODCACHE environment.
179! go env -w GOMODCACHE=~/test
180stderr 'go: GOMODCACHE entry is relative; must be absolute path: "~/test"'
181! go env -w GOMODCACHE=./test
182stderr 'go: GOMODCACHE entry is relative; must be absolute path: "./test"'
183
184# go env -w checks validity of GOEXPERIMENT
185env GOEXPERIMENT=
186! go env -w GOEXPERIMENT=badexp
187stderr 'unknown GOEXPERIMENT badexp'
188go env -w GOEXPERIMENT=fieldtrack
189
190# go env -w and go env -u work on unknown fields already in the go/env file
191cp bad.env $GOENV
192go env GOENV
193cat $GOENV
194go env
195! stdout UNKNOWN
196go env UNKNOWN
197stdout yes
198go env -w UNKNOWN=maybe
199go env UNKNOWN
200stdout maybe
201go env -u UNKNOWN
202go env UNKNOWN
203! stdout . # gone
204
205-- bad.env --
206UNKNOWN=yes
View as plain text