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

     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
    14  grep '^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.
    18  go work use ./m1_22_0
    19  grep '^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.
    24  env TESTGO_VERSION=go1.21
    25  env TESTGO_VERSION_SWITCH=switch
    26  rm go.work
    27  go work init
    28  env GOTOOLCHAIN=local
    29  ! go work use ./m1_22_0
    30  stderr '^go: m1_22_0'${/}'go.mod requires go >= 1.22.0 \(running go 1.21; GOTOOLCHAIN=local\)$'
    31  env GOTOOLCHAIN=auto
    32  go work use ./m1_22_0
    33  stderr '^go: m1_22_0'${/}'go.mod requires go >= 1.22.0; switching to go1.22.9$'
    34  grep '^go 1.22.0$' go.work
    35  grep '^toolchain go1.22.9$' go.work
    36  
    37  # work use with an even newer module should bump go again.
    38  go work use ./m1_22_1
    39  ! stderr switching
    40  grep '^go 1.22.1$' go.work
    41  grep '^toolchain go1.22.9$' go.work  # unchanged
    42  
    43  # work use with an even newer module should bump go and toolchain again.
    44  env GOTOOLCHAIN=go1.22.9
    45  ! go work use ./m1_24_rc0
    46  stderr '^go: m1_24_rc0'${/}'go.mod requires go >= 1.24rc0 \(running go 1.22.9; GOTOOLCHAIN=go1.22.9\)$'
    47  env GOTOOLCHAIN=auto
    48  go work use ./m1_24_rc0
    49  stderr '^go: m1_24_rc0'${/}'go.mod requires go >= 1.24rc0; switching to go1.24rc1$'
    50  grep '^go 1.24rc0$' go.work
    51  grep '^toolchain go1.24rc1$' go.work
    52  

View as plain text