]> Cypherpunks.ru repositories - gostls13.git/blob - src/cmd/go/testdata/script/mod_edit.txt
cmd/go: handle '@' in local path when running 'go mod edit -replace'
[gostls13.git] / src / cmd / go / testdata / script / mod_edit.txt
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 -- x.go --
91 package x
92
93 -- w/w.go --
94 package w
95
96 -- $WORK/go.mod.init --
97 module x.x/y/z
98
99 go $goversion
100 -- $WORK/go.mod.edit1 --
101 module x.x/y/z
102
103 go $goversion
104
105 require x.1 v1.0.0
106
107 exclude (
108         x.1 v1.2.0
109         x.1 v1.2.1
110         x.1 v2.0.0+incompatible
111 )
112
113 replace (
114         x.1 v1.3.0 => y.1 v1.4.0
115         x.1 v1.4.0 => ../z
116 )
117
118 retract (
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 --
125 module x.x/y/z
126
127 go $goversion
128
129 exclude x.1 v1.2.0
130
131 replace x.1 v1.4.0 => ../z
132
133 retract (
134         v1.6.0
135         [v1.3.0, v1.4.0]
136 )
137
138 require 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 --
180 module x.x/y/z
181
182 go $goversion
183
184 exclude x.1 v1.2.0
185
186 replace (
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
191 retract (
192         v1.6.0
193         [v1.3.0, v1.4.0]
194 )
195
196 require x.3 v1.99.0
197 -- $WORK/go.mod.edit4 --
198 module x.x/y/z
199
200 go $goversion
201
202 exclude x.1 v1.2.0
203
204 replace x.1 => y.1/v2 v2.3.6
205
206 retract (
207         v1.6.0
208         [v1.3.0, v1.4.0]
209 )
210
211 require x.3 v1.99.0
212 -- $WORK/go.mod.edit5 --
213 module x.x/y/z
214
215 go $goversion
216
217 exclude x.1 v1.2.0
218
219 retract (
220         v1.6.0
221         [v1.3.0, v1.4.0]
222 )
223
224 require x.3 v1.99.0
225 -- $WORK/go.mod.edit6 --
226 module x.x/y/z
227
228 go $goversion
229
230 exclude x.1 v1.2.0
231
232 retract (
233         v1.6.0
234         [v1.3.0, v1.4.0]
235 )
236
237 require x.3 v1.99.0
238
239 replace x.1 => ../y.1/@v2
240 -- $WORK/local/go.mod.edit --
241 module local-only
242
243 go $goversion
244
245 require other-local v1.0.0
246
247 replace other-local v1.0.0 => ./other
248 -- $WORK/go.mod.badfmt --
249 module     x.x/y/z
250
251 go 1.10
252
253 exclude x.1     v1.2.0
254
255 replace x.1    =>   y.1/v2 v2.3.6
256
257 require x.3   v1.99.0
258
259 retract [  "v1.8.1" , "v1.8.2" ]
260 -- $WORK/go.mod.goodfmt --
261 module x.x/y/z
262
263 go 1.10
264
265 exclude x.1 v1.2.0
266
267 replace x.1 => y.1/v2 v2.3.6
268
269 require x.3 v1.99.0
270
271 retract [v1.8.1, v1.8.2]
272 -- $WORK/m/go.mod.edit --
273 module x.x/y/z
274
275 go $goversion
276 -- $WORK/go.mod.retractrationale --
277 module x.x/y/z
278
279 go 1.15
280
281 // a
282 retract v1.0.0
283
284 // b
285 retract (
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
318 module 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 }