1 env 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
8 stderr 'cannot determine module path'
9 ! exists go.mod
10
11 go mod init x.x/y/z
12 stderr 'creating new go.mod: module x.x/y/z'
13 cmpenv go.mod $WORK/go.mod.init
14
15 ! go mod init
16 cmpenv go.mod $WORK/go.mod.init
17
18 # go mod edits
19 go 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
20 cmpenv go.mod $WORK/go.mod.edit1
21 go 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]
22 cmpenv go.mod $WORK/go.mod.edit2
23
24 # -exclude and -retract reject invalid versions.
25 ! go mod edit -exclude=example.com/m@bad
26 stderr '^go: -exclude=example.com/m@bad: version "bad" invalid: must be of the form v1.2.3$'
27 ! go mod edit -retract=bad
28 stderr '^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
31 stderr '^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
34 stderr '^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
37 stderr '^go: -exclude=gopkg\.in/example\.v1@v2\.0\.0: version "v2\.0\.0" invalid: should be v1, not v2$'
38
39 cmpenv go.mod $WORK/go.mod.edit2
40
41 # go mod edit -json
42 go mod edit -json
43 cmpenv stdout $WORK/go.mod.json
44
45 # go mod edit -json (retractions with rationales)
46 go mod edit -json $WORK/go.mod.retractrationale
47 cmp stdout $WORK/go.mod.retractrationale.json
48
49 # go mod edit -json (deprecation)
50 go mod edit -json $WORK/go.mod.deprecation
51 cmp stdout $WORK/go.mod.deprecation.json
52
53 # go mod edit -json (empty mod file)
54 go mod edit -json $WORK/go.mod.empty
55 cmp stdout $WORK/go.mod.empty.json
56
57 # go mod edit -replace
58 go 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
59 cmpenv go.mod $WORK/go.mod.edit3
60 go mod edit -replace=x.1=y.1/v2@v2.3.6
61 cmpenv go.mod $WORK/go.mod.edit4
62 go mod edit -dropreplace=x.1
63 cmpenv go.mod $WORK/go.mod.edit5
64 go mod edit -replace=x.1=../y.1/@v2
65 cmpenv go.mod $WORK/go.mod.edit6
66 ! go mod edit -replace=x.1=y.1/@v2
67 stderr '^go: -replace=x.1=y.1/@v2: invalid new path: malformed import path "y.1/": trailing slash$'
68
69 # go mod edit -fmt
70 cp $WORK/go.mod.badfmt go.mod
71 go mod edit -fmt -print # -print should avoid writing file
72 cmpenv stdout $WORK/go.mod.goodfmt
73 cmp go.mod $WORK/go.mod.badfmt
74 go mod edit -fmt # without -print, should write file (and nothing to stdout)
75 ! stdout .
76 cmpenv go.mod $WORK/go.mod.goodfmt
77
78 # go mod edit -module
79 cd $WORK/m
80 go mod init a.a/b/c
81 go mod edit -module x.x/y/z
82 cmpenv go.mod go.mod.edit
83
84 # golang.org/issue/30513: don't require go-gettable module paths.
85 cd $WORK/local
86 go mod init foo
87 go mod edit -module local-only -require=other-local@v1.0.0 -replace other-local@v1.0.0=./other
88 cmpenv go.mod go.mod.edit
89
90 # go mod edit -godebug
91 cd $WORK/g
92 cp go.mod.start go.mod
93 go mod edit -godebug key=value
94 cmpenv go.mod go.mod.edit
95 go mod edit -dropgodebug key2
96 cmpenv go.mod go.mod.edit
97 go mod edit -dropgodebug key
98 cmpenv go.mod go.mod.start
99
100 -- x.go --
101 package x
102
103 -- w/w.go --
104 package w
105
106 -- $WORK/go.mod.init --
107 module x.x/y/z
108
109 go $goversion
110 -- $WORK/go.mod.edit1 --
111 module x.x/y/z
112
113 go $goversion
114
115 require x.1 v1.0.0
116
117 exclude (
118 x.1 v1.2.0
119 x.1 v1.2.1
120 x.1 v2.0.0+incompatible
121 )
122
123 replace (
124 x.1 v1.3.0 => y.1 v1.4.0
125 x.1 v1.4.0 => ../z
126 )
127
128 retract (
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 --
135 module x.x/y/z
136
137 go $goversion
138
139 exclude x.1 v1.2.0
140
141 replace x.1 v1.4.0 => ../z
142
143 retract (
144 v1.6.0
145 [v1.3.0, v1.4.0]
146 )
147
148 require 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 --
190 module x.x/y/z
191
192 go $goversion
193
194 exclude x.1 v1.2.0
195
196 replace (
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
201 retract (
202 v1.6.0
203 [v1.3.0, v1.4.0]
204 )
205
206 require x.3 v1.99.0
207 -- $WORK/go.mod.edit4 --
208 module x.x/y/z
209
210 go $goversion
211
212 exclude x.1 v1.2.0
213
214 replace x.1 => y.1/v2 v2.3.6
215
216 retract (
217 v1.6.0
218 [v1.3.0, v1.4.0]
219 )
220
221 require x.3 v1.99.0
222 -- $WORK/go.mod.edit5 --
223 module x.x/y/z
224
225 go $goversion
226
227 exclude x.1 v1.2.0
228
229 retract (
230 v1.6.0
231 [v1.3.0, v1.4.0]
232 )
233
234 require x.3 v1.99.0
235 -- $WORK/go.mod.edit6 --
236 module x.x/y/z
237
238 go $goversion
239
240 exclude x.1 v1.2.0
241
242 retract (
243 v1.6.0
244 [v1.3.0, v1.4.0]
245 )
246
247 require x.3 v1.99.0
248
249 replace x.1 => ../y.1/@v2
250 -- $WORK/local/go.mod.edit --
251 module local-only
252
253 go $goversion
254
255 require other-local v1.0.0
256
257 replace other-local v1.0.0 => ./other
258 -- $WORK/go.mod.badfmt --
259 module x.x/y/z
260
261 go 1.10
262
263 exclude x.1 v1.2.0
264
265 replace x.1 => y.1/v2 v2.3.6
266
267 require x.3 v1.99.0
268
269 retract [ "v1.8.1" , "v1.8.2" ]
270 -- $WORK/go.mod.goodfmt --
271 module x.x/y/z
272
273 go 1.10
274
275 exclude x.1 v1.2.0
276
277 replace x.1 => y.1/v2 v2.3.6
278
279 require x.3 v1.99.0
280
281 retract [v1.8.1, v1.8.2]
282 -- $WORK/m/go.mod.edit --
283 module x.x/y/z
284
285 go $goversion
286 -- $WORK/go.mod.retractrationale --
287 module x.x/y/z
288
289 go 1.15
290
291 // a
292 retract v1.0.0
293
294 // b
295 retract (
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
328 module 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 --
352 module g
353
354 go 1.10
355 -- $WORK/g/go.mod.edit --
356 module g
357
358 go 1.10
359
360 godebug key=value
361
View as plain text