1 env TESTGO_VERSION=go1.21
2 env TESTGO_VERSION_SWITCH=switch
4 # First, test 'go mod download' outside of a module.
6 # There is no go.mod file into which we can record the selected toolchain,
7 # so unfortunately these version switches won't be as reproducible as other
8 # go commands, but that's still preferable to failing entirely or downloading
9 # a module zip that we don't understand.
11 # GOTOOLCHAIN=auto should run the newer toolchain
13 go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
14 stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
17 # GOTOOLCHAIN=min+auto should run the newer toolchain
18 env GOTOOLCHAIN=go1.21+auto
19 go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
20 stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
23 # GOTOOLCHAIN=go1.21 should NOT run the newer toolchain
24 env GOTOOLCHAIN=go1.21
25 ! go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
27 stderr 'rsc.io/needgo122@v0.0.1 requires go >= 1.22'
28 stderr 'rsc.io/needgo123@v0.0.1 requires go >= 1.23'
29 stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23'
30 stderr 'requires go >= 1.23'
31 ! stderr 'requires go >= 1.21' # that's us!
34 # JSON output should be emitted exactly once,
35 # and non-JSON output should go to stderr instead of stdout.
37 go mod download -json rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
38 stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
40 stdout -count=1 '"Path": "rsc.io/needgo121",'
41 stdout -count=1 '"Path": "rsc.io/needgo122",'
42 stdout -count=1 '"Path": "rsc.io/needgo123",'
43 stdout -count=1 '"Path": "rsc.io/needall",'
45 # GOTOOLCHAIN=go1.21 should write the errors in the JSON Error fields, not to stderr.
46 env GOTOOLCHAIN=go1.21
47 ! go mod download -json rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
49 stdout -count=1 '"Error": "rsc.io/needgo122@v0.0.1 requires go .*= 1.22 \(running go 1.21; GOTOOLCHAIN=go1.21\)"'
50 stdout -count=1 '"Error": "rsc.io/needgo123@v0.0.1 requires go .*= 1.23 \(running go 1.21; GOTOOLCHAIN=go1.21\)"'
51 stdout -count=1 '"Error": "rsc.io/needall@v0.0.1 requires go .*= 1.23 \(running go 1.21; GOTOOLCHAIN=go1.21\)"'
52 ! stdout '"Error": "rsc.io/needgo121' # We can handle this one.
56 # Within a module, 'go mod download' of explicit versions should upgrade if
57 # needed to perform the download, but should not change the main module's
58 # toolchain version (because the downloaded modules are still not required by
65 go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
66 stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
68 cmp go.mod go.mod.orig
71 # However, 'go mod download' without arguments should fix up the
72 # 'go' and 'toolchain' lines to be consistent with the existing
73 # requirements in the module graph.
75 go mod edit -require=rsc.io/needall@v0.0.1
78 # If an upgrade is needed, GOTOOLCHAIN=go1.21 should cause
79 # the command to fail without changing go.mod.
81 env GOTOOLCHAIN=go1.21
83 stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23'
87 # If an upgrade is needed, GOTOOLCHAIN=auto should perform
88 # the upgrade and record the resulting toolchain version.
90 env GOTOOLCHAIN=go1.21
92 stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23'
94 cmp go.mod go.mod.final
101 -- example/go.mod.final --
106 require rsc.io/needall v0.0.1