Text file src/cmd/go/testdata/script/mod_tidy_compat_irrelevant.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  # This module selects the same versions in Go 1.16 and 1.17 for all modules
    14  # that provide packages (or test dependencies of packages) imported by the
    15  # main module. However, in Go 1.16 it selects a higher version of a
    16  # transitive module dependency that is not otherwise relevant to the main module.
    17  # As a result, Go 1.16 needs an additional checksum for the go.mod file of
    18  # that irrelevant dependency.
    19  #
    20  # The Go 1.16 module graph looks like:
    21  #
    22  # m ---- lazy v0.1.0 ---- incompatible v1.0.0
    23  #         |
    24  #         + ------------- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible
    25  
    26  cp go.mod go.mod.orig
    27  go mod tidy
    28  cmp go.mod go.mod.orig
    29  
    30  # Make sure that -diff behaves the same as tidy.
    31  [exec:patch] mv go.mod go.mod.tidyResult
    32  [exec:patch] mv go.sum go.sum.tidyResult
    33  [exec:patch] cp go.mod.orig go.mod
    34  [exec:patch] ! go mod tidy -diff
    35  [exec:patch] cp stdout diff.patch
    36  [exec:patch] exec patch -p1 -i diff.patch
    37  [exec:patch] go mod tidy -diff
    38  [exec:patch] ! stdout .
    39  [exec:patch] cmp go.mod go.mod.tidyResult
    40  [exec:patch] cmp go.sum go.sum.tidyResult
    41  
    42  go list -deps -test -f $MODFMT all
    43  cp stdout out-117.txt
    44  
    45  go mod edit -go=1.16
    46  go list -deps -test -f $MODFMT all
    47  cmp stdout out-117.txt
    48  
    49  
    50  # If we explicitly drop compatibility with 1.16, we retain fewer checksums,
    51  # which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode.
    52  
    53  cp go.mod.orig go.mod
    54  go mod tidy -compat=1.17
    55  cmp go.mod go.mod.orig
    56  
    57  # Make sure that -diff behaves the same as tidy.
    58  [exec:patch] cp go.mod.orig go.mod
    59  [exec:patch] rm go.sum
    60  [exec:patch] go mod tidy -compat=1.17 -diff
    61  [exec:patch] ! stdout .
    62  
    63  go list -deps -test -f $MODFMT all
    64  cmp stdout out-117.txt
    65  
    66  go mod edit -go=1.16
    67  ! go list -deps -test -f $MODFMT all
    68  stderr -count=1 '^go: example.net/lazy@v0.1.0 requires\n\texample.com/retract/incompatible@v1.0.0: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/retract/incompatible$'
    69  
    70  
    71  -- go.mod --
    72  // Module m imports packages from the same versions under Go 1.17
    73  // as under Go 1.16, but under 1.16 its (implicit) external test dependencies
    74  // are higher.
    75  module example.com/m
    76  
    77  go 1.17
    78  
    79  replace (
    80  	example.net/lazy v0.1.0 => ./lazy
    81  	example.net/requireincompatible v0.1.0 => ./requireincompatible
    82  )
    83  
    84  require example.net/lazy v0.1.0
    85  -- m.go --
    86  package m
    87  
    88  import _ "example.net/lazy"
    89  -- lazy/go.mod --
    90  // Module lazy requires example.com/retract/incompatible v1.0.0.
    91  //
    92  // When viewed from the outside it also has a transitive dependency
    93  // on v2.0.0+incompatible, but in lazy mode that transitive dependency
    94  // is pruned out.
    95  module example.net/lazy
    96  
    97  go 1.17
    98  
    99  exclude example.com/retract/incompatible v2.0.0+incompatible
   100  
   101  require (
   102  	example.com/retract/incompatible v1.0.0
   103  	example.net/requireincompatible v0.1.0
   104  )
   105  -- lazy/lazy.go --
   106  package lazy
   107  -- lazy/unimported/unimported.go --
   108  package unimported
   109  
   110  import _ "example.com/retract/incompatible"
   111  -- requireincompatible/go.mod --
   112  module example.net/requireincompatible
   113  
   114  go 1.15
   115  
   116  require example.com/retract/incompatible v2.0.0+incompatible
   117  

View as plain text