1 # This test uses the fake toolchain switch support in cmd/go/internal/toolchain.Switch
2 # to exercise all the version selection logic without needing actual toolchains.
3 # See gotoolchain_net.txt and gotoolchain_path.txt for tests of network and PATH toolchains.
5 env TESTGO_VERSION=go1.500
6 env TESTGO_VERSION_SWITCH=switch
8 # Default setting should be auto
13 stdout GOTOOLCHAIN=.?auto.? # maybe quoted
15 # GOTOOLCHAIN=auto runs default toolchain without a go.mod or go.work
19 # GOTOOLCHAIN=path runs default toolchain without a go.mod or go.work
24 # GOTOOLCHAIN=asdf is a syntax error
27 stderr '^go: invalid GOTOOLCHAIN "asdf"$'
29 # GOTOOLCHAIN=version is used directly.
30 env GOTOOLCHAIN=go1.600
34 env GOTOOLCHAIN=go1.400
38 # GOTOOLCHAIN=version+auto sets a minimum.
39 env GOTOOLCHAIN=go1.600+auto
43 env GOTOOLCHAIN=go1.400+auto
47 # GOTOOLCHAIN=version+path sets a minimum too.
48 env GOTOOLCHAIN=go1.600+path
52 env GOTOOLCHAIN=go1.400+path
56 # Create a go.mod file and test interactions with auto and path.
58 # GOTOOLCHAIN=auto uses go line if newer than local toolchain.
61 go mod edit -go=1.700 -toolchain=none
65 go mod edit -go=1.300 -toolchain=none
67 stdout 1.500 # local toolchain is newer
69 go mod edit -go=1.700 -toolchain=go1.300
71 stdout go1.700 # toolchain too old, ignored
73 go mod edit -go=1.300 -toolchain=default
77 go mod edit -go=1.700 -toolchain=default
79 stdout go1.500 # toolchain local is like GOTOOLCHAIN=local and wins
81 stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; go.mod sets toolchain default\)'
83 # GOTOOLCHAIN=path does the same.
85 go mod edit -go=1.700 -toolchain=none
89 go mod edit -go=1.300 -toolchain=none
91 stdout 1.500 # local toolchain is newer
93 go mod edit -go=1.700 -toolchain=go1.300
95 stdout go1.700 # toolchain too old, ignored
97 go mod edit -go=1.300 -toolchain=default
101 go mod edit -go=1.700 -toolchain=default
103 stdout go1.500 # toolchain default applies even if older than go line
105 stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; GOTOOLCHAIN=path; go.mod sets toolchain default\)'
107 # GOTOOLCHAIN=min+auto with toolchain default uses min, not local
109 env GOTOOLCHAIN=go1.400+auto
110 go mod edit -go=1.300 -toolchain=default
112 stdout 1.400 # not 1.500 local toolchain
114 env GOTOOLCHAIN=go1.600+auto
115 go mod edit -go=1.300 -toolchain=default
117 stdout 1.600 # not 1.500 local toolchain
119 # GOTOOLCHAIN names can have -suffix
120 env GOTOOLCHAIN=go1.800-bigcorp
122 stdout go1.800-bigcorp
125 go mod edit -go=1.999 -toolchain=go1.800-bigcorp
129 go mod edit -go=1.777 -toolchain=go1.800-bigcorp
131 stdout go1.800-bigcorp
133 # go.work takes priority over go.mod
134 go mod edit -go=1.700 -toolchain=go1.999-wrong
136 go work edit -go=1.400 -toolchain=go1.600-right
140 go work edit -go=1.400 -toolchain=default
144 # go.work misconfiguration does not break go work edit
145 # ('go 1.600 / toolchain local' forces use of 1.500 which can't normally load that go.work; allow work edit to fix it.)
146 go work edit -go=1.600 -toolchain=default
150 go work edit -toolchain=none
156 # go.mod misconfiguration does not break go mod edit
157 go mod edit -go=1.600 -toolchain=default
161 go mod edit -toolchain=none
165 # toolchain built with a custom version should know how it compares to others
167 env TESTGO_VERSION=go1.500-bigcorp
168 go mod edit -go=1.499 -toolchain=none
170 stdout go1.500-bigcorp
172 go mod edit -go=1.500 -toolchain=none
174 stdout go1.500-bigcorp
176 go mod edit -go=1.501 -toolchain=none
180 env TESTGO_VERSION='go1.500 (bigcorp)'
181 go mod edit -go=1.499 -toolchain=none
183 stdout 'go1.500 \(bigcorp\)'
185 go mod edit -go=1.500 -toolchain=none
187 stdout 'go1.500 \(bigcorp\)'
189 go mod edit -go=1.501 -toolchain=none
193 # go install m@v and go run m@v should ignore go.mod and use m@v
194 env TESTGO_VERSION=go1.2.3
195 go mod edit -go=1.999 -toolchain=go1.998
197 ! go install rsc.io/fortune/nonexist@v0.0.1
198 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
199 stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist'
201 ! go run rsc.io/fortune/nonexist@v0.0.1
202 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
203 stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist'
205 # go install should handle unknown flags to find m@v
206 ! go install -unknownflag rsc.io/fortune/nonexist@v0.0.1
207 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
208 stderr '^flag provided but not defined: -unknownflag'
210 ! go install -unknownflag arg rsc.io/fortune/nonexist@v0.0.1
211 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
212 stderr '^flag provided but not defined: -unknownflag'
214 # go run cannot handle unknown boolean flags
215 ! go run -unknownflag rsc.io/fortune/nonexist@v0.0.1
217 stderr '^flag provided but not defined: -unknownflag'
219 ! go run -unknownflag oops rsc.io/fortune/nonexist@v0.0.1
221 stderr '^flag provided but not defined: -unknownflag'
223 # go run can handle unknown flag with argument.
224 ! go run -unknown=flag rsc.io/fortune/nonexist@v0.0.1
225 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
226 stderr '^flag provided but not defined: -unknown'
228 # go install m@v should handle queries
229 ! go install rsc.io/fortune/nonexist@v0.0
230 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
231 stderr '^go: rsc.io/fortune/nonexist@v0.0: module rsc.io/fortune@v0.0 found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist'
233 # go run m@v should handle queries
234 ! go install rsc.io/fortune/nonexist@v0
235 stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
236 stderr '^go: rsc.io/fortune/nonexist@v0: module rsc.io/fortune@v0 found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist'
238 # go install m@v should use local toolchain if not upgrading
239 ! go install rsc.io/fortune/nonexist@v1
242 stderr '^go: downloading rsc.io/fortune v1.0.0$'
243 stderr '^go: rsc.io/fortune/nonexist@v1: module rsc.io/fortune@v1 found \(v1.0.0\), but does not contain package rsc.io/fortune/nonexist'
245 # go run m@v should use local toolchain if not upgrading
246 ! go run rsc.io/fortune/nonexist@v1
249 stderr '^go: rsc.io/fortune/nonexist@v1: module rsc.io/fortune@v1 found \(v1.0.0\), but does not contain package rsc.io/fortune/nonexist'