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
10 env 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
26 cp go.mod go.mod.orig
27 go mod tidy
28 cmp go.mod go.mod.orig
29
30 go list -deps -test -f $MODFMT all
31 cp stdout out-117.txt
32
33 go mod edit -go=1.16
34 go list -deps -test -f $MODFMT all
35 cmp 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
41 cp go.mod.orig go.mod
42 go mod tidy -compat=1.17
43 cmp go.mod go.mod.orig
44
45 go list -deps -test -f $MODFMT all
46 cmp stdout out-117.txt
47
48 go mod edit -go=1.16
49 ! go list -deps -test -f $MODFMT all
50 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$'
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.
57 module example.com/m
58
59 go 1.17
60
61 replace (
62 example.net/lazy v0.1.0 => ./lazy
63 example.net/requireincompatible v0.1.0 => ./requireincompatible
64 )
65
66 require example.net/lazy v0.1.0
67 -- m.go --
68 package m
69
70 import _ "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.
77 module example.net/lazy
78
79 go 1.17
80
81 exclude example.com/retract/incompatible v2.0.0+incompatible
82
83 require (
84 example.com/retract/incompatible v1.0.0
85 example.net/requireincompatible v0.1.0
86 )
87 -- lazy/lazy.go --
88 package lazy
89 -- lazy/unimported/unimported.go --
90 package unimported
91
92 import _ "example.com/retract/incompatible"
93 -- requireincompatible/go.mod --
94 module example.net/requireincompatible
95
96 go 1.15
97
98 require example.com/retract/incompatible v2.0.0+incompatible
99
View as plain text