...

Text file src/cmd/go/testdata/script/work_use_toolchain.txt

Documentation: cmd/go/testdata/script

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

View as plain text