1 env GO111MODULE=off
2
3 # go env should default to the right places
4 env AppData=$HOME/windowsappdata
5 env home=$HOME/plan9home
6 go 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.
17 env GOENV=$WORK/envdir/go/env
18 go env GOENV
19 stdout envdir[\\/]go[\\/]env
20
21 # go env shows all variables
22 go env
23 stdout GOARCH=
24 stdout GOOS=
25 stdout GOROOT=
26
27 # go env ignores invalid flag in GOFLAGS environment variable
28 env GOFLAGS='=true'
29 go env
30
31 # checking errors
32 ! go env -w
33 stderr 'go: no KEY=VALUE arguments given'
34 ! go env -u
35 stderr 'go: ''go env -u'' requires an argument'
36
37 # go env -w changes default setting
38 env root=
39 [GOOS:windows] env root=c:
40 env GOPATH=
41 go env -w GOPATH=$root/non-exist/gopath
42 ! stderr .+
43 grep GOPATH=$root/non-exist/gopath $WORK/envdir/go/env
44 go env GOPATH
45 stdout /non-exist/gopath
46
47 # go env -w does not override OS environment, and warns about that
48 env GOPATH=$root/other
49 go env -w GOPATH=$root/non-exist/gopath2
50 stderr 'warning: go env -w GOPATH=... does not override conflicting OS environment variable'
51 go env GOPATH
52 stdout $root/other
53
54 # but go env -w does do the update, and unsetting the env var exposes the change
55 env GOPATH=
56 go env GOPATH
57 stdout $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.
61 env GOPATH=$root/other
62 go env -u GOPATH
63 ! stderr .+
64 go env -u GOPATH
65 ! stderr .+
66
67 # go env -w rejects unknown or bad variables
68 ! go env -w GOGC=off
69 stderr 'unknown go command variable GOGC'
70 ! go env -w GOEXE=.bat
71 stderr 'GOEXE cannot be modified'
72 ! go env -w GOVERSION=customversion
73 stderr 'GOVERSION cannot be modified'
74 ! go env -w GOENV=/env
75 stderr 'GOENV can only be set using the OS environment'
76 ! go env -w GODEBUG=gctrace=1
77 stderr 'GODEBUG can only be set using the OS environment'
78
79 # go env -w can set multiple variables
80 env CC=
81 go env CC
82 ! stdout ^xyc$
83 go env -w GOOS=$GOOS CC=xyc
84 grep CC=xyc $GOENV
85 # file is maintained in sorted order
86 grep 'CC=xyc\nGOOS=' $GOENV
87 go env CC
88 stdout ^xyc$
89
90 # go env -u unsets effect of go env -w.
91 go env -u CC
92 go env CC
93 ! stdout ^xyc$
94
95 # go env -w rejects double-set variables
96 ! go env -w GOOS=$GOOS GOOS=$GOOS
97 stderr 'multiple values for key: GOOS'
98
99 # go env -w rejects missing variables
100 ! go env -w GOOS
101 stderr '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
105 stderr 'invalid GO111MODULE value "badvalue"'
106
107 # go env -w rejects invalid GOPATH values
108 ! go env -w GOPATH=~/go
109 stderr 'GOPATH entry cannot start with shell metacharacter'
110
111 ! go env -w GOPATH=./go
112 stderr 'GOPATH entry is relative; must be absolute path'
113
114 # go env -w rejects invalid GOTMPDIR values
115 ! go env -w GOTMPDIR=x
116 stderr '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
124 go env -u GOTMPDIR
125 go env GOTMPDIR
126 stdout ^$
127
128 [GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z
129 [!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z
130 go env -w GOTMPDIR=
131 go env GOTMPDIR
132 stdout ^$
133
134 # go env -w rejects relative CC values
135 [!GOOS:windows] go env -w CC=/usr/bin/clang
136 go 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
148 go 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
159 env GOOS=
160 env GOARCH=
161 # check -w doesn't allow invalid GOOS
162 ! go env -w GOOS=linuxx
163 stderr 'unsupported GOOS/GOARCH pair linuxx'
164 # check -w doesn't allow invalid GOARCH
165 ! go env -w GOARCH=amd644
166 stderr 'unsupported GOOS/GOARCH.*/amd644$'
167 # check -w doesn't allow invalid GOOS with valid GOARCH
168 ! go env -w GOOS=linuxx GOARCH=amd64
169 stderr '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
172 stderr 'unsupported GOOS/GOARCH pair android/s390x'
173 # check that -u considers explicit envs
174 go env -w GOOS=linux GOARCH=mips
175 env GOOS=windows
176 ! go env -u GOOS
177 stderr 'unsupported GOOS/GOARCH.*windows/mips$'
178 env GOOS=
179
180 # go env -w should reject relative paths in GOMODCACHE environment.
181 ! go env -w GOMODCACHE=~/test
182 stderr 'go: GOMODCACHE entry is relative; must be absolute path: "~/test"'
183 ! go env -w GOMODCACHE=./test
184 stderr 'go: GOMODCACHE entry is relative; must be absolute path: "./test"'
185
186 # go env -w checks validity of GOEXPERIMENT
187 env GOEXPERIMENT=
188 ! go env -w GOEXPERIMENT=badexp
189 stderr 'unknown GOEXPERIMENT badexp'
190 go env -w GOEXPERIMENT=fieldtrack
191
192 # go env -w and go env -u work on unknown fields already in the go/env file
193 cp bad.env $GOENV
194 go env GOENV
195 cat $GOENV
196 go env
197 ! stdout UNKNOWN
198 go env UNKNOWN
199 stdout yes
200 go env -w UNKNOWN=maybe
201 go env UNKNOWN
202 stdout maybe
203 go env -u UNKNOWN
204 go env UNKNOWN
205 ! stdout . # gone
206
207 -- bad.env --
208 UNKNOWN=yes
209
View as plain text