...

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

Documentation: cmd/go/testdata/script

     1env TESTGO_VERSION=go1.21
     2env TESTGO_VERSION_SWITCH=switch
     3
     4# First, test 'go mod download' outside of a module.
     5#
     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.
    10
    11# GOTOOLCHAIN=auto should run the newer toolchain
    12env GOTOOLCHAIN=auto
    13go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
    14stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
    15! stderr '\(running'
    16
    17# GOTOOLCHAIN=min+auto should run the newer toolchain
    18env GOTOOLCHAIN=go1.21+auto
    19go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
    20stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
    21! stderr '\(running'
    22
    23# GOTOOLCHAIN=go1.21 should NOT run the newer toolchain
    24env GOTOOLCHAIN=go1.21
    25! go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
    26! stderr switching
    27stderr 'rsc.io/needgo122@v0.0.1 requires go >= 1.22'
    28stderr 'rsc.io/needgo123@v0.0.1 requires go >= 1.23'
    29stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23'
    30stderr 'requires go >= 1.23'
    31! stderr 'requires go >= 1.21' # that's us!
    32
    33
    34# JSON output should be emitted exactly once,
    35# and non-JSON output should go to stderr instead of stdout.
    36env GOTOOLCHAIN=auto
    37go mod download -json rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
    38stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
    39! stderr '\(running'
    40stdout -count=1 '"Path": "rsc.io/needgo121",'
    41stdout -count=1 '"Path": "rsc.io/needgo122",'
    42stdout -count=1 '"Path": "rsc.io/needgo123",'
    43stdout -count=1 '"Path": "rsc.io/needall",'
    44
    45# GOTOOLCHAIN=go1.21 should write the errors in the JSON Error fields, not to stderr.
    46env GOTOOLCHAIN=go1.21
    47! go mod download -json rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
    48! stderr switching
    49stdout -count=1 '"Error": "rsc.io/needgo122@v0.0.1 requires go .*= 1.22 \(running go 1.21; GOTOOLCHAIN=go1.21\)"'
    50stdout -count=1 '"Error": "rsc.io/needgo123@v0.0.1 requires go .*= 1.23 \(running go 1.21; GOTOOLCHAIN=go1.21\)"'
    51stdout -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.
    53! stderr .
    54
    55
    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
    59# the main module).
    60
    61cd example
    62cp go.mod go.mod.orig
    63
    64env GOTOOLCHAIN=auto
    65go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest
    66stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
    67! stderr '\(running'
    68cmp go.mod go.mod.orig
    69
    70
    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.
    74
    75go mod edit -require=rsc.io/needall@v0.0.1
    76cp go.mod go.mod.121
    77
    78# If an upgrade is needed, GOTOOLCHAIN=go1.21 should cause
    79# the command to fail without changing go.mod.
    80
    81env GOTOOLCHAIN=go1.21
    82! go mod download
    83stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23'
    84! stderr switching
    85cmp go.mod go.mod.121
    86
    87# If an upgrade is needed, GOTOOLCHAIN=auto should perform
    88# the upgrade and record the resulting toolchain version.
    89
    90env GOTOOLCHAIN=auto
    91go mod download
    92stderr '^go: module rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$'
    93cmp go.mod go.mod.final
    94
    95
    96-- example/go.mod --
    97module example
    98
    99go 1.21
   100-- example/go.mod.final --
   101module example
   102
   103go 1.23
   104
   105toolchain go1.23.9
   106
   107require rsc.io/needall v0.0.1

View as plain text