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