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# go mod edit -godebug
91cd $WORK/g
92cp go.mod.start go.mod
93go mod edit -godebug key=value
94cmpenv go.mod go.mod.edit
95go mod edit -dropgodebug key2
96cmpenv go.mod go.mod.edit
97go mod edit -dropgodebug key
98cmpenv go.mod go.mod.start
99
100# go mod edit -tool
101cd $WORK/h
102cp go.mod.start go.mod
103go mod edit -tool example.com/tool
104cmpenv go.mod go.mod.edit
105go mod edit -droptool example.com/tool2
106cmpenv go.mod go.mod.edit
107go mod edit -droptool example.com/tool
108cmpenv go.mod go.mod.start
109
110-- x.go --
111package x
112
113-- w/w.go --
114package w
115
116-- $WORK/go.mod.init --
117module x.x/y/z
118
119go $goversion
120-- $WORK/go.mod.edit1 --
121module x.x/y/z
122
123go $goversion
124
125require x.1 v1.0.0
126
127exclude (
128 x.1 v1.2.0
129 x.1 v1.2.1
130 x.1 v2.0.0+incompatible
131)
132
133replace (
134 x.1 v1.3.0 => y.1 v1.4.0
135 x.1 v1.4.0 => ../z
136)
137
138retract (
139 v1.6.0
140 [v1.3.0, v1.4.0]
141 [v1.1.0, v1.2.0]
142 v1.0.0
143)
144-- $WORK/go.mod.edit2 --
145module x.x/y/z
146
147go $goversion
148
149exclude x.1 v1.2.0
150
151replace x.1 v1.4.0 => ../z
152
153retract (
154 v1.6.0
155 [v1.3.0, v1.4.0]
156)
157
158require x.3 v1.99.0
159-- $WORK/go.mod.json --
160{
161 "Module": {
162 "Path": "x.x/y/z"
163 },
164 "Go": "$goversion",
165 "Require": [
166 {
167 "Path": "x.3",
168 "Version": "v1.99.0"
169 }
170 ],
171 "Exclude": [
172 {
173 "Path": "x.1",
174 "Version": "v1.2.0"
175 }
176 ],
177 "Replace": [
178 {
179 "Old": {
180 "Path": "x.1",
181 "Version": "v1.4.0"
182 },
183 "New": {
184 "Path": "../z"
185 }
186 }
187 ],
188 "Retract": [
189 {
190 "Low": "v1.6.0",
191 "High": "v1.6.0"
192 },
193 {
194 "Low": "v1.3.0",
195 "High": "v1.4.0"
196 }
197 ],
198 "Tool": null
199}
200-- $WORK/go.mod.edit3 --
201module x.x/y/z
202
203go $goversion
204
205exclude x.1 v1.2.0
206
207replace (
208 x.1 v1.3.0 => y.1/v2 v2.3.5
209 x.1 v1.4.0 => y.1/v2 v2.3.5
210)
211
212retract (
213 v1.6.0
214 [v1.3.0, v1.4.0]
215)
216
217require x.3 v1.99.0
218-- $WORK/go.mod.edit4 --
219module x.x/y/z
220
221go $goversion
222
223exclude x.1 v1.2.0
224
225replace x.1 => y.1/v2 v2.3.6
226
227retract (
228 v1.6.0
229 [v1.3.0, v1.4.0]
230)
231
232require x.3 v1.99.0
233-- $WORK/go.mod.edit5 --
234module x.x/y/z
235
236go $goversion
237
238exclude x.1 v1.2.0
239
240retract (
241 v1.6.0
242 [v1.3.0, v1.4.0]
243)
244
245require x.3 v1.99.0
246-- $WORK/go.mod.edit6 --
247module x.x/y/z
248
249go $goversion
250
251exclude x.1 v1.2.0
252
253retract (
254 v1.6.0
255 [v1.3.0, v1.4.0]
256)
257
258require x.3 v1.99.0
259
260replace x.1 => ../y.1/@v2
261-- $WORK/local/go.mod.edit --
262module local-only
263
264go $goversion
265
266require other-local v1.0.0
267
268replace other-local v1.0.0 => ./other
269-- $WORK/go.mod.badfmt --
270module x.x/y/z
271
272go 1.10
273
274exclude x.1 v1.2.0
275
276replace x.1 => y.1/v2 v2.3.6
277
278require x.3 v1.99.0
279
280retract [ "v1.8.1" , "v1.8.2" ]
281-- $WORK/go.mod.goodfmt --
282module x.x/y/z
283
284go 1.10
285
286exclude x.1 v1.2.0
287
288replace x.1 => y.1/v2 v2.3.6
289
290require x.3 v1.99.0
291
292retract [v1.8.1, v1.8.2]
293-- $WORK/m/go.mod.edit --
294module x.x/y/z
295
296go $goversion
297-- $WORK/go.mod.retractrationale --
298module x.x/y/z
299
300go 1.15
301
302// a
303retract v1.0.0
304
305// b
306retract (
307 v1.0.1
308 v1.0.2 // c
309)
310-- $WORK/go.mod.retractrationale.json --
311{
312 "Module": {
313 "Path": "x.x/y/z"
314 },
315 "Go": "1.15",
316 "Require": null,
317 "Exclude": null,
318 "Replace": null,
319 "Retract": [
320 {
321 "Low": "v1.0.0",
322 "High": "v1.0.0",
323 "Rationale": "a"
324 },
325 {
326 "Low": "v1.0.1",
327 "High": "v1.0.1",
328 "Rationale": "b"
329 },
330 {
331 "Low": "v1.0.2",
332 "High": "v1.0.2",
333 "Rationale": "c"
334 }
335 ],
336 "Tool": null
337}
338-- $WORK/go.mod.deprecation --
339// Deprecated: and the new one is not ready yet
340module m
341-- $WORK/go.mod.deprecation.json --
342{
343 "Module": {
344 "Path": "m",
345 "Deprecated": "and the new one is not ready yet"
346 },
347 "Require": null,
348 "Exclude": null,
349 "Replace": null,
350 "Retract": null,
351 "Tool": null
352}
353-- $WORK/go.mod.empty --
354-- $WORK/go.mod.empty.json --
355{
356 "Module": {
357 "Path": ""
358 },
359 "Require": null,
360 "Exclude": null,
361 "Replace": null,
362 "Retract": null,
363 "Tool": null
364}
365-- $WORK/g/go.mod.start --
366module g
367
368go 1.10
369-- $WORK/g/go.mod.edit --
370module g
371
372go 1.10
373
374godebug key=value
375-- $WORK/h/go.mod.start --
376module g
377
378go 1.24
379-- $WORK/h/go.mod.edit --
380module g
381
382go 1.24
383
384tool example.com/tool
View as plain text