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

     1  # https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by
     2  # default preserve enough checksums for the module to be used by Go 1.16.
     3  #
     4  # We don't have a copy of Go 1.16 handy, but we can simulate it by editing the
     5  # 'go' version in the go.mod file to 1.16, without actually updating the
     6  # requirements to match.
     7  
     8  [short] skip
     9  
    10  env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}'
    11  
    12  
    13  # For this module, Go 1.17 prunes out a (transitive and otherwise-irrelevant)
    14  # requirement on a retracted higher version of a dependency.
    15  # However, when Go 1.16 reads the same requirements from the go.mod file,
    16  # it does not prune out that requirement, and selects the retracted version.
    17  #
    18  # The Go 1.16 module graph looks like:
    19  #
    20  # m ---- lazy v0.1.0 ---- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible
    21  # |        |
    22  # + -------+------------- incompatible v1.0.0
    23  #
    24  # The Go 1.17 module graph is the same except that the dependencies of
    25  # requireincompatible are pruned out (because the module that requires
    26  # it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to
    27  # the main module).
    28  
    29  
    30  # 'go mod tidy' should by default diagnose the difference in dependencies as an
    31  # error, with useful suggestions about how to resolve it.
    32  
    33  cp go.mod go.mod.orig
    34  ! go mod tidy
    35  stderr '^go: example\.com/m imports\n\texample\.net/lazy imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n'
    36  stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1\.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
    37  
    38  cmp go.mod go.mod.orig
    39  
    40  # Make sure that -diff behaves the same as tidy.
    41  [exec:patch] cp go.mod.orig go.mod
    42  [exec:patch] ! exists go.sum
    43  [exec:patch] ! go mod tidy -diff
    44  [exec:patch] ! stdout .
    45  [exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/lazy imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n'
    46  [exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1\.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
    47  
    48  # The suggested '-compat' flag to ignore differences should silence the error
    49  # and leave go.mod unchanged, resulting in checksum errors when Go 1.16 tries
    50  # to load a module pruned out by Go 1.17.
    51  
    52  go mod tidy -compat=1.17
    53  ! stderr .
    54  cmp go.mod go.mod.orig
    55  
    56  # Make sure that -diff behaves the same as tidy.
    57  [exec:patch] mv go.mod go.mod.tidyResult
    58  [exec:patch] mv go.sum go.sum.tidyResult
    59  [exec:patch] cp go.mod.orig go.mod
    60  [exec:patch] ! go mod tidy -compat=1.17 -diff
    61  [exec:patch] cp stdout diff.patch
    62  [exec:patch] exec patch -p1 -i diff.patch
    63  [exec:patch] go mod tidy -compat=1.17 -diff
    64  [exec:patch] ! stdout .
    65  [exec:patch] cmp go.mod go.mod.tidyResult
    66  [exec:patch] cmp go.sum go.sum.tidyResult
    67  
    68  go mod edit -go=1.16
    69  ! go list -f $MODFMT -deps ./...
    70  stderr -count=1 '^go: example\.net/lazy@v0\.1\.0 requires\n\texample\.net/requireincompatible@v0\.1\.0 requires\n\texample\.com/retract/incompatible@v2\.0\.0\+incompatible: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/retract/incompatible$'
    71  
    72  
    73  # There are two ways for the module author to bring the two into alignment.
    74  # One is to *explicitly* 'exclude' the version that is already *implicitly*
    75  # pruned out under 1.17.
    76  
    77  go mod edit -exclude=example.com/retract/incompatible@v2.0.0+incompatible
    78  go list -f $MODFMT -deps ./...
    79  stdout '^example.com/retract/incompatible v1\.0\.0$'
    80  ! stdout 'v2\.0\.0'
    81  
    82  
    83  # The other is to explicitly upgrade the version required under Go 1.17
    84  # to match the version selected by Go 1.16. The commands suggested by
    85  # 'go mod tidy' should do exactly that.
    86  
    87  cp go.mod.orig go.mod
    88  
    89  go mod tidy -go=1.16
    90  go list -f $MODFMT -deps ./...
    91  stdout '^example.com/retract/incompatible v2\.0\.0\+incompatible$'
    92  ! stdout 'v1\.0\.0'
    93  
    94  go mod tidy -go=1.17
    95  go list -f $MODFMT -deps ./...
    96  stdout '^example.com/retract/incompatible v2\.0\.0\+incompatible$'
    97  ! stdout 'v1\.0\.0'
    98  
    99  go mod edit -go=1.16
   100  go list -f $MODFMT -deps ./...
   101  stdout '^example.com/retract/incompatible v2\.0\.0\+incompatible$'
   102  ! stdout 'v1\.0\.0'
   103  
   104  
   105  -- go.mod --
   106  // Module m indirectly imports a package from
   107  // example.com/retract/incompatible. Its selected version of
   108  // that module is lower under Go 1.17 semantics than under Go 1.16.
   109  module example.com/m
   110  
   111  go 1.17
   112  
   113  replace (
   114  	example.net/lazy v0.1.0 => ./lazy
   115  	example.net/requireincompatible v0.1.0 => ./requireincompatible
   116  )
   117  
   118  require example.net/lazy v0.1.0
   119  
   120  require example.com/retract/incompatible v1.0.0 // indirect
   121  -- incompatible.go --
   122  package incompatible
   123  
   124  import _ "example.net/lazy"
   125  
   126  -- lazy/go.mod --
   127  // Module lazy requires example.com/retract/incompatible v1.0.0.
   128  //
   129  // When viewed from the outside it also has a transitive dependency
   130  // on v2.0.0+incompatible, but in lazy mode that transitive dependency
   131  // is pruned out.
   132  module example.net/lazy
   133  
   134  go 1.17
   135  
   136  exclude example.com/retract/incompatible v2.0.0+incompatible
   137  
   138  require (
   139  	example.com/retract/incompatible v1.0.0
   140  	example.net/requireincompatible v0.1.0
   141  )
   142  -- lazy/lazy.go --
   143  package lazy
   144  
   145  import _ "example.com/retract/incompatible"
   146  
   147  -- requireincompatible/go.mod --
   148  module example.net/requireincompatible
   149  
   150  go 1.15
   151  
   152  require example.com/retract/incompatible v2.0.0+incompatible
   153  

View as plain text