1env GO111MODULE=on
2
3# Test that go mod edits and related mod flags work.
4# Also test that they can use a dummy name that isn't resolvable. golang.org/issue/24100
5
6# go mod init
7! go mod init
8stderr 'cannot determine module path'
9! exists go.mod
10
11go mod init x.x/y/z
12stderr 'creating new go.mod: module x.x/y/z'
13cmpenv go.mod $WORK/go.mod.init
14
15! go mod init
16cmpenv go.mod $WORK/go.mod.init
17
18# go mod edits
19go mod edit -droprequire=x.1 -require=x.1@v1.0.0 -require=x.2@v1.1.0 -droprequire=x.2 -exclude='x.1 @ v1.2.0' -exclude=x.1@v1.2.1 -exclude=x.1@v2.0.0+incompatible -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z' -retract=v1.6.0 -retract=[v1.1.0,v1.2.0] -retract=[v1.3.0,v1.4.0] -retract=v1.0.0
20cmpenv go.mod $WORK/go.mod.edit1
21go mod edit -droprequire=x.1 -dropexclude=x.1@v1.2.1 -dropexclude=x.1@v2.0.0+incompatible -dropreplace=x.1@v1.3.0 -require=x.3@v1.99.0 -dropretract=v1.0.0 -dropretract=[v1.1.0,v1.2.0]
22cmpenv go.mod $WORK/go.mod.edit2
23
24# -exclude and -retract reject invalid versions.
25! go mod edit -exclude=example.com/m@bad
26stderr '^go: -exclude=example.com/m@bad: version "bad" invalid: must be of the form v1.2.3$'
27! go mod edit -retract=bad
28stderr '^go: -retract=bad: version "bad" invalid: must be of the form v1.2.3$'
29
30! go mod edit -exclude=example.com/m@v2.0.0
31stderr '^go: -exclude=example.com/m@v2\.0\.0: version "v2\.0\.0" invalid: should be v2\.0\.0\+incompatible \(or module example\.com/m/v2\)$'
32
33! go mod edit -exclude=example.com/m/v2@v1.0.0
34stderr '^go: -exclude=example.com/m/v2@v1\.0\.0: version "v1\.0\.0" invalid: should be v2, not v1$'
35
36! go mod edit -exclude=gopkg.in/example.v1@v2.0.0
37stderr '^go: -exclude=gopkg\.in/example\.v1@v2\.0\.0: version "v2\.0\.0" invalid: should be v1, not v2$'
38
39cmpenv go.mod $WORK/go.mod.edit2
40
41# go mod edit -json
42go mod edit -json
43cmpenv stdout $WORK/go.mod.json
44
45# go mod edit -json (retractions with rationales)
46go mod edit -json $WORK/go.mod.retractrationale
47cmp stdout $WORK/go.mod.retractrationale.json
48
49# go mod edit -json (deprecation)
50go mod edit -json $WORK/go.mod.deprecation
51cmp stdout $WORK/go.mod.deprecation.json
52
53# go mod edit -json (empty mod file)
54go mod edit -json $WORK/go.mod.empty
55cmp stdout $WORK/go.mod.empty.json
56
57# go mod edit -replace
58go mod edit -replace=x.1@v1.3.0=y.1/v2@v2.3.5 -replace=x.1@v1.4.0=y.1/v2@v2.3.5
59cmpenv go.mod $WORK/go.mod.edit3
60go mod edit -replace=x.1=y.1/v2@v2.3.6
61cmpenv go.mod $WORK/go.mod.edit4
62go mod edit -dropreplace=x.1
63cmpenv go.mod $WORK/go.mod.edit5
64go mod edit -replace=x.1=../y.1/@v2
65cmpenv go.mod $WORK/go.mod.edit6
66! go mod edit -replace=x.1=y.1/@v2
67stderr '^go: -replace=x.1=y.1/@v2: invalid new path: malformed import path "y.1/": trailing slash$'
68
69# go mod edit -fmt
70cp $WORK/go.mod.badfmt go.mod
71go mod edit -fmt -print # -print should avoid writing file
72cmpenv stdout $WORK/go.mod.goodfmt
73cmp go.mod $WORK/go.mod.badfmt
74go mod edit -fmt # without -print, should write file (and nothing to stdout)
75! stdout .
76cmpenv go.mod $WORK/go.mod.goodfmt
77
78# go mod edit -module
79cd $WORK/m
80go mod init a.a/b/c
81go mod edit -module x.x/y/z
82cmpenv go.mod go.mod.edit
83
84# golang.org/issue/30513: don't require go-gettable module paths.
85cd $WORK/local
86go mod init foo
87go mod edit -module local-only -require=other-local@v1.0.0 -replace other-local@v1.0.0=./other
88cmpenv go.mod go.mod.edit
89
90-- x.go --
91package x
92
93-- w/w.go --
94package w
95
96-- $WORK/go.mod.init --
97module x.x/y/z
98
99go $goversion
100-- $WORK/go.mod.edit1 --
101module x.x/y/z
102
103go $goversion
104
105require x.1 v1.0.0
106
107exclude (
108 x.1 v1.2.0
109 x.1 v1.2.1
110 x.1 v2.0.0+incompatible
111)
112
113replace (
114 x.1 v1.3.0 => y.1 v1.4.0
115 x.1 v1.4.0 => ../z
116)
117
118retract (
119 v1.6.0
120 [v1.3.0, v1.4.0]
121 [v1.1.0, v1.2.0]
122 v1.0.0
123)
124-- $WORK/go.mod.edit2 --
125module x.x/y/z
126
127go $goversion
128
129exclude x.1 v1.2.0
130
131replace x.1 v1.4.0 => ../z
132
133retract (
134 v1.6.0
135 [v1.3.0, v1.4.0]
136)
137
138require x.3 v1.99.0
139-- $WORK/go.mod.json --
140{
141 "Module": {
142 "Path": "x.x/y/z"
143 },
144 "Go": "$goversion",
145 "Require": [
146 {
147 "Path": "x.3",
148 "Version": "v1.99.0"
149 }
150 ],
151 "Exclude": [
152 {
153 "Path": "x.1",
154 "Version": "v1.2.0"
155 }
156 ],
157 "Replace": [
158 {
159 "Old": {
160 "Path": "x.1",
161 "Version": "v1.4.0"
162 },
163 "New": {
164 "Path": "../z"
165 }
166 }
167 ],
168 "Retract": [
169 {
170 "Low": "v1.6.0",
171 "High": "v1.6.0"
172 },
173 {
174 "Low": "v1.3.0",
175 "High": "v1.4.0"
176 }
177 ]
178}
179-- $WORK/go.mod.edit3 --
180module x.x/y/z
181
182go $goversion
183
184exclude x.1 v1.2.0
185
186replace (
187 x.1 v1.3.0 => y.1/v2 v2.3.5
188 x.1 v1.4.0 => y.1/v2 v2.3.5
189)
190
191retract (
192 v1.6.0
193 [v1.3.0, v1.4.0]
194)
195
196require x.3 v1.99.0
197-- $WORK/go.mod.edit4 --
198module x.x/y/z
199
200go $goversion
201
202exclude x.1 v1.2.0
203
204replace x.1 => y.1/v2 v2.3.6
205
206retract (
207 v1.6.0
208 [v1.3.0, v1.4.0]
209)
210
211require x.3 v1.99.0
212-- $WORK/go.mod.edit5 --
213module x.x/y/z
214
215go $goversion
216
217exclude x.1 v1.2.0
218
219retract (
220 v1.6.0
221 [v1.3.0, v1.4.0]
222)
223
224require x.3 v1.99.0
225-- $WORK/go.mod.edit6 --
226module x.x/y/z
227
228go $goversion
229
230exclude x.1 v1.2.0
231
232retract (
233 v1.6.0
234 [v1.3.0, v1.4.0]
235)
236
237require x.3 v1.99.0
238
239replace x.1 => ../y.1/@v2
240-- $WORK/local/go.mod.edit --
241module local-only
242
243go $goversion
244
245require other-local v1.0.0
246
247replace other-local v1.0.0 => ./other
248-- $WORK/go.mod.badfmt --
249module x.x/y/z
250
251go 1.10
252
253exclude x.1 v1.2.0
254
255replace x.1 => y.1/v2 v2.3.6
256
257require x.3 v1.99.0
258
259retract [ "v1.8.1" , "v1.8.2" ]
260-- $WORK/go.mod.goodfmt --
261module x.x/y/z
262
263go 1.10
264
265exclude x.1 v1.2.0
266
267replace x.1 => y.1/v2 v2.3.6
268
269require x.3 v1.99.0
270
271retract [v1.8.1, v1.8.2]
272-- $WORK/m/go.mod.edit --
273module x.x/y/z
274
275go $goversion
276-- $WORK/go.mod.retractrationale --
277module x.x/y/z
278
279go 1.15
280
281// a
282retract v1.0.0
283
284// b
285retract (
286 v1.0.1
287 v1.0.2 // c
288)
289-- $WORK/go.mod.retractrationale.json --
290{
291 "Module": {
292 "Path": "x.x/y/z"
293 },
294 "Go": "1.15",
295 "Require": null,
296 "Exclude": null,
297 "Replace": null,
298 "Retract": [
299 {
300 "Low": "v1.0.0",
301 "High": "v1.0.0",
302 "Rationale": "a"
303 },
304 {
305 "Low": "v1.0.1",
306 "High": "v1.0.1",
307 "Rationale": "b"
308 },
309 {
310 "Low": "v1.0.2",
311 "High": "v1.0.2",
312 "Rationale": "c"
313 }
314 ]
315}
316-- $WORK/go.mod.deprecation --
317// Deprecated: and the new one is not ready yet
318module m
319-- $WORK/go.mod.deprecation.json --
320{
321 "Module": {
322 "Path": "m",
323 "Deprecated": "and the new one is not ready yet"
324 },
325 "Require": null,
326 "Exclude": null,
327 "Replace": null,
328 "Retract": null
329}
330-- $WORK/go.mod.empty --
331-- $WORK/go.mod.empty.json --
332{
333 "Module": {
334 "Path": ""
335 },
336 "Require": null,
337 "Exclude": null,
338 "Replace": null,
339 "Retract": null
340}
View as plain text