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

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

View as plain text