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

View as plain text