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 # TODO(#46160): -count=1 instead of -count=2.
51 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$'
52
53
54 -- go.mod --
55 // Module m imports packages from the same versions under Go 1.17
56 // as under Go 1.16, but under 1.16 its (implicit) external test dependencies
57 // are higher.
58 module example.com/m
59
60 go 1.17
61
62 replace (
63 example.net/lazy v0.1.0 => ./lazy
64 example.net/requireincompatible v0.1.0 => ./requireincompatible
65 )
66
67 require example.net/lazy v0.1.0
68 -- m.go --
69 package m
70
71 import _ "example.net/lazy"
72 -- lazy/go.mod --
73 // Module lazy requires example.com/retract/incompatible v1.0.0.
74 //
75 // When viewed from the outside it also has a transitive dependency
76 // on v2.0.0+incompatible, but in lazy mode that transitive dependency
77 // is pruned out.
78 module example.net/lazy
79
80 go 1.17
81
82 exclude example.com/retract/incompatible v2.0.0+incompatible
83
84 require (
85 example.com/retract/incompatible v1.0.0
86 example.net/requireincompatible v0.1.0
87 )
88 -- lazy/lazy.go --
89 package lazy
90 -- lazy/unimported/unimported.go --
91 package unimported
92
93 import _ "example.com/retract/incompatible"
94 -- requireincompatible/go.mod --
95 module example.net/requireincompatible
96
97 go 1.15
98
99 require example.com/retract/incompatible v2.0.0+incompatible
100
View as plain text