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
8 stderr 'cannot determine module path'
12 stderr 'creating new go.mod: module x.x/y/z'
13 cmpenv go.mod $WORK/go.mod.init
16 cmpenv go.mod $WORK/go.mod.init
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
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$'
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\)$'
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$'
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$'
39 cmpenv go.mod $WORK/go.mod.edit2
43 cmpenv stdout $WORK/go.mod.json
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
49 # go mod edit -json (deprecation)
50 go mod edit -json $WORK/go.mod.deprecation
51 cmp stdout $WORK/go.mod.deprecation.json
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
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$'
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)
76 cmpenv go.mod $WORK/go.mod.goodfmt
81 go mod edit -module x.x/y/z
82 cmpenv go.mod go.mod.edit
84 # golang.org/issue/30513: don't require go-gettable module paths.
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
96 -- $WORK/go.mod.init --
100 -- $WORK/go.mod.edit1 --
110 x.1 v2.0.0+incompatible
114 x.1 v1.3.0 => y.1 v1.4.0
124 -- $WORK/go.mod.edit2 --
131 replace x.1 v1.4.0 => ../z
139 -- $WORK/go.mod.json --
179 -- $WORK/go.mod.edit3 --
187 x.1 v1.3.0 => y.1/v2 v2.3.5
188 x.1 v1.4.0 => y.1/v2 v2.3.5
197 -- $WORK/go.mod.edit4 --
204 replace x.1 => y.1/v2 v2.3.6
212 -- $WORK/go.mod.edit5 --
225 -- $WORK/go.mod.edit6 --
239 replace x.1 => ../y.1/@v2
240 -- $WORK/local/go.mod.edit --
245 require other-local v1.0.0
247 replace other-local v1.0.0 => ./other
248 -- $WORK/go.mod.badfmt --
255 replace x.1 => y.1/v2 v2.3.6
259 retract [ "v1.8.1" , "v1.8.2" ]
260 -- $WORK/go.mod.goodfmt --
267 replace x.1 => y.1/v2 v2.3.6
271 retract [v1.8.1, v1.8.2]
272 -- $WORK/m/go.mod.edit --
276 -- $WORK/go.mod.retractrationale --
289 -- $WORK/go.mod.retractrationale.json --
316 -- $WORK/go.mod.deprecation --
317 // Deprecated: and the new one is not ready yet
319 -- $WORK/go.mod.deprecation.json --
323 "Deprecated": "and the new one is not ready yet"
330 -- $WORK/go.mod.empty --
331 -- $WORK/go.mod.empty.json --