...
1[!net:golang.org] skip
2[!git] skip
3
4env GO111MODULE=on
5env GOPROXY=direct
6env GOSUMDB=off
7env 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.
18cp go.mod.orig go.mod
19go mod edit -require golang.org/x/text@14c0d48ead0c
20cd outside
21! go list -m golang.org/x/text
22stderr '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'
23cd ..
24go list -m golang.org/x/text
25stdout 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c'
26grep '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.
29cp go.mod.orig go.mod
30go mod edit -require golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c
31cd outside
32! go list -m golang.org/x/text
33stderr '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'
34cd ..
35! go list -m golang.org/x/text
36stderr '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.
39cp go.mod.orig go.mod
40go get golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c
41go list -m golang.org/x/text/...
42stdout '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.
46cp go.mod.orig go.mod
47go mod edit -require golang.org/x/text@v2.1.1-0.20170915032832-14c0d48ead0c
48cd outside
49! go list -m golang.org/x/text
50stderr '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'
51cd ..
52! go list -m golang.org/x/text
53stderr '^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.
56cp go.mod.orig go.mod
57go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0
58cd outside
59! go list -m golang.org/x/text
60stderr '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\)'
61cd ..
62! go list -m golang.org/x/text
63stderr '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.
66cp go.mod.orig go.mod
67go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a
68cd outside
69! go list -m golang.org/x/text
70stderr '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\)'
71cd ..
72! go list -m golang.org/x/text
73stderr '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.
76cp go.mod.orig go.mod
77go mod edit -require golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c
78cd outside
79! go list -m golang.org/x/text
80stderr '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\)'
81cd ..
82! go list -m golang.org/x/text
83stderr '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.
87go mod edit -replace golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c=golang.org/x/text@14c0d48ead0c
88cd outside
89! go list -m golang.org/x/text
90stderr '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\)'
91cd ..
92go list -m golang.org/x/text
93stdout '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.
96cp go.mod.orig go.mod
97go mod edit -require golang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c
98cd outside
99! go list -m golang.org/x/text
100stderr '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'
101cd ..
102! go list -m golang.org/x/text
103stderr '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-.
108cp go.mod.orig go.mod
109go mod edit -require golang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c
110cd outside
111! go list -m golang.org/x/text
112stderr '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'
113cd ..
114! go list -m golang.org/x/text
115stderr '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.
119cp go.mod.orig go.mod
120go mod edit -require golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c
121cd outside
122! go list -m golang.org/x/text
123stderr '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'
124cd ..
125! go list -m golang.org/x/text
126stderr '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.
130go mod edit -replace golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c=golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
131cd outside
132! go list -m golang.org/x/text
133stderr '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'
134cd ..
135go list -m golang.org/x/text
136stdout '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'
140cp go.mod.orig go.mod
141go mod edit -require golang.org/x/text@v1.999999.0
142go mod edit -replace golang.org/x/text@v1.999999.0=golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
143cd outside
144! go get golang.org/x/text@upgrade
145stderr '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'
146cd ..
147go get golang.org/x/text@upgrade
148go list -m golang.org/x/text
149stdout '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.
152cp go.mod.orig go.mod
153go mod edit -require golang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c
154cd outside
155! go list -m golang.org/x/text
156stderr '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\)'
157cd ..
158! go list -m golang.org/x/text
159stderr '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.
162cp go.mod.orig go.mod
163go mod edit -require golang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac
164cd outside
165! go list -m golang.org/x/text
166stderr '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'
167cd ..
168! go list -m golang.org/x/text
169stderr '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.
172cp go.mod.orig go.mod
173go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c+incompatible
174cd outside
175! go list -m golang.org/x/text
176stderr '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'
177cd ..
178! go list -m golang.org/x/text
179stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible'
180
181[!net:github.com] stop
182
183# The pseudo-version for a commit after a tag with a non-matching major version
184# should instead be based on the last matching tag.
185cp go.mod.orig go.mod
186go mod edit -require github.com/pierrec/lz4@473cd7ce01a1
187go list -m github.com/pierrec/lz4
188stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1'
189cd outside
190go list -m github.com/pierrec/lz4
191stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1'
192cd ..
193
194# A +incompatible pseudo-version for a module that has an explicit go.mod file is invalid.
195cp go.mod.orig go.mod
196go mod edit -require github.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d+incompatible
197cd outside
198! go list -m github.com/pierrec/lz4
199stderr '^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"\)$'
200cd ..
201! go list -m github.com/pierrec/lz4
202stderr '^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"\)$'
203
204# A +incompatible pseudo-version is valid for a revision of the module
205# that lacks a go.mod file.
206cp go.mod.orig go.mod
207go mod edit -require github.com/pierrec/lz4@v2.0.4-0.20180826165652-dbe9298ce099+incompatible
208cd outside
209go list -m github.com/pierrec/lz4
210stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible'
211cd ..
212go list -m github.com/pierrec/lz4
213stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible'
214
215# 'go get' for a mismatched major version without a go.mod file should resolve
216# to the equivalent +incompatible version, not a pseudo-version with a different
217# major version.
218cp go.mod.orig go.mod
219go get github.com/pierrec/lz4@v2.0.5
220go list -m github.com/pierrec/lz4
221stdout 'github.com/pierrec/lz4 v2.0.5\+incompatible'
222
223# 'go get' for a mismatched major version with a go.mod file should error out,
224# not resolve to a pseudo-version with a different major version.
225cp go.mod.orig go.mod
226! go get github.com/pierrec/lz4@v2.0.8
227stderr '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"\)$'
228
229# An invalid +incompatible suffix for a canonical version should error out,
230# not resolve to a pseudo-version.
231#
232# TODO(bcmills): The "outside" view for this failure mode is missing its import stack.
233# Figure out why and fix it.
234cp go.mod.orig go.mod
235go mod edit -require github.com/pierrec/lz4@v2.0.8+incompatible
236cd outside
237! go list -m github.com/pierrec/lz4
238stderr '^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"\)$'
239cd ..
240! go list -m github.com/pierrec/lz4
241stderr '^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"\)$'
242
243-- go.mod.orig --
244module example.com
245
246go 1.13
247-- outside/go.mod --
248module example.com/outside
249
250go 1.13
251
252require example.com v0.0.0
253replace example.com v0.0.0 => ./..
View as plain text