| 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. |
| 4 |
|
| 5 |
env TESTGO_VERSION=go1.500 |
| 6 |
env TESTGO_VERSION_SWITCH=switch |
| 7 |
|
| 8 |
# GOTOOLCHAIN=auto runs default toolchain without a go.mod or go.work |
| 9 |
env GOTOOLCHAIN=auto |
| 10 |
go version |
| 11 |
stdout go1.500 |
| 12 |
|
| 13 |
# GOTOOLCHAIN=path runs default toolchain without a go.mod or go.work |
| 14 |
env GOTOOLCHAIN=path |
| 15 |
go version |
| 16 |
stdout go1.500 |
| 17 |
|
| 18 |
# GOTOOLCHAIN=asdf is a syntax error |
| 19 |
env GOTOOLCHAIN=asdf |
| 20 |
! go version |
| 21 |
stderr '^go: invalid GOTOOLCHAIN "asdf"$' |
| 22 |
|
| 23 |
# GOTOOLCHAIN=version is used directly. |
| 24 |
env GOTOOLCHAIN=go1.600 |
| 25 |
go version |
| 26 |
stdout go1.600 |
| 27 |
|
| 28 |
env GOTOOLCHAIN=go1.400 |
| 29 |
go version |
| 30 |
stdout go1.400 |
| 31 |
|
| 32 |
# GOTOOLCHAIN=version+auto sets a minimum. |
| 33 |
env GOTOOLCHAIN=go1.600+auto |
| 34 |
go version |
| 35 |
stdout go1.600 |
| 36 |
|
| 37 |
env GOTOOLCHAIN=go1.400.0+auto |
| 38 |
go version |
| 39 |
stdout go1.400.0 |
| 40 |
|
| 41 |
# GOTOOLCHAIN=version+path sets a minimum too. |
| 42 |
env GOTOOLCHAIN=go1.600+path |
| 43 |
go version |
| 44 |
stdout go1.600 |
| 45 |
|
| 46 |
env GOTOOLCHAIN=go1.400+path |
| 47 |
go version |
| 48 |
stdout go1.400 |
| 49 |
|
| 50 |
# Create a go.mod file and test interactions with auto and path. |
| 51 |
|
| 52 |
# GOTOOLCHAIN=auto uses go line if newer than local toolchain. |
| 53 |
env GOTOOLCHAIN=auto |
| 54 |
go mod init m |
| 55 |
go mod edit -go=1.700 -toolchain=none |
| 56 |
go version |
| 57 |
stdout 1.700 |
| 58 |
|
| 59 |
go mod edit -go=1.300 -toolchain=none |
| 60 |
go version |
| 61 |
stdout 1.500 # local toolchain is newer |
| 62 |
|
| 63 |
go mod edit -go=1.700 -toolchain=go1.300 |
| 64 |
go version |
| 65 |
stdout go1.700 # toolchain too old, ignored |
| 66 |
|
| 67 |
go mod edit -go=1.300 -toolchain=default |
| 68 |
go version |
| 69 |
stdout go1.500 |
| 70 |
|
| 71 |
go mod edit -go=1.700 -toolchain=default |
| 72 |
go version |
| 73 |
stdout go1.500 # toolchain local is like GOTOOLCHAIN=local and wins |
| 74 |
! go build |
| 75 |
stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; go.mod sets toolchain default\)' |
| 76 |
|
| 77 |
# GOTOOLCHAIN=path does the same. |
| 78 |
env GOTOOLCHAIN=path |
| 79 |
go mod edit -go=1.700 -toolchain=none |
| 80 |
go version |
| 81 |
stdout 1.700 |
| 82 |
|
| 83 |
go mod edit -go=1.300 -toolchain=none |
| 84 |
go version |
| 85 |
stdout 1.500 # local toolchain is newer |
| 86 |
|
| 87 |
go mod edit -go=1.700 -toolchain=go1.300 |
| 88 |
go version |
| 89 |
stdout go1.700 # toolchain too old, ignored |
| 90 |
|
| 91 |
go mod edit -go=1.300 -toolchain=default |
| 92 |
go version |
| 93 |
stdout go1.500 |
| 94 |
|
| 95 |
go mod edit -go=1.700 -toolchain=default |
| 96 |
go version |
| 97 |
stdout go1.500 # toolchain default applies even if older than go line |
| 98 |
! go build |
| 99 |
stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; GOTOOLCHAIN=path; go.mod sets toolchain default\)' |
| 100 |
|
| 101 |
# GOTOOLCHAIN=min+auto with toolchain default uses min, not local |
| 102 |
|
| 103 |
env GOTOOLCHAIN=go1.400+auto |
| 104 |
go mod edit -go=1.300 -toolchain=default |
| 105 |
go version |
| 106 |
stdout 1.400 # not 1.500 local toolchain |
| 107 |
|
| 108 |
env GOTOOLCHAIN=go1.600+auto |
| 109 |
go mod edit -go=1.300 -toolchain=default |
| 110 |
go version |
| 111 |
stdout 1.600 # not 1.500 local toolchain |
| 112 |
|
| 113 |
# GOTOOLCHAIN names can have -suffix |
| 114 |
env GOTOOLCHAIN=go1.800-bigcorp |
| 115 |
go version |
| 116 |
stdout go1.800-bigcorp |
| 117 |
|
| 118 |
env GOTOOLCHAIN=auto |
| 119 |
go mod edit -go=1.999 -toolchain=go1.800-bigcorp |
| 120 |
go version |
| 121 |
stdout go1.999 |
| 122 |
|
| 123 |
go mod edit -go=1.777 -toolchain=go1.800-bigcorp |
| 124 |
go version |
| 125 |
stdout go1.800-bigcorp |
| 126 |
|
| 127 |
# go.work takes priority over go.mod |
| 128 |
go mod edit -go=1.700 -toolchain=go1.999-wrong |
| 129 |
go work init |
| 130 |
go work edit -go=1.400 -toolchain=go1.600-right |
| 131 |
go version |
| 132 |
stdout go1.600-right |
| 133 |
|
| 134 |
go work edit -go=1.400 -toolchain=default |
| 135 |
go version |
| 136 |
stdout go1.500 |
| 137 |
|
| 138 |
# go.work misconfiguration does not break go work edit |
| 139 |
# ('go 1.600 / toolchain local' forces use of 1.500 which can't normally load that go.work; allow work edit to fix it.) |
| 140 |
go work edit -go=1.600 -toolchain=default |
| 141 |
go version |
| 142 |
stdout go1.500 |
| 143 |
|
| 144 |
go work edit -toolchain=none |
| 145 |
go version |
| 146 |
stdout go1.600 |
| 147 |
|
| 148 |
rm go.work |
| 149 |
|
| 150 |
# go.mod misconfiguration does not break go mod edit |
| 151 |
go mod edit -go=1.600 -toolchain=default |
| 152 |
go version |
| 153 |
stdout go1.500 |
| 154 |
|
| 155 |
go mod edit -toolchain=none |
| 156 |
go version |
| 157 |
stdout go1.600 |
| 158 |
|
| 159 |
# toolchain built with a custom version should know how it compares to others |
| 160 |
|
| 161 |
env TESTGO_VERSION=go1.500-bigcorp |
| 162 |
go mod edit -go=1.499 -toolchain=none |
| 163 |
go version |
| 164 |
stdout go1.500-bigcorp |
| 165 |
|
| 166 |
go mod edit -go=1.499 -toolchain=go1.499 |
| 167 |
go version |
| 168 |
stdout go1.500-bigcorp |
| 169 |
|
| 170 |
go mod edit -go=1.500 -toolchain=none |
| 171 |
go version |
| 172 |
stdout go1.500-bigcorp |
| 173 |
|
| 174 |
go mod edit -go=1.500 -toolchain=go1.500 |
| 175 |
go version |
| 176 |
stdout go1.500-bigcorp |
| 177 |
|
| 178 |
go mod edit -go=1.501 -toolchain=none |
| 179 |
go version |
| 180 |
stdout go1.501 |
| 181 |
|
| 182 |
# If toolchain > go, we must upgrade to the indicated toolchain (not just the go version). |
| 183 |
go mod edit -go=1.499 -toolchain=go1.501 |
| 184 |
go version |
| 185 |
stdout go1.501 |
| 186 |
|
| 187 |
env TESTGO_VERSION='go1.500 (bigcorp)' |
| 188 |
go mod edit -go=1.499 -toolchain=none |
| 189 |
go version |
| 190 |
stdout 'go1.500 \(bigcorp\)' |
| 191 |
|
| 192 |
go mod edit -go=1.500 -toolchain=none |
| 193 |
go version |
| 194 |
stdout 'go1.500 \(bigcorp\)' |
| 195 |
|
| 196 |
go mod edit -go=1.501 -toolchain=none |
| 197 |
go version |
| 198 |
stdout go1.501 |
| 199 |
|
| 200 |
go mod edit -go=1.21 |
| 201 |
|
| 202 |
# avoid two-step switch, first from install target requirement, then from GOTOOLCHAIN min |
| 203 |
# instead, just jump directly to GOTOOLCHAIN min |
| 204 |
env TESTGO_VERSION=go1.2.3 |
| 205 |
env GODEBUG=toolchaintrace=1 |
| 206 |
env GOTOOLCHAIN=go1.23.0+auto |
| 207 |
! go install rsc.io/fortune/[email protected] |
| 208 |
! stderr 'switching to go1.22.9' |
| 209 |
stderr 'using go1.23.0' |
| 210 |
env GOTOOLCHAIN=auto |
| 211 |
|
| 212 |
# go install m@v and go run m@v should use the go directive from m@v, |
| 213 |
# or the go directive in go.mod, whichever is higher. |
| 214 |
env TESTGO_VERSION=go1.2.3 |
| 215 |
go mod edit -go=1.1.1 -toolchain=go1.1.1 |
| 216 |
|
| 217 |
! go install rsc.io/fortune/[email protected] |
| 218 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 219 |
! stderr 'upgrading toolchain' |
| 220 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found, but does not contain package rsc.io/fortune/nonexist' |
| 221 |
|
| 222 |
! go run rsc.io/fortune/[email protected] |
| 223 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 224 |
! stderr 'upgrading toolchain' |
| 225 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found, but does not contain package rsc.io/fortune/nonexist' |
| 226 |
|
| 227 |
go mod edit -go=1.23rc1 -toolchain=go1.1.1 |
| 228 |
|
| 229 |
! go install rsc.io/fortune/[email protected] |
| 230 |
stderr '^go: upgrading toolchain to go1.23rc1 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' |
| 231 |
! stderr 'switching to' |
| 232 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found, but does not contain package rsc.io/fortune/nonexist' |
| 233 |
|
| 234 |
! go run rsc.io/fortune/[email protected] |
| 235 |
stderr '^go: upgrading toolchain to go1.23rc1 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' |
| 236 |
! stderr 'switching to' |
| 237 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found, but does not contain package rsc.io/fortune/nonexist' |
| 238 |
|
| 239 |
go mod edit -go=1.23rc1 -toolchain=go1.998 |
| 240 |
|
| 241 |
! go install rsc.io/fortune/[email protected] |
| 242 |
stderr '^go: upgrading toolchain to go1.998 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' |
| 243 |
! stderr 'switching to' |
| 244 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found, but does not contain package rsc.io/fortune/nonexist' |
| 245 |
|
| 246 |
! go run rsc.io/fortune/[email protected] |
| 247 |
stderr '^go: upgrading toolchain to go1.998 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' |
| 248 |
! stderr 'switching to' |
| 249 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found, but does not contain package rsc.io/fortune/nonexist' |
| 250 |
|
| 251 |
go mod edit -go=1.1.1 -toolchain=go1.1.1 |
| 252 |
|
| 253 |
# go install should handle unknown flags to find m@v |
| 254 |
! go install -unknownflag rsc.io/fortune/[email protected] |
| 255 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 256 |
stderr '^flag provided but not defined: -unknownflag' |
| 257 |
|
| 258 |
! go install -unknownflag arg rsc.io/fortune/[email protected] |
| 259 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 260 |
stderr '^flag provided but not defined: -unknownflag' |
| 261 |
|
| 262 |
env GODEBUG= |
| 263 |
|
| 264 |
# go run cannot handle unknown boolean flags |
| 265 |
! go run -unknownflag rsc.io/fortune/[email protected] |
| 266 |
! stderr switching |
| 267 |
stderr '^flag provided but not defined: -unknownflag' |
| 268 |
|
| 269 |
! go run -unknownflag oops rsc.io/fortune/[email protected] |
| 270 |
! stderr switching |
| 271 |
stderr '^flag provided but not defined: -unknownflag' |
| 272 |
|
| 273 |
# go run can handle unknown flag with argument. |
| 274 |
! go run -unknown=flag rsc.io/fortune/[email protected] |
| 275 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 276 |
stderr '^flag provided but not defined: -unknown' |
| 277 |
|
| 278 |
# go install m@v should handle queries |
| 279 |
! go install rsc.io/fortune/[email protected] |
| 280 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 281 |
stderr '^go: rsc.io/fortune/[email protected]: module rsc.io/[email protected] found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist' |
| 282 |
|
| 283 |
# go run m@v should handle queries |
| 284 |
! go install rsc.io/fortune/nonexist@v0 |
| 285 |
stderr '^go: rsc.io/[email protected] requires go >= 1.21rc999; switching to go1.22.9$' |
| 286 |
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' |
| 287 |
|
| 288 |
# go install m@v should use local toolchain if not upgrading |
| 289 |
! go install rsc.io/fortune/nonexist@v1 |
| 290 |
! stderr go1.22.9 |
| 291 |
! stderr switching |
| 292 |
stderr '^go: downloading rsc.io/fortune v1.0.0$' |
| 293 |
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' |
| 294 |
|
| 295 |
# go run m@v should use local toolchain if not upgrading |
| 296 |
! go run rsc.io/fortune/nonexist@v1 |
| 297 |
! stderr go1.22.9 |
| 298 |
! stderr switching |
| 299 |
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' |