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 has the same module dependency graph in Go 1.16 as in Go 1.17,
14 # but in 1.16 requires (checksums for) additional (irrelevant) go.mod files.
15 #
16 # The module graph under both versions looks like:
17 #
18 # m ---- example.com/version v1.1.0
19 # |
20 # + ---- example.net/lazy v0.1.0 ---- example.com/version v1.0.1
21 #
22 # Go 1.17 avoids loading the go.mod file for example.com/version v1.0.1
23 # (because it is lower than the version explicitly required by m,
24 # and the module that requires it — m — specifies 'go 1.17').
25 #
26 # That go.mod file happens not to affect the final 1.16 module graph anyway,
27 # so the pruned graph is equivalent to the unpruned one.
28
29 cp go.mod go.mod.orig
30 go mod tidy
31 cmp go.mod go.mod.orig
32
33 # Make sure that -diff behaves the same as tidy.
34 [exec:patch] mv go.mod go.mod.tidyResult
35 [exec:patch] mv go.sum go.sum.tidyResult
36 [exec:patch] cp go.mod.orig go.mod
37 [exec:patch] ! go mod tidy -diff
38 [exec:patch] cp stdout diff.patch
39 [exec:patch] exec patch -p1 -i diff.patch
40 [exec:patch] go mod tidy -diff
41 [exec:patch] cmp go.mod go.mod.tidyResult
42 [exec:patch] cmp go.sum go.sum.tidyResult
43
44 go list -m all
45 cmp stdout m_all.txt
46
47 go mod edit -go=1.16
48 go list -m all
49 cmp stdout m_all.txt
50
51
52 # If we explicitly drop compatibility with 1.16, we retain fewer checksums,
53 # which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode.
54
55 cp go.mod.orig go.mod
56 go mod tidy -compat=1.17
57 cmp go.mod go.mod.orig
58
59 # Make sure that -diff behaves the same as tidy.
60 [exec:patch] mv go.mod go.mod.tidyResult
61 [exec:patch] mv go.sum go.sum.tidyResult
62 [exec:patch] cp go.mod.orig go.mod
63 [exec:patch] ! go mod tidy -compat=1.17 -diff
64 [exec:patch] cp stdout diff.patch
65 [exec:patch] exec patch -p1 -i diff.patch
66 [exec:patch] go mod tidy -compat=1.17 -diff
67 [exec:patch] cmp go.mod go.mod.tidyResult
68 [exec:patch] cmp go.sum go.sum.tidyResult
69
70 go list -m all
71 cmp stdout m_all.txt
72
73 go mod edit -go=1.16
74 ! go list -m all
75 stderr '^go: example.net/lazy@v0.1.0 requires\n\texample.com/version@v1.0.1: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/version$'
76
77
78 -- go.mod --
79 // Module m happens to have the exact same build list as what would be
80 // selected under Go 1.16, but computes that build list without looking at
81 // as many go.mod files.
82 module example.com/m
83
84 go 1.17
85
86 replace example.net/lazy v0.1.0 => ./lazy
87
88 require (
89 example.com/version v1.1.0
90 example.net/lazy v0.1.0
91 )
92 -- m_all.txt --
93 example.com/m
94 example.com/version v1.1.0
95 example.net/lazy v0.1.0 => ./lazy
96 -- compatible.go --
97 package compatible
98
99 import (
100 _ "example.com/version"
101 _ "example.net/lazy"
102 )
103 -- lazy/go.mod --
104 // Module lazy requires example.com/version v1.0.1.
105 //
106 // However, since this module is lazy, its dependents
107 // should not need checksums for that version of the module
108 // unless they actually import packages from it.
109 module example.net/lazy
110
111 go 1.17
112
113 require example.com/version v1.0.1
114 -- lazy/lazy.go --
115 package lazy
116
117 import _ "example.com/version"
118
View as plain text