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, the "deleted" dependency contains an imported package, but
14 # Go 1.16 selects a higher version (in which that package has been deleted).
15
16 cp go.mod go.mod.orig
17
18 ! go mod tidy
19
20 stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n'
21
22 stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
23
24 # Make sure that -diff behaves the same as tidy.
25 [exec:patch] cp go.mod.orig go.mod
26 [exec:patch] ! exists go.sum
27 [exec:patch] ! go mod tidy -diff
28 [exec:patch] ! stdout .
29 [exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n'
30 [exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
31
32 # The suggested 'go mod tidy -e' command should proceed anyway.
33
34 go mod tidy -e
35 cmp go.mod go.mod.tidy
36
37 # Make sure that -diff behaves the same as tidy.
38 [exec:patch] cp go.mod go.mod.tidyResult
39 [exec:patch] ! exists go.sum
40 [exec:patch] cp go.mod.orig go.mod
41 [exec:patch] ! go mod tidy -e -diff
42 [exec:patch] cp stdout diff.patch
43 [exec:patch] exec patch -p1 -i diff.patch
44 [exec:patch] go mod tidy -e -diff
45 [exec:patch] ! stdout .
46 [exec:patch] cmp go.mod go.mod.tidyResult
47 [exec:patch] ! exists go.sum
48
49 # In 'go 1.16' mode we should error out in the way we claimed.
50
51 cd 116-outside
52 ! go list -deps -f $MODFMT example.com/m
53 stderr '^\.\.[/\\]m\.go:4:2: no required module provides package example\.net/deleted; to add it:\n\tgo get example\.net/deleted$'
54 cd ..
55
56 go mod edit -go=1.16
57 ! go list -deps -f $MODFMT example.com/m
58 stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$'
59
60 [exec:patch] cp go.mod go.mod.orig
61 ! go mod tidy
62 stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$'
63
64 # Make sure that -diff behaves the same as tidy.
65 [exec:patch] cp go.mod.orig go.mod
66 [exec:patch] ! exists go.sum
67 [exec:patch] ! go mod tidy -diff
68 [exec:patch] ! stdout .
69 [exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$'
70
71 -- go.mod --
72 module example.com/m
73
74 go 1.17
75
76 replace (
77 example.net/deleted v0.1.0 => ./d1
78 example.net/deleted v0.2.0 => ./d2
79 example.net/lazy v0.1.0 => ./lazy
80 example.net/pruned v0.1.0 => ./pruned
81 )
82
83 require (
84 example.net/deleted v0.1.0
85 example.net/deleted v0.1.0 // redundant
86 example.net/lazy v0.1.0
87 )
88 -- go.mod.tidy --
89 module example.com/m
90
91 go 1.17
92
93 replace (
94 example.net/deleted v0.1.0 => ./d1
95 example.net/deleted v0.2.0 => ./d2
96 example.net/lazy v0.1.0 => ./lazy
97 example.net/pruned v0.1.0 => ./pruned
98 )
99
100 require (
101 example.net/deleted v0.1.0
102 example.net/lazy v0.1.0
103 )
104 -- 116-outside/go.mod --
105 module outside
106
107 go 1.16
108
109 replace (
110 example.com/m => ../
111 example.net/deleted v0.1.0 => ../d1
112 example.net/deleted v0.2.0 => ../d2
113 example.net/lazy v0.1.0 => ../lazy
114 example.net/pruned v0.1.0 => ../pruned
115 )
116
117 require example.com/m v0.1.0
118 -- m.go --
119 package m
120
121 import (
122 _ "example.net/deleted"
123 _ "example.net/lazy"
124 )
125
126 -- d1/go.mod --
127 module example.net/deleted
128
129 go 1.17
130 -- d1/deleted.go --
131 package deleted
132 -- d2/go.mod --
133 module example.net/deleted
134
135 go 1.17
136 -- d2/README --
137 There is no longer a Go package here.
138
139 -- lazy/go.mod --
140 module example.net/lazy
141
142 go 1.17
143
144 require example.net/pruned v0.1.0
145 -- lazy/lazy.go --
146 package lazy
147
148 -- pruned/go.mod --
149 module example.net/pruned
150
151 go 1.17
152
153 require example.net/deleted v0.2.0
154
View as plain text