...
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
10env 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
26cp go.mod go.mod.orig
27go mod tidy
28cmp go.mod go.mod.orig
29
30go list -deps -test -f $MODFMT all
31cp stdout out-117.txt
32
33go mod edit -go=1.16
34go list -deps -test -f $MODFMT all
35cmp stdout out-117.txt
36
37
38# If we explicitly drop compatibility with 1.16, we retain fewer checksums,
39# which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode.
40
41cp go.mod.orig go.mod
42go mod tidy -compat=1.17
43cmp go.mod go.mod.orig
44
45go list -deps -test -f $MODFMT all
46cmp stdout out-117.txt
47
48go mod edit -go=1.16
49! go list -deps -test -f $MODFMT all
50stderr -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$'
51
52
53-- go.mod --
54// Module m imports packages from the same versions under Go 1.17
55// as under Go 1.16, but under 1.16 its (implicit) external test dependencies
56// are higher.
57module example.com/m
58
59go 1.17
60
61replace (
62 example.net/lazy v0.1.0 => ./lazy
63 example.net/requireincompatible v0.1.0 => ./requireincompatible
64)
65
66require example.net/lazy v0.1.0
67-- m.go --
68package m
69
70import _ "example.net/lazy"
71-- lazy/go.mod --
72// Module lazy requires example.com/retract/incompatible v1.0.0.
73//
74// When viewed from the outside it also has a transitive dependency
75// on v2.0.0+incompatible, but in lazy mode that transitive dependency
76// is pruned out.
77module example.net/lazy
78
79go 1.17
80
81exclude example.com/retract/incompatible v2.0.0+incompatible
82
83require (
84 example.com/retract/incompatible v1.0.0
85 example.net/requireincompatible v0.1.0
86)
87-- lazy/lazy.go --
88package lazy
89-- lazy/unimported/unimported.go --
90package unimported
91
92import _ "example.com/retract/incompatible"
93-- requireincompatible/go.mod --
94module example.net/requireincompatible
95
96go 1.15
97
98require example.com/retract/incompatible v2.0.0+incompatible
View as plain text