...

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

Documentation: cmd/go/testdata/script

     1# This test verifies that 'go get' and 'go mod tidy' switch to a newer toolchain
     2# if needed to process newly-reolved imports.
     3
     4env TESTGO_VERSION=go1.21.0
     5env TESTGO_VERSION_SWITCH=switch
     6
     7cp go.mod go.mod.orig
     8
     9# tidy reports needing 1.22.0 for b1
    10env GOTOOLCHAIN=local
    11! go mod tidy
    12stderr '^go: example imports\n\texample.net/b: module ./b1 requires go >= 1.22.0 \(running go 1.21.0; GOTOOLCHAIN=local\)$'
    13env GOTOOLCHAIN=auto
    14go mod tidy
    15
    16cmp stderr tidy-stderr.want
    17cmp go.mod go.mod.tidy
    18
    19cp go.mod.orig go.mod
    20env GOTOOLCHAIN=local
    21! go get -v .
    22stderr '^go: example.net/b@v0.1.0: module ./b1 requires go >= 1.22.0 \(running go 1.21.0; GOTOOLCHAIN=local\)$'
    23env GOTOOLCHAIN=auto
    24go get -v .
    25cmp stderr get-v-stderr.want
    26cmp go.mod go.mod.tidy
    27
    28cp go.mod.orig go.mod
    29env GOTOOLCHAIN=local
    30! go get -u -v .
    31stderr '^go: example.net/a@v0.2.0: module ./a2 requires go >= 1.22.0 \(running go 1.21.0; GOTOOLCHAIN=local\)$'
    32env GOTOOLCHAIN=auto
    33go get -u -v .
    34cmp stderr get-u-v-stderr.want
    35cmp go.mod go.mod.upgraded
    36
    37-- tidy-stderr.want --
    38go: found example.net/b in example.net/b v0.1.0
    39go: module ./b1 requires go >= 1.22.0; switching to go1.22.9
    40go: found example.net/b in example.net/b v0.1.0
    41go: found example.net/c in example.net/c v0.1.0
    42-- get-v-stderr.want --
    43go: trying upgrade to example.net/b@v0.1.0
    44go: module ./b1 requires go >= 1.22.0; switching to go1.22.9
    45go: trying upgrade to example.net/b@v0.1.0
    46go: accepting indirect upgrade from go@1.20 to 1.22.0
    47go: trying upgrade to example.net/c@v0.1.0
    48go: upgraded go 1.20 => 1.22.0
    49go: added toolchain go1.22.9
    50go: added example.net/b v0.1.0
    51go: added example.net/c v0.1.0
    52go: added example.net/d v0.1.0
    53-- get-u-v-stderr.want --
    54go: trying upgrade to example.net/a@v0.2.0
    55go: trying upgrade to example.net/b@v0.1.0
    56go: module ./a2 requires go >= 1.22.0; switching to go1.22.9
    57go: trying upgrade to example.net/a@v0.2.0
    58go: trying upgrade to example.net/b@v0.1.0
    59go: accepting indirect upgrade from go@1.20 to 1.22.0
    60go: trying upgrade to example.net/c@v0.1.0
    61go: trying upgrade to example.net/d@v0.2.0
    62go: module ./d2 requires go >= 1.23.0; switching to go1.23.9
    63go: trying upgrade to example.net/a@v0.2.0
    64go: trying upgrade to example.net/b@v0.1.0
    65go: accepting indirect upgrade from go@1.20 to 1.22.0
    66go: trying upgrade to example.net/c@v0.1.0
    67go: trying upgrade to example.net/d@v0.2.0
    68go: accepting indirect upgrade from go@1.22.0 to 1.23.0
    69go: upgraded go 1.20 => 1.23.0
    70go: added toolchain go1.23.9
    71go: upgraded example.net/a v0.1.0 => v0.2.0
    72go: added example.net/b v0.1.0
    73go: added example.net/c v0.1.0
    74go: added example.net/d v0.2.0
    75-- go.mod --
    76module example
    77
    78go 1.20
    79
    80require example.net/a v0.1.0
    81
    82replace (
    83	example.net/a v0.1.0 => ./a1
    84	example.net/a v0.2.0 => ./a2
    85	example.net/b v0.1.0 => ./b1
    86	example.net/c v0.1.0 => ./c1
    87	example.net/d v0.1.0 => ./d1
    88	example.net/d v0.2.0 => ./d2
    89)
    90-- go.mod.tidy --
    91module example
    92
    93go 1.22.0
    94
    95toolchain go1.22.9
    96
    97require (
    98	example.net/a v0.1.0
    99	example.net/b v0.1.0
   100)
   101
   102require (
   103	example.net/c v0.1.0 // indirect
   104	example.net/d v0.1.0 // indirect
   105)
   106
   107replace (
   108	example.net/a v0.1.0 => ./a1
   109	example.net/a v0.2.0 => ./a2
   110	example.net/b v0.1.0 => ./b1
   111	example.net/c v0.1.0 => ./c1
   112	example.net/d v0.1.0 => ./d1
   113	example.net/d v0.2.0 => ./d2
   114)
   115-- go.mod.upgraded --
   116module example
   117
   118go 1.23.0
   119
   120toolchain go1.23.9
   121
   122require (
   123	example.net/a v0.2.0
   124	example.net/b v0.1.0
   125)
   126
   127require (
   128	example.net/c v0.1.0 // indirect
   129	example.net/d v0.2.0 // indirect
   130)
   131
   132replace (
   133	example.net/a v0.1.0 => ./a1
   134	example.net/a v0.2.0 => ./a2
   135	example.net/b v0.1.0 => ./b1
   136	example.net/c v0.1.0 => ./c1
   137	example.net/d v0.1.0 => ./d1
   138	example.net/d v0.2.0 => ./d2
   139)
   140-- example.go --
   141package example
   142
   143import (
   144	_ "example.net/a"
   145	_ "example.net/b"
   146)
   147-- a1/go.mod --
   148module example.net/a
   149
   150go 1.20
   151-- a1/a.go --
   152package a
   153-- a2/go.mod --
   154module example.net/a
   155
   156go 1.22.0
   157
   158toolchain go1.23.0
   159-- a2/a.go --
   160package a
   161-- b1/go.mod --
   162module example.net/b
   163
   164go 1.22.0
   165
   166toolchain go1.23.0
   167-- b1/b.go --
   168package b
   169
   170import _ "example.net/c"  // Note: module b is intentionally untidy, as if due to a bad git merge
   171-- c1/go.mod --
   172module example.net/c
   173
   174go 1.22.0
   175
   176require example.net/d v0.1.0
   177-- c1/c.go --
   178package c
   179
   180import _ "example.net/d"
   181-- d1/go.mod --
   182module example.net/d
   183
   184go 1.22.0
   185-- d1/d.go --
   186package d
   187-- d2/go.mod --
   188module example.net/d
   189
   190go 1.23.0
   191-- d2/d.go --
   192package d

View as plain text