1 # Create basic modules and work space.
2 env TESTGO_VERSION=go1.50
3 mkdir m1_22_0
4 go mod init -C m1_22_0
5 go mod edit -C m1_22_0 -go=1.22.0 -toolchain=go1.99.0
6 mkdir m1_22_1
7 go mod init -C m1_22_1
8 go mod edit -C m1_22_1 -go=1.22.1 -toolchain=go1.99.1
9 mkdir m1_24_rc0
10 go mod init -C m1_24_rc0
11 go mod edit -C m1_24_rc0 -go=1.24rc0 -toolchain=go1.99.2
12
13 go work init ./m1_22_0 ./m1_22_1
14 cat go.work
15 grep '^go 1.48.0$' go.work
16 ! grep toolchain go.work
17
18 # work sync with older modules should leave go 1.48.0 in the go.work.
19 go work sync
20 cat go.work
21 grep '^go 1.48.0$' go.work
22 ! grep toolchain go.work
23
24 # work sync with newer modules should update go 1.21 -> 1.22.1 and toolchain -> go1.22.9 in go.work
25 env TESTGO_VERSION=go1.21
26 env TESTGO_VERSION_SWITCH=switch
27 go work edit -go=1.21
28 grep '^go 1.21$' go.work
29 ! grep toolchain go.work
30 env GOTOOLCHAIN=local
31 ! go work sync
32 stderr '^go: cannot load module m1_22_0 listed in go.work file: m1_22_0'${/}'go.mod requires go >= 1.22.0 \(running go 1.21; GOTOOLCHAIN=local\)$'
33 stderr '^go: cannot load module m1_22_1 listed in go.work file: m1_22_1'${/}'go.mod requires go >= 1.22.1 \(running go 1.21; GOTOOLCHAIN=local\)$'
34 env GOTOOLCHAIN=auto
35 go work sync
36 stderr '^go: m1_22_1'${/}'go.mod requires go >= 1.22.1; switching to go1.22.9$'
37 grep '^go 1.22.1$' go.work
38 ! grep toolchain go.work
39
40 # work sync with newer modules should update go 1.22.1 -> 1.24rc1 and drop toolchain
41 go work edit -use=./m1_24_rc0
42 go work sync
43 stderr '^go: m1_24_rc0'${/}'go.mod requires go >= 1.24rc0; switching to go1.24rc1$'
44 cat go.work
45 grep '^go 1.24rc0$' go.work
46 ! grep toolchain go.work
47
View as plain text