1 [!net] skip
2 [!exec:git] skip
3
4 env GO111MODULE=on
5 env GOPROXY=direct
6 env GOSUMDB=off
7 env GOFLAGS=-mod=mod
8
9 # Regression test for golang.org/issue/27173: if the user (or go.mod file)
10 # requests a pseudo-version that does not match both the module path and commit
11 # metadata, reject it with a helpful error message.
12 #
13 # TODO(bcmills): Replace the github.com/pierrec/lz4 examples with something
14 # equivalent on vcs-test.golang.org.
15
16 # An incomplete commit hash is not a valid semantic version,
17 # but can appear in the main go.mod file anyway and should be resolved.
18 cp go.mod.orig go.mod
19 go mod edit -require golang.org/x/text@14c0d48ead0c
20 cd outside
21 ! go list -m golang.org/x/text
22 stderr 'go: example.com@v0.0.0 \(replaced by \./\.\.\): parsing ..[/\\]go.mod: '$WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "14c0d48ead0c" invalid: must be of the form v1.2.3'
23 cd ..
24 go list -m golang.org/x/text
25 stdout 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c'
26 grep 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' go.mod
27
28 # A module path below the repo root that does not contain a go.mod file is invalid.
29 cp go.mod.orig go.mod
30 go mod edit -require golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c
31 cd outside
32 ! go list -m golang.org/x/text
33 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c'
34 cd ..
35 ! go list -m golang.org/x/text
36 stderr 'golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c'
37
38 # However, arguments to 'go get' can name packages above the root.
39 cp go.mod.orig go.mod
40 go get golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c
41 go list -m golang.org/x/text/...
42 stdout 'golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c'
43 ! stdout 'golang.org/x/text/unicode'
44
45 # A major version that does not match the module path is invalid.
46 cp go.mod.orig go.mod
47 go mod edit -require golang.org/x/text@v2.1.1-0.20170915032832-14c0d48ead0c
48 cd outside
49 ! go list -m golang.org/x/text
50 stderr 'go: example.com@v0.0.0 \(replaced by \./\.\.\): parsing ..[/\\]go.mod: '$WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "v2.1.1-0.20170915032832-14c0d48ead0c" invalid: should be v0 or v1, not v2'
51 cd ..
52 ! go list -m golang.org/x/text
53 stderr $WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "v2.1.1-0.20170915032832-14c0d48ead0c" invalid: should be v0 or v1, not v2'
54
55 # A pseudo-version with fewer than 12 digits of SHA-1 prefix is invalid.
56 cp go.mod.orig go.mod
57 go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0
58 cd outside
59 ! go list -m golang.org/x/text
60 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0: invalid pseudo-version: revision is shorter than canonical \(expected 14c0d48ead0c\)'
61 cd ..
62 ! go list -m golang.org/x/text
63 stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0: invalid pseudo-version: revision is shorter than canonical \(expected 14c0d48ead0c\)'
64
65 # A pseudo-version with more than 12 digits of SHA-1 prefix is invalid.
66 cp go.mod.orig go.mod
67 go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a
68 cd outside
69 ! go list -m golang.org/x/text
70 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a: invalid pseudo-version: revision is longer than canonical \(expected 14c0d48ead0c\)'
71 cd ..
72 ! go list -m golang.org/x/text
73 stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a: invalid pseudo-version: revision is longer than canonical \(expected 14c0d48ead0c\)'
74
75 # A pseudo-version that does not match the commit timestamp is invalid.
76 cp go.mod.orig go.mod
77 go mod edit -require golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c
78 cd outside
79 ! go list -m golang.org/x/text
80 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)'
81 cd ..
82 ! go list -m golang.org/x/text
83 stderr 'golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)'
84
85 # A 'replace' directive in the main module can replace an invalid timestamp
86 # with a valid one.
87 go mod edit -replace golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c=golang.org/x/text@14c0d48ead0c
88 cd outside
89 ! go list -m golang.org/x/text
90 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)'
91 cd ..
92 go list -m golang.org/x/text
93 stdout 'golang.org/x/text v0.1.1-0.20190915032832-14c0d48ead0c => golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c'
94
95 # A pseudo-version that is not derived from a tag is invalid.
96 cp go.mod.orig go.mod
97 go mod edit -require golang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c
98 cd outside
99 ! go list -m golang.org/x/text
100 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c: invalid pseudo-version: preceding tag \(v1.999.998\) not found'
101 cd ..
102 ! go list -m golang.org/x/text
103 stderr 'golang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c: invalid pseudo-version: preceding tag \(v1.999.998\) not found'
104
105 # A v1.0.0- pseudo-version that is not derived from a tag is invalid:
106 # v1.0.0- implies no tag, but the correct no-tag prefix for a module path
107 # without a major-version suffix is v0.0.0-.
108 cp go.mod.orig go.mod
109 go mod edit -require golang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c
110 cd outside
111 ! go list -m golang.org/x/text
112 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c: invalid pseudo-version: major version without preceding tag must be v0, not v1'
113 cd ..
114 ! go list -m golang.org/x/text
115 stderr 'golang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c: invalid pseudo-version: major version without preceding tag must be v0, not v1'
116
117 # A pseudo-version vX.Y.Z+1 cannot have Z+1 == 0, since that would
118 # imply a base tag with a negative patch field.
119 cp go.mod.orig go.mod
120 go mod edit -require golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c
121 cd outside
122 ! go list -m golang.org/x/text
123 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c: invalid pseudo-version: version before v0.0.0 would have negative patch number'
124 cd ..
125 ! go list -m golang.org/x/text
126 stderr 'golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c: invalid pseudo-version: version before v0.0.0 would have negative patch number'
127
128 # A 'replace' directive in the main module can replace an
129 # invalid pseudo-version base with a valid one.
130 go mod edit -replace golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c=golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
131 cd outside
132 ! go list -m golang.org/x/text
133 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c: invalid pseudo-version: version before v0.0.0 would have negative patch number'
134 cd ..
135 go list -m golang.org/x/text
136 stdout 'golang.org/x/text v0.0.0-0.20170915032832-14c0d48ead0c => golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c'
137
138 # A 'replace' directive can replace an invalid 'latest' version, and
139 # should suppress errors for that version in 'go get -u'
140 cp go.mod.orig go.mod
141 go mod edit -require golang.org/x/text@v1.999999.0
142 go mod edit -replace golang.org/x/text@v1.999999.0=golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
143 cd outside
144 ! go get golang.org/x/text@upgrade
145 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v1.999999.0: reading golang.org/x/text/go.mod at revision v1.999999.0: unknown revision v1.999999.0'
146 cd ..
147 go get golang.org/x/text@upgrade
148 go list -m golang.org/x/text
149 stdout 'golang.org/x/text v1.999999.0 => golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c'
150
151 # A pseudo-version derived from a non-ancestor tag is invalid.
152 cp go.mod.orig go.mod
153 go mod edit -require golang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c
154 cd outside
155 ! go list -m golang.org/x/text
156 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c: invalid pseudo-version: revision 14c0d48ead0c is not a descendent of preceding tag \(v0.2.0\)'
157 cd ..
158 ! go list -m golang.org/x/text
159 stderr 'golang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c: invalid pseudo-version: revision 14c0d48ead0c is not a descendent of preceding tag \(v0.2.0\)'
160
161 # A pseudo-version derived from a canonical tag on the same revision is invalid.
162 cp go.mod.orig go.mod
163 go mod edit -require golang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac
164 cd outside
165 ! go list -m golang.org/x/text
166 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac: invalid pseudo-version: tag \(v0.2.0\) found on revision c4d099d611ac is already canonical, so should not be replaced with a pseudo-version derived from that tag'
167 cd ..
168 ! go list -m golang.org/x/text
169 stderr 'golang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac: invalid pseudo-version: tag \(v0.2.0\) found on revision c4d099d611ac is already canonical, so should not be replaced with a pseudo-version derived from that tag'
170
171 # A +incompatible suffix is not allowed on a version that is actually compatible.
172 cp go.mod.orig go.mod
173 go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c+incompatible
174 cd outside
175 ! go list -m golang.org/x/text
176 stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible'
177 cd ..
178 ! go list -m golang.org/x/text
179 stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible'
180
181 # The pseudo-version for a commit after a tag with a non-matching major version
182 # should instead be based on the last matching tag.
183 cp go.mod.orig go.mod
184 go mod edit -require github.com/pierrec/lz4@473cd7ce01a1
185 go list -m github.com/pierrec/lz4
186 stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1'
187 cd outside
188 go list -m github.com/pierrec/lz4
189 stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1'
190 cd ..
191
192 # A +incompatible pseudo-version for a module that has an explicit go.mod file is invalid.
193 cp go.mod.orig go.mod
194 go mod edit -require github.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d+incompatible
195 cd outside
196 ! go list -m github.com/pierrec/lz4
197 stderr '^go: example.com@v0.0.0 requires\n\tgithub.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$'
198 cd ..
199 ! go list -m github.com/pierrec/lz4
200 stderr '^go: github.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$'
201
202 # A +incompatible pseudo-version is valid for a revision of the module
203 # that lacks a go.mod file.
204 cp go.mod.orig go.mod
205 go mod edit -require github.com/pierrec/lz4@v2.0.4-0.20180826165652-dbe9298ce099+incompatible
206 cd outside
207 go list -m github.com/pierrec/lz4
208 stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible'
209 cd ..
210 go list -m github.com/pierrec/lz4
211 stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible'
212
213 # 'go get' for a mismatched major version without a go.mod file should resolve
214 # to the equivalent +incompatible version, not a pseudo-version with a different
215 # major version.
216 cp go.mod.orig go.mod
217 go get github.com/pierrec/lz4@v2.0.5
218 go list -m github.com/pierrec/lz4
219 stdout 'github.com/pierrec/lz4 v2.0.5\+incompatible'
220
221 # 'go get' for a mismatched major version with a go.mod file should error out,
222 # not resolve to a pseudo-version with a different major version.
223 cp go.mod.orig go.mod
224 ! go get github.com/pierrec/lz4@v2.0.8
225 stderr 'go: github.com/pierrec/lz4@v2.0.8: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$'
226
227 # An invalid +incompatible suffix for a canonical version should error out,
228 # not resolve to a pseudo-version.
229 #
230 # TODO(bcmills): The "outside" view for this failure mode is missing its import stack.
231 # Figure out why and fix it.
232 cp go.mod.orig go.mod
233 go mod edit -require github.com/pierrec/lz4@v2.0.8+incompatible
234 cd outside
235 ! go list -m github.com/pierrec/lz4
236 stderr '^go: github.com/pierrec/lz4@v2.0.8\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$'
237 cd ..
238 ! go list -m github.com/pierrec/lz4
239 stderr '^go: github.com/pierrec/lz4@v2.0.8\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$'
240
241 -- go.mod.orig --
242 module example.com
243
244 go 1.13
245 -- outside/go.mod --
246 module example.com/outside
247
248 go 1.13
249
250 require example.com v0.0.0
251 replace example.com v0.0.0 => ./..
252
View as plain text