Text file src/cmd/go/testdata/script/mod_tidy_compat_implicit.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.16 selects the same versions of all explicit dependencies
    14  # as Go 1.17 does. However, Go 1.16 selects a higher version of an *implicit*
    15  # dependency, imported by a test of one of the (external) imported packages.
    16  # As a result, Go 1.16 also needs checksums for the module sources for that higher
    17  # version.
    18  #
    19  # The Go 1.16 module graph looks like:
    20  #
    21  # m ---- lazy v0.1.0 ---- incompatible v1.0.0
    22  #         |
    23  #         + ------------- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible
    24  #
    25  # The Go 1.17 module graph is the same except that the dependencies of
    26  # requireincompatible are pruned out (because the module that requires
    27  # it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to
    28  # the main module).
    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 tested by\n\texample\.net/lazy.test 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  # The suggested '-compat' flag to ignore differences should silence the error
    41  # and leave go.mod unchanged, resulting in checksum errors when Go 1.16 tries
    42  # to load a module pruned out by Go 1.17.
    43  
    44  go mod tidy -compat=1.17
    45  ! stderr .
    46  cmp go.mod go.mod.orig
    47  
    48  go list -deps -test -f $MODFMT ./...
    49  stdout '^example.net/lazy v0.1.0$'
    50  
    51  go mod edit -go=1.16
    52  ! go list -deps -test -f $MODFMT ./...
    53  
    54  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$'
    55  
    56  
    57  # If we combine a Go 1.16 go.sum file...
    58  go mod tidy -go=1.16
    59  
    60  # ...with a Go 1.17 go.mod file...
    61  cp go.mod.orig go.mod
    62  
    63  # ...then Go 1.17 no longer works. 😞
    64  ! go list -deps -test -f $MODFMT all
    65  stderr -count=1 '^go: can''t load test package: lazy[/\\]lazy_test.go:3:8: missing go\.sum entry for module providing package example\.com/retract/incompatible \(imported by example\.net/lazy\); to add:\n\tgo get -t example.net/lazy@v0\.1\.0$'
    66  
    67  
    68  # However, if we take the union of the go.sum files...
    69  go list -mod=mod -deps -test all
    70  cmp go.mod go.mod.orig
    71  
    72  # ...then Go 1.17 continues to work...
    73  go list -deps -test -f $MODFMT all
    74  stdout '^example\.com/retract/incompatible v1\.0\.0$'
    75  
    76  # ...and 1.16 also works(‽), but selects a different version for the
    77  # external-test dependency.
    78  go mod edit -go=1.16
    79  go list -deps -test -f $MODFMT all
    80  stdout '^example\.com/retract/incompatible v2\.0\.0\+incompatible$'
    81  
    82  
    83  -- go.mod --
    84  // Module m imports packages from the same versions under Go 1.17
    85  // as under Go 1.16, but under 1.16 its (implicit) external test dependencies
    86  // are higher.
    87  module example.com/m
    88  
    89  go 1.17
    90  
    91  replace (
    92  	example.net/lazy v0.1.0 => ./lazy
    93  	example.net/requireincompatible v0.1.0 => ./requireincompatible
    94  )
    95  
    96  require example.net/lazy v0.1.0
    97  -- implicit.go --
    98  package implicit
    99  
   100  import _ "example.net/lazy"
   101  -- lazy/go.mod --
   102  // Module lazy requires example.com/retract/incompatible v1.0.0.
   103  //
   104  // When viewed from the outside it also has a transitive dependency
   105  // on v2.0.0+incompatible, but in lazy mode that transitive dependency
   106  // is pruned out.
   107  module example.net/lazy
   108  
   109  go 1.17
   110  
   111  exclude example.com/retract/incompatible v2.0.0+incompatible
   112  
   113  require (
   114  	example.com/retract/incompatible v1.0.0
   115  	example.net/requireincompatible v0.1.0
   116  )
   117  -- lazy/lazy.go --
   118  package lazy
   119  -- lazy/lazy_test.go --
   120  package lazy_test
   121  
   122  import _ "example.com/retract/incompatible"
   123  -- requireincompatible/go.mod --
   124  module example.net/requireincompatible
   125  
   126  go 1.15
   127  
   128  require example.com/retract/incompatible v2.0.0+incompatible
   129  

View as plain text