aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/env_write.txt
blob: b5e97391679cc52442322e972c7a82fbed0e30bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
env GO111MODULE=off

# go env should default to the right places
env AppData=$HOME/windowsappdata
env home=$HOME/plan9home
go env GOENV
[aix] stdout $HOME/.config/go/env
[darwin] stdout $HOME'/Library/Application Support/go/env'
[freebsd] stdout $HOME/.config/go/env
[linux] stdout $HOME/.config/go/env
[netbsd] stdout $HOME/.config/go/env
[openbsd] stdout $HOME/.config/go/env
[plan9] stdout $HOME/plan9home/lib/go/env
[windows] stdout $HOME\\windowsappdata\\go\\env

# Now override it to something writable.
env GOENV=$WORK/envdir/go/env
go env GOENV
stdout envdir[\\/]go[\\/]env

# go env shows all variables
go env
stdout GOARCH=
stdout GOOS=
stdout GOROOT=

# go env ignores invalid flag in GOFLAGS environment variable
env GOFLAGS='=true'
go env

# checking errors
! go env -w
stderr 'go env -w: no KEY=VALUE arguments given'
! go env -u
stderr 'go env -u: no arguments given'

# go env -w changes default setting
env root=
[windows] env root=c:
env GOPATH=
go env -w GOPATH=$root/non-exist/gopath
! stderr .+
grep GOPATH=$root/non-exist/gopath $WORK/envdir/go/env
go env GOPATH
stdout /non-exist/gopath

# go env -w does not override OS environment, and warns about that
env GOPATH=$root/other
go env -w GOPATH=$root/non-exist/gopath2
stderr 'warning: go env -w GOPATH=... does not override conflicting OS environment variable'
go env GOPATH
stdout $root/other

# but go env -w does do the update, and unsetting the env var exposes the change
env GOPATH=
go env GOPATH
stdout $root/non-exist/gopath2

# unsetting with go env -u does not warn about OS environment overrides,
# nor does it warn about variables that haven't been set by go env -w.
env GOPATH=$root/other
go env -u GOPATH
! stderr .+
go env -u GOPATH
! stderr .+

# go env -w rejects unknown or bad variables
! go env -w GODEBUG=gctrace=1
stderr 'unknown go command variable GODEBUG'
! go env -w GOEXE=.bat
stderr 'GOEXE cannot be modified'
! go env -w GOVERSION=customversion
stderr 'GOVERSION cannot be modified'
! go env -w GOENV=/env
stderr 'GOENV can only be set using the OS environment'

# go env -w can set multiple variables
env CC=
go env CC
! stdout ^xyc$
go env -w GOOS=$GOOS CC=xyc
grep CC=xyc $GOENV
# file is maintained in sorted order
grep 'CC=xyc\nGOOS=' $GOENV
go env CC
stdout ^xyc$

# go env -u unsets effect of go env -w.
go env -u CC
go env CC
! stdout ^xyc$

# go env -w rejects double-set variables
! go env -w GOOS=$GOOS GOOS=$GOOS
stderr 'multiple values for key: GOOS'

# go env -w rejects missing variables
! go env -w GOOS
stderr 'arguments must be KEY=VALUE: invalid argument: GOOS'

# go env -w rejects invalid GO111MODULE values, as otherwise cmd/go would break
! go env -w GO111MODULE=badvalue
stderr 'invalid GO111MODULE value "badvalue"'

# go env -w rejects invalid GOPATH values
! go env -w GOPATH=~/go
stderr 'GOPATH entry cannot start with shell metacharacter'

! go env -w GOPATH=./go
stderr 'GOPATH entry is relative; must be absolute path'

# go env -w rejects invalid GOTMPDIR values
! go env -w GOTMPDIR=x
stderr 'go env -w: GOTMPDIR must be an absolute path'

# go env -w should accept absolute GOTMPDIR value
# and should not create it
[windows] go env -w GOTMPDIR=$WORK\x\y\z
[!windows] go env -w GOTMPDIR=$WORK/x/y/z
! exists $WORK/x/y/z
# we should be able to clear an env
go env -u GOTMPDIR
go env GOTMPDIR
stdout ^$

[windows] go env -w GOTMPDIR=$WORK\x\y\z
[!windows] go env -w GOTMPDIR=$WORK/x/y/z
go env -w GOTMPDIR=
go env GOTMPDIR
stdout ^$

# go env -w rejects relative CC values
[!windows] go env -w CC=/usr/bin/clang
go env -w CC=clang
[!windows] ! go env -w CC=./clang
[!windows] ! go env -w CC=bin/clang
[!windows] stderr 'go env -w: CC entry is relative; must be absolute path'

[windows] go env -w CC=$WORK\bin\clang
[windows] ! go env -w CC=.\clang
[windows] ! go env -w CC=bin\clang
[windows] stderr 'go env -w: CC entry is relative; must be absolute path'

# go env -w rejects relative CXX values
[!windows] go env -w CC=/usr/bin/cpp
go env -w CXX=cpp
[!windows] ! go env -w CXX=./cpp
[!windows] ! go env -w CXX=bin/cpp
[!windows] stderr 'go env -w: CXX entry is relative; must be absolute path'

[windows] go env -w CXX=$WORK\bin\cpp
[windows] ! go env -w CXX=.\cpp
[windows] ! go env -w CXX=bin\cpp
[windows] stderr 'go env -w: CXX entry is relative; must be absolute path'

# go env -w/-u checks validity of GOOS/ARCH combinations
env GOOS=
env GOARCH=
# check -w doesn't allow invalid GOOS
! go env -w GOOS=linuxx
stderr 'unsupported GOOS/GOARCH pair linuxx'
# check -w doesn't allow invalid GOARCH
! go env -w GOARCH=amd644
stderr 'unsupported GOOS/GOARCH.*/amd644$'
# check -w doesn't allow invalid GOOS with valid GOARCH
! go env -w GOOS=linuxx GOARCH=amd64
stderr 'unsupported GOOS/GOARCH pair linuxx'
# check a valid GOOS and GOARCH values but an incompatible combinations
! go env -w GOOS=android GOARCH=s390x
stderr 'unsupported GOOS/GOARCH pair android/s390x'
# check that -u considers explicit envs
go env -w GOOS=linux GOARCH=mips
env GOOS=windows
! go env -u GOOS
stderr 'unsupported GOOS/GOARCH.*windows/mips$'

# go env -w should reject relative paths in GOMODCACHE environment.
! go env -w GOMODCACHE=~/test
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "~/test"'
! go env -w GOMODCACHE=./test
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "./test"'

# go env -w checks validity of GOEXPERIMENT
env GOEXPERIMENT=
! go env -w GOEXPERIMENT=badexp
stderr 'unknown GOEXPERIMENT badexp'
go env -w GOEXPERIMENT=fieldtrack