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 [aix] stdout $HOME/.config/go/env
8 [darwin] stdout $HOME'/Library/Application Support/go/env'
9 [freebsd] stdout $HOME/.config/go/env
10 [linux] stdout $HOME/.config/go/env
11 [netbsd] stdout $HOME/.config/go/env
12 [openbsd] stdout $HOME/.config/go/env
13 [plan9] stdout $HOME/plan9home/lib/go/env
14 [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 [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 GODEBUG=gctrace=1
69 stderr 'unknown go command variable GODEBUG'
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
77 # go env -w can set multiple variables
78 env CC=
79 go env CC
80 ! stdout ^xyc$
81 go env -w GOOS=$GOOS CC=xyc
82 grep CC=xyc $GOENV
83 # file is maintained in sorted order
84 grep 'CC=xyc\nGOOS=' $GOENV
85 go env CC
86 stdout ^xyc$
87
88 # go env -u unsets effect of go env -w.
89 go env -u CC
90 go env CC
91 ! stdout ^xyc$
92
93 # go env -w rejects double-set variables
94 ! go env -w GOOS=$GOOS GOOS=$GOOS
95 stderr 'multiple values for key: GOOS'
96
97 # go env -w rejects missing variables
98 ! go env -w GOOS
99 stderr '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
103 stderr 'invalid GO111MODULE value "badvalue"'
104
105 # go env -w rejects invalid GOPATH values
106 ! go env -w GOPATH=~/go
107 stderr 'GOPATH entry cannot start with shell metacharacter'
108
109 ! go env -w GOPATH=./go
110 stderr 'GOPATH entry is relative; must be absolute path'
111
112 # go env -w rejects invalid GOTMPDIR values
113 ! go env -w GOTMPDIR=x
114 stderr 'go: GOTMPDIR must be an absolute path'
115
116 # go env -w should accept absolute GOTMPDIR value
117 # and should not create it
118 [windows] go env -w GOTMPDIR=$WORK\x\y\z
119 [!windows] go env -w GOTMPDIR=$WORK/x/y/z
120 ! exists $WORK/x/y/z
121 # we should be able to clear an env
122 go env -u GOTMPDIR
123 go env GOTMPDIR
124 stdout ^$
125
126 [windows] go env -w GOTMPDIR=$WORK\x\y\z
127 [!windows] go env -w GOTMPDIR=$WORK/x/y/z
128 go env -w GOTMPDIR=
129 go env GOTMPDIR
130 stdout ^$
131
132 # go env -w rejects relative CC values
133 [!windows] go env -w CC=/usr/bin/clang
134 go env -w CC=clang
135 [!windows] ! go env -w CC=./clang
136 [!windows] ! go env -w CC=bin/clang
137 [!windows] stderr 'go: CC entry is relative; must be absolute path'
138
139 [windows] go env -w CC=$WORK\bin\clang
140 [windows] ! go env -w CC=.\clang
141 [windows] ! go env -w CC=bin\clang
142 [windows] stderr 'go: CC entry is relative; must be absolute path'
143
144 # go env -w rejects relative CXX values
145 [!windows] go env -w CC=/usr/bin/cpp
146 go env -w CXX=cpp
147 [!windows] ! go env -w CXX=./cpp
148 [!windows] ! go env -w CXX=bin/cpp
149 [!windows] stderr 'go: CXX entry is relative; must be absolute path'
150
151 [windows] go env -w CXX=$WORK\bin\cpp
152 [windows] ! go env -w CXX=.\cpp
153 [windows] ! go env -w CXX=bin\cpp
154 [windows] stderr 'go: CXX entry is relative; must be absolute path'
155
156 # go env -w/-u checks validity of GOOS/ARCH combinations
157 env GOOS=
158 env GOARCH=
159 # check -w doesn't allow invalid GOOS
160 ! go env -w GOOS=linuxx
161 stderr 'unsupported GOOS/GOARCH pair linuxx'
162 # check -w doesn't allow invalid GOARCH
163 ! go env -w GOARCH=amd644
164 stderr 'unsupported GOOS/GOARCH.*/amd644$'
165 # check -w doesn't allow invalid GOOS with valid GOARCH
166 ! go env -w GOOS=linuxx GOARCH=amd64
167 stderr '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
170 stderr 'unsupported GOOS/GOARCH pair android/s390x'
171 # check that -u considers explicit envs
172 go env -w GOOS=linux GOARCH=mips
173 env GOOS=windows
174 ! go env -u GOOS
175 stderr 'unsupported GOOS/GOARCH.*windows/mips$'
176
177 # go env -w should reject relative paths in GOMODCACHE environment.
178 ! go env -w GOMODCACHE=~/test
179 stderr 'go: GOMODCACHE entry is relative; must be absolute path: "~/test"'
180 ! go env -w GOMODCACHE=./test
181 stderr 'go: GOMODCACHE entry is relative; must be absolute path: "./test"'
182
183 # go env -w checks validity of GOEXPERIMENT
184 env GOEXPERIMENT=
185 ! go env -w GOEXPERIMENT=badexp
186 stderr 'unknown GOEXPERIMENT badexp'
187 go env -w GOEXPERIMENT=fieldtrack
188
View as plain text