1 [short] skip
2 [!git] skip
3
4 env GOPROXY=direct
5 env GOSUMDB=off
6 env 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.
14 cp go.mod.orig go.mod
15 go mod edit -require vcs-test.golang.org/go/invalid-version@1732873
16 cd outside
17 ! go list -m vcs-test.golang.org/go/invalid-version
18 stderr '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'
19 cd ..
20 go list -m vcs-test.golang.org/go/invalid-version
21 stdout 'vcs-test.golang.org/go/invalid-version v0.1.1-0.20170915032832-1732873102df'
22 grep '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.
25 cp go.mod.orig go.mod
26 go mod edit -require vcs-test.golang.org/go/invalid-version/unicode@v0.0.0-20170915032832-1732873102df
27 cd outside
28 ! go list -m vcs-test.golang.org/go/invalid-version
29 stderr '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'
30 cd ..
31 ! go list -m vcs-test.golang.org/go/invalid-version
32 stderr '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.
35 cp go.mod.orig go.mod
36 go get vcs-test.golang.org/go/invalid-version@v0.1.1-0.20170915032832-90ac26bf7f41
37 go list -m vcs-test.golang.org/go/invalid-version/...
38 stdout '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.
42 cp go.mod.orig go.mod
43 go mod edit -require vcs-test.golang.org/go/invalid-version@v2.1.1-0.20170915032832-1732873102df
44 cd outside
45 ! go list -m vcs-test.golang.org/go/invalid-version
46 stderr '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'
47 cd ..
48 ! go list -m vcs-test.golang.org/go/invalid-version
49 stderr '^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.
52 cp go.mod.orig go.mod
53 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.1.1-0.20170915032832-1732873102d
54 cd outside
55 ! go list -m vcs-test.golang.org/go/invalid-version
56 stderr '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\)'
57 cd ..
58 ! go list -m vcs-test.golang.org/go/invalid-version
59 stderr '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.
62 cp go.mod.orig go.mod
63 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.1.1-0.20170915032832-1732873102dfcda2ecfbb94082da3cd4b21bc715
64 cd outside
65 ! go list -m vcs-test.golang.org/go/invalid-version
66 stderr '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\)'
67 cd ..
68 ! go list -m vcs-test.golang.org/go/invalid-version
69 stderr '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.
72 cp go.mod.orig go.mod
73 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.1.1-0.20190915032832-1732873102df
74 cd outside
75 ! go list -m vcs-test.golang.org/go/invalid-version
76 stderr '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\)'
77 cd ..
78 ! go list -m vcs-test.golang.org/go/invalid-version
79 stderr '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.
83 go mod edit -replace vcs-test.golang.org/go/invalid-version@v0.1.1-0.20190915032832-1732873102df=vcs-test.golang.org/go/invalid-version@1732873102df
84 cd outside
85 ! go list -m vcs-test.golang.org/go/invalid-version
86 stderr '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\)'
87 cd ..
88 go list -m vcs-test.golang.org/go/invalid-version
89 stdout '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.
92 cp go.mod.orig go.mod
93 go mod edit -require vcs-test.golang.org/go/invalid-version@v1.999.999-0.20170915032832-1732873102df
94 cd outside
95 ! go list -m vcs-test.golang.org/go/invalid-version
96 stderr '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'
97 cd ..
98 ! go list -m vcs-test.golang.org/go/invalid-version
99 stderr '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-.
104 cp go.mod.orig go.mod
105 go mod edit -require vcs-test.golang.org/go/invalid-version@v1.0.0-20170915032832-1732873102df
106 cd outside
107 ! go list -m vcs-test.golang.org/go/invalid-version
108 stderr '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'
109 cd ..
110 ! go list -m vcs-test.golang.org/go/invalid-version
111 stderr '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.
115 cp go.mod.orig go.mod
116 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.0.0-0.20170915032832-1732873102df
117 cd outside
118 ! go list -m vcs-test.golang.org/go/invalid-version
119 stderr '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'
120 cd ..
121 ! go list -m vcs-test.golang.org/go/invalid-version
122 stderr '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.
126 go 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
127 cd outside
128 ! go list -m vcs-test.golang.org/go/invalid-version
129 stderr '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'
130 cd ..
131 go list -m vcs-test.golang.org/go/invalid-version
132 stdout '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'
136 cp go.mod.orig go.mod
137 go mod edit -require vcs-test.golang.org/go/invalid-version@v1.999999.0
138 go 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
139 cd outside
140 ! go get vcs-test.golang.org/go/invalid-version@upgrade
141 stderr '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'
142 cd ..
143 go get vcs-test.golang.org/go/invalid-version@upgrade
144 go list -m vcs-test.golang.org/go/invalid-version
145 stdout '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.
149 cp go.mod.orig go.mod
150 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.2.1-0.20170915032832-1732873102df
151 cd outside
152 ! go list -m vcs-test.golang.org/go/invalid-version
153 stderr '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\)'
154 cd ..
155 ! go list -m vcs-test.golang.org/go/invalid-version
156 stderr '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.
159 cp go.mod.orig go.mod
160 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.2.1-0.20171213102548-a72be5ead5a6
161 cd outside
162 ! go list -m vcs-test.golang.org/go/invalid-version
163 stderr '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'
164 cd ..
165 ! go list -m vcs-test.golang.org/go/invalid-version
166 stderr '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.
169 cp go.mod.orig go.mod
170 go mod edit -require vcs-test.golang.org/go/invalid-version@v0.1.1-0.20170915032832-1732873102df+incompatible
171 cd outside
172 ! go list -m vcs-test.golang.org/go/invalid-version
173 stderr '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'
174 cd ..
175 ! go list -m vcs-test.golang.org/go/invalid-version
176 stderr '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).
180 cp go.mod.orig go.mod
181 go mod edit -require vcs-test.golang.org/go/invalid-version@5213b9f8842f
182 go list -m vcs-test.golang.org/go/invalid-version
183 stdout 'vcs-test.golang.org/go/invalid-version v0.2.1-0.20171213102548-5213b9f8842f'
184 cd outside
185 go list -m vcs-test.golang.org/go/invalid-version
186 stdout 'vcs-test.golang.org/go/invalid-version v0.2.1-0.20171213102548-5213b9f8842f'
187 cd ..
188
189 # A +incompatible pseudo-version for a module that has an explicit go.mod file is invalid.
190 cp go.mod.orig go.mod
191 go mod edit -require vcs-test.golang.org/go/invalid-version@v4.0.1-0.20171213102548-5213b9f8842f+incompatible
192 cd outside
193 ! go list -m vcs-test.golang.org/go/invalid-version
194 stderr '^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"\)$'
195 cd ..
196 ! go list -m vcs-test.golang.org/go/invalid-version
197 stderr '^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.
201 cp go.mod.orig go.mod
202 go mod edit -require vcs-test.golang.org/go/invalid-version@v4.0.1-0.20171213102548-dbb861dd9ef0+incompatible
203 cd outside
204 go list -m vcs-test.golang.org/go/invalid-version
205 stdout 'vcs-test.golang.org/go/invalid-version v4.0.1-0.20171213102548-dbb861dd9ef0\+incompatible'
206 cd ..
207 go list -m vcs-test.golang.org/go/invalid-version
208 stdout '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.
213 cp go.mod.orig go.mod
214 go get vcs-test.golang.org/go/invalid-version@v5.0.0
215 go list -m vcs-test.golang.org/go/invalid-version
216 stdout '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.
220 cp go.mod.orig go.mod
221 ! go get vcs-test.golang.org/go/invalid-version@v4.0.0
222 stderr '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.
229 cp go.mod.orig go.mod
230 go mod edit -require vcs-test.golang.org/go/invalid-version@v4.0.0+incompatible
231 cd outside
232 ! go list -m vcs-test.golang.org/go/invalid-version
233 stderr '^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"\)$'
234 cd ..
235 ! go list -m vcs-test.golang.org/go/invalid-version
236 stderr '^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 --
239 module example.com
240
241 go 1.13
242 -- outside/go.mod --
243 module example.com/outside
244
245 go 1.13
246
247 require example.com v0.0.0
248 replace example.com v0.0.0 => ./..
249
View as plain text