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