|
| 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 | +cp go.mod go.mod.orig |
| 31 | +go mod tidy |
| 32 | +cmp go.mod go.mod.orig |
| 33 | + |
| 34 | +go list -deps -test -f $MODFMT all |
| 35 | +stdout '^example\.com/retract/incompatible v1\.0\.0$' |
| 36 | + |
| 37 | +go mod edit -go=1.16 |
| 38 | +! go list -deps -test -f $MODFMT all |
| 39 | + |
| 40 | + # TODO(#46160): -count=1 instead of -count=2. |
| 41 | +stderr -count=2 '^go: example\.net/lazy@v0\.1\.0 requires\n\texample\.com/retract/incompatible@v1\.0\.0: missing go\.sum entry; to add it:\n\tgo mod download example\.com/retract/incompatible$' |
| 42 | + |
| 43 | + |
| 44 | +# If we combine a Go 1.16 go.sum file... |
| 45 | +go mod tidy -go=1.16 |
| 46 | + |
| 47 | +# ...with a Go 1.17 go.mod file... |
| 48 | +cp go.mod.orig go.mod |
| 49 | + |
| 50 | +# ...then Go 1.17 no longer works. 😞 |
| 51 | +! go list -deps -test -f $MODFMT all |
| 52 | +stderr -count=1 '^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$' |
| 53 | + |
| 54 | + |
| 55 | +# However, if we take the union of the go.sum files... |
| 56 | +go list -mod=mod -deps -test all |
| 57 | +cmp go.mod go.mod.orig |
| 58 | + |
| 59 | +# ...then Go 1.17 continues to work... |
| 60 | +go list -deps -test -f $MODFMT all |
| 61 | +stdout '^example\.com/retract/incompatible v1\.0\.0$' |
| 62 | + |
| 63 | +# ...and 1.16 also works(‽), but selects a different version for the |
| 64 | +# external-test dependency. |
| 65 | +go mod edit -go=1.16 |
| 66 | +go list -deps -test -f $MODFMT all |
| 67 | +stdout '^example\.com/retract/incompatible v2\.0\.0\+incompatible$' |
| 68 | + |
| 69 | + |
| 70 | +# TODO(#46100): In compatibility mode, should we reject the above difference as |
| 71 | +# incompatible, or save checksums for both possible versions of the test |
| 72 | +# dependency? |
| 73 | + |
| 74 | + |
| 75 | +-- go.mod -- |
| 76 | +// Module m imports packages from the same versions under Go 1.17 |
| 77 | +// as under Go 1.16, but under 1.16 its (implicit) external test dependencies |
| 78 | +// are higher. |
| 79 | +module example.com/m |
| 80 | + |
| 81 | +go 1.17 |
| 82 | + |
| 83 | +replace ( |
| 84 | + example.net/lazy v0.1.0 => ./lazy |
| 85 | + example.net/requireincompatible v0.1.0 => ./requireincompatible |
| 86 | +) |
| 87 | + |
| 88 | +require example.net/lazy v0.1.0 |
| 89 | +-- implicit.go -- |
| 90 | +package implicit |
| 91 | + |
| 92 | +import _ "example.net/lazy" |
| 93 | +-- lazy/go.mod -- |
| 94 | +// Module lazy requires example.com/retract/incompatible v1.0.0. |
| 95 | +// |
| 96 | +// When viewed from the outside it also has a transitive dependency |
| 97 | +// on v2.0.0+incompatible, but in lazy mode that transitive dependency |
| 98 | +// is pruned out. |
| 99 | +module example.net/lazy |
| 100 | + |
| 101 | +go 1.17 |
| 102 | + |
| 103 | +exclude example.com/retract/incompatible v2.0.0+incompatible |
| 104 | + |
| 105 | +require ( |
| 106 | + example.com/retract/incompatible v1.0.0 |
| 107 | + example.net/requireincompatible v0.1.0 |
| 108 | +) |
| 109 | +-- lazy/lazy.go -- |
| 110 | +package lazy |
| 111 | +-- lazy/lazy_test.go -- |
| 112 | +package lazy_test |
| 113 | + |
| 114 | +import _ "example.com/retract/incompatible" |
| 115 | +-- requireincompatible/go.mod -- |
| 116 | +module example.net/requireincompatible |
| 117 | + |
| 118 | +go 1.15 |
| 119 | + |
| 120 | +require example.com/retract/incompatible v2.0.0+incompatible |
0 commit comments