...

Text file src/cmd/go/testdata/script/mod_edit.txt

Documentation: cmd/go/testdata/script

     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# go mod edit -tool
   101cd $WORK/h
   102cp go.mod.start go.mod
   103go mod edit -tool example.com/tool
   104cmpenv go.mod go.mod.edit
   105go mod edit -droptool example.com/tool2
   106cmpenv go.mod go.mod.edit
   107go mod edit -droptool example.com/tool
   108cmpenv go.mod go.mod.start
   109
   110# go mod edit -ignore
   111cd $WORK/i
   112cp go.mod.start go.mod
   113go mod edit -ignore example.com/ignore
   114cmpenv go.mod go.mod.edit
   115go mod edit -dropignore example.com/ignore2
   116cmpenv go.mod go.mod.edit
   117go mod edit -dropignore example.com/ignore
   118cmpenv go.mod go.mod.start
   119
   120-- x.go --
   121package x
   122
   123-- w/w.go --
   124package w
   125
   126-- $WORK/go.mod.init --
   127module x.x/y/z
   128
   129go $goversion
   130-- $WORK/go.mod.edit1 --
   131module x.x/y/z
   132
   133go $goversion
   134
   135require x.1 v1.0.0
   136
   137exclude (
   138	x.1 v1.2.0
   139	x.1 v1.2.1
   140	x.1 v2.0.0+incompatible
   141)
   142
   143replace (
   144	x.1 v1.3.0 => y.1 v1.4.0
   145	x.1 v1.4.0 => ../z
   146)
   147
   148retract (
   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 --
   155module x.x/y/z
   156
   157go $goversion
   158
   159exclude x.1 v1.2.0
   160
   161replace x.1 v1.4.0 => ../z
   162
   163retract (
   164	v1.6.0
   165	[v1.3.0, v1.4.0]
   166)
   167
   168require 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 --
   212module x.x/y/z
   213
   214go $goversion
   215
   216exclude x.1 v1.2.0
   217
   218replace (
   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
   223retract (
   224	v1.6.0
   225	[v1.3.0, v1.4.0]
   226)
   227
   228require x.3 v1.99.0
   229-- $WORK/go.mod.edit4 --
   230module x.x/y/z
   231
   232go $goversion
   233
   234exclude x.1 v1.2.0
   235
   236replace x.1 => y.1/v2 v2.3.6
   237
   238retract (
   239	v1.6.0
   240	[v1.3.0, v1.4.0]
   241)
   242
   243require x.3 v1.99.0
   244-- $WORK/go.mod.edit5 --
   245module x.x/y/z
   246
   247go $goversion
   248
   249exclude x.1 v1.2.0
   250
   251retract (
   252	v1.6.0
   253	[v1.3.0, v1.4.0]
   254)
   255
   256require x.3 v1.99.0
   257-- $WORK/go.mod.edit6 --
   258module x.x/y/z
   259
   260go $goversion
   261
   262exclude x.1 v1.2.0
   263
   264retract (
   265	v1.6.0
   266	[v1.3.0, v1.4.0]
   267)
   268
   269require x.3 v1.99.0
   270
   271replace x.1 => ../y.1/@v2
   272-- $WORK/local/go.mod.edit --
   273module local-only
   274
   275go $goversion
   276
   277require other-local v1.0.0
   278
   279replace other-local v1.0.0 => ./other
   280-- $WORK/go.mod.badfmt --
   281module     x.x/y/z
   282
   283go 1.10
   284
   285exclude x.1     v1.2.0
   286
   287replace x.1    =>   y.1/v2 v2.3.6
   288
   289require x.3   v1.99.0
   290
   291retract [  "v1.8.1" , "v1.8.2" ]
   292-- $WORK/go.mod.goodfmt --
   293module x.x/y/z
   294
   295go 1.10
   296
   297exclude x.1 v1.2.0
   298
   299replace x.1 => y.1/v2 v2.3.6
   300
   301require x.3 v1.99.0
   302
   303retract [v1.8.1, v1.8.2]
   304-- $WORK/m/go.mod.edit --
   305module x.x/y/z
   306
   307go $goversion
   308-- $WORK/go.mod.retractrationale --
   309module x.x/y/z
   310
   311go 1.15
   312
   313// a
   314retract v1.0.0
   315
   316// b
   317retract (
   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
   352module 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 --
   380module g
   381
   382go 1.10
   383-- $WORK/g/go.mod.edit --
   384module g
   385
   386go 1.10
   387
   388godebug key=value
   389-- $WORK/h/go.mod.start --
   390module g
   391
   392go 1.24
   393-- $WORK/h/go.mod.edit --
   394module g
   395
   396go 1.24
   397
   398tool example.com/tool
   399-- $WORK/i/go.mod.start --
   400module g
   401
   402go 1.24
   403-- $WORK/i/go.mod.edit --
   404module g
   405
   406go 1.24
   407
   408ignore example.com/ignore

View as plain text