1
2 # Create basic modules and work space.
3 # Note that toolchain lines in modules should be completely ignored.
4 env TESTGO_VERSION=go1.50
5 mkdir m1_22_0
6 go mod init -C m1_22_0
7 go mod edit -C m1_22_0 -go=1.22.0 -toolchain=go1.99.0
8
9 # work init writes the current Go version to the go line
10 go work init
11 grep '^go 1.50$' go.work
12 ! grep toolchain go.work
13
14 # work init with older modules should leave go 1.50 in the go.work.
15 rm go.work
16 go work init ./m1_22_0
17 grep '^go 1.50$' go.work
18 ! grep toolchain go.work
19
20 # work init with newer modules should bump go,
21 # including updating to a newer toolchain as needed.
22 # Because work init writes the current toolchain as the go version,
23 # it writes the bumped go version, not the max of the used modules.
24 env TESTGO_VERSION=go1.21
25 env TESTGO_VERSION_SWITCH=switch
26 rm go.work
27 env GOTOOLCHAIN=local
28 ! go work init ./m1_22_0
29 stderr '^go: m1_22_0'${/}'go.mod requires go >= 1.22.0 \(running go 1.21; GOTOOLCHAIN=local\)$'
30 env GOTOOLCHAIN=auto
31 go work init ./m1_22_0
32 stderr '^go: m1_22_0'${/}'go.mod requires go >= 1.22.0; switching to go1.22.9$'
33 cat go.work
34 grep '^go 1.22.9$' go.work
35 ! grep toolchain go.work
36
View as plain text