...

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

Documentation: cmd/go/testdata/script

     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
    10env 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
    33cp go.mod go.mod.orig
    34! go mod tidy
    35stderr '^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'
    36stderr '\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
    38cmp 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
    44go mod tidy -compat=1.17
    45! stderr .
    46cmp go.mod go.mod.orig
    47
    48go list -deps -test -f $MODFMT ./...
    49stdout '^example.net/lazy v0.1.0$'
    50
    51go mod edit -go=1.16
    52! go list -deps -test -f $MODFMT ./...
    53
    54stderr -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...
    58go mod tidy -go=1.16
    59
    60# ...with a Go 1.17 go.mod file...
    61cp go.mod.orig go.mod
    62
    63# ...then Go 1.17 no longer works. 😞
    64! go list -deps -test -f $MODFMT all
    65stderr -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...
    69go list -mod=mod -deps -test all
    70cmp go.mod go.mod.orig
    71
    72# ...then Go 1.17 continues to work...
    73go list -deps -test -f $MODFMT all
    74stdout '^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.
    78go mod edit -go=1.16
    79go list -deps -test -f $MODFMT all
    80stdout '^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.
    87module example.com/m
    88
    89go 1.17
    90
    91replace (
    92	example.net/lazy v0.1.0 => ./lazy
    93	example.net/requireincompatible v0.1.0 => ./requireincompatible
    94)
    95
    96require example.net/lazy v0.1.0
    97-- implicit.go --
    98package implicit
    99
   100import _ "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.
   107module example.net/lazy
   108
   109go 1.17
   110
   111exclude example.com/retract/incompatible v2.0.0+incompatible
   112
   113require (
   114	example.com/retract/incompatible v1.0.0
   115	example.net/requireincompatible v0.1.0
   116)
   117-- lazy/lazy.go --
   118package lazy
   119-- lazy/lazy_test.go --
   120package lazy_test
   121
   122import _ "example.com/retract/incompatible"
   123-- requireincompatible/go.mod --
   124module example.net/requireincompatible
   125
   126go 1.15
   127
   128require example.com/retract/incompatible v2.0.0+incompatible

View as plain text