...

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# 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 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'
    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
    52go mod tidy -compat=1.17
    53! stderr .
    54cmp 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
    68go list -deps -test -f $MODFMT ./...
    69stdout '^example.net/lazy v0.1.0$'
    70
    71go mod edit -go=1.16
    72! go list -deps -test -f $MODFMT ./...
    73
    74stderr -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$'
    75
    76
    77# If we combine a Go 1.16 go.sum file...
    78go mod tidy -go=1.16
    79
    80# ...with a Go 1.17 go.mod file...
    81cp go.mod.orig go.mod
    82
    83# ...then Go 1.17 no longer works. 😞
    84! go list -deps -test -f $MODFMT all
    85stderr -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$'
    86
    87
    88# However, if we take the union of the go.sum files...
    89go list -mod=mod -deps -test all
    90cmp go.mod go.mod.orig
    91
    92# ...then Go 1.17 continues to work...
    93go list -deps -test -f $MODFMT all
    94stdout '^example\.com/retract/incompatible v1\.0\.0$'
    95
    96# ...and 1.16 also works(‽), but selects a different version for the
    97# external-test dependency.
    98go mod edit -go=1.16
    99go list -deps -test -f $MODFMT all
   100stdout '^example\.com/retract/incompatible v2\.0\.0\+incompatible$'
   101
   102
   103-- go.mod --
   104// Module m imports packages from the same versions under Go 1.17
   105// as under Go 1.16, but under 1.16 its (implicit) external test dependencies
   106// are higher.
   107module example.com/m
   108
   109go 1.17
   110
   111replace (
   112	example.net/lazy v0.1.0 => ./lazy
   113	example.net/requireincompatible v0.1.0 => ./requireincompatible
   114)
   115
   116require example.net/lazy v0.1.0
   117-- implicit.go --
   118package implicit
   119
   120import _ "example.net/lazy"
   121-- lazy/go.mod --
   122// Module lazy requires example.com/retract/incompatible v1.0.0.
   123//
   124// When viewed from the outside it also has a transitive dependency
   125// on v2.0.0+incompatible, but in lazy mode that transitive dependency
   126// is pruned out.
   127module example.net/lazy
   128
   129go 1.17
   130
   131exclude example.com/retract/incompatible v2.0.0+incompatible
   132
   133require (
   134	example.com/retract/incompatible v1.0.0
   135	example.net/requireincompatible v0.1.0
   136)
   137-- lazy/lazy.go --
   138package lazy
   139-- lazy/lazy_test.go --
   140package lazy_test
   141
   142import _ "example.com/retract/incompatible"
   143-- requireincompatible/go.mod --
   144module example.net/requireincompatible
   145
   146go 1.15
   147
   148require example.com/retract/incompatible v2.0.0+incompatible

View as plain text