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