Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     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 mod: -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 mod: -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 mod: -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 mod: -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 mod: -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  
    65  # go mod edit -fmt
    66  cp $WORK/go.mod.badfmt go.mod
    67  go mod edit -fmt -print # -print should avoid writing file
    68  cmpenv stdout $WORK/go.mod.goodfmt
    69  cmp go.mod $WORK/go.mod.badfmt
    70  go mod edit -fmt # without -print, should write file (and nothing to stdout)
    71  ! stdout .
    72  cmpenv go.mod $WORK/go.mod.goodfmt
    73  
    74  # go mod edit -module
    75  cd $WORK/m
    76  go mod init a.a/b/c
    77  go mod edit -module x.x/y/z
    78  cmpenv go.mod go.mod.edit
    79  
    80  # golang.org/issue/30513: don't require go-gettable module paths.
    81  cd $WORK/local
    82  go mod init foo
    83  go mod edit -module local-only -require=other-local@v1.0.0 -replace other-local@v1.0.0=./other
    84  cmpenv go.mod go.mod.edit
    85  
    86  -- x.go --
    87  package x
    88  
    89  -- w/w.go --
    90  package w
    91  
    92  -- $WORK/go.mod.init --
    93  module x.x/y/z
    94  
    95  go $goversion
    96  -- $WORK/go.mod.edit1 --
    97  module x.x/y/z
    98  
    99  go $goversion
   100  
   101  require x.1 v1.0.0
   102  
   103  exclude (
   104  	x.1 v1.2.0
   105  	x.1 v1.2.1
   106  	x.1 v2.0.0+incompatible
   107  )
   108  
   109  replace (
   110  	x.1 v1.3.0 => y.1 v1.4.0
   111  	x.1 v1.4.0 => ../z
   112  )
   113  
   114  retract (
   115  	v1.6.0
   116  	[v1.3.0, v1.4.0]
   117  	[v1.1.0, v1.2.0]
   118  	v1.0.0
   119  )
   120  -- $WORK/go.mod.edit2 --
   121  module x.x/y/z
   122  
   123  go $goversion
   124  
   125  exclude x.1 v1.2.0
   126  
   127  replace x.1 v1.4.0 => ../z
   128  
   129  retract (
   130  	v1.6.0
   131  	[v1.3.0, v1.4.0]
   132  )
   133  
   134  require x.3 v1.99.0
   135  -- $WORK/go.mod.json --
   136  {
   137  	"Module": {
   138  		"Path": "x.x/y/z"
   139  	},
   140  	"Go": "$goversion",
   141  	"Require": [
   142  		{
   143  			"Path": "x.3",
   144  			"Version": "v1.99.0"
   145  		}
   146  	],
   147  	"Exclude": [
   148  		{
   149  			"Path": "x.1",
   150  			"Version": "v1.2.0"
   151  		}
   152  	],
   153  	"Replace": [
   154  		{
   155  			"Old": {
   156  				"Path": "x.1",
   157  				"Version": "v1.4.0"
   158  			},
   159  			"New": {
   160  				"Path": "../z"
   161  			}
   162  		}
   163  	],
   164  	"Retract": [
   165  		{
   166  			"Low": "v1.6.0",
   167  			"High": "v1.6.0"
   168  		},
   169  		{
   170  			"Low": "v1.3.0",
   171  			"High": "v1.4.0"
   172  		}
   173  	]
   174  }
   175  -- $WORK/go.mod.edit3 --
   176  module x.x/y/z
   177  
   178  go $goversion
   179  
   180  exclude x.1 v1.2.0
   181  
   182  replace (
   183  	x.1 v1.3.0 => y.1/v2 v2.3.5
   184  	x.1 v1.4.0 => y.1/v2 v2.3.5
   185  )
   186  
   187  retract (
   188  	v1.6.0
   189  	[v1.3.0, v1.4.0]
   190  )
   191  
   192  require x.3 v1.99.0
   193  -- $WORK/go.mod.edit4 --
   194  module x.x/y/z
   195  
   196  go $goversion
   197  
   198  exclude x.1 v1.2.0
   199  
   200  replace x.1 => y.1/v2 v2.3.6
   201  
   202  retract (
   203  	v1.6.0
   204  	[v1.3.0, v1.4.0]
   205  )
   206  
   207  require x.3 v1.99.0
   208  -- $WORK/go.mod.edit5 --
   209  module x.x/y/z
   210  
   211  go $goversion
   212  
   213  exclude x.1 v1.2.0
   214  
   215  retract (
   216  	v1.6.0
   217  	[v1.3.0, v1.4.0]
   218  )
   219  
   220  require x.3 v1.99.0
   221  -- $WORK/local/go.mod.edit --
   222  module local-only
   223  
   224  go $goversion
   225  
   226  require other-local v1.0.0
   227  
   228  replace other-local v1.0.0 => ./other
   229  -- $WORK/go.mod.badfmt --
   230  module     x.x/y/z
   231  
   232  go 1.10
   233  
   234  exclude x.1     v1.2.0
   235  
   236  replace x.1    =>   y.1/v2 v2.3.6
   237  
   238  require x.3   v1.99.0
   239  
   240  retract [  "v1.8.1" , "v1.8.2" ]
   241  -- $WORK/go.mod.goodfmt --
   242  module x.x/y/z
   243  
   244  go 1.10
   245  
   246  exclude x.1 v1.2.0
   247  
   248  replace x.1 => y.1/v2 v2.3.6
   249  
   250  require x.3 v1.99.0
   251  
   252  retract [v1.8.1, v1.8.2]
   253  -- $WORK/m/go.mod.edit --
   254  module x.x/y/z
   255  
   256  go $goversion
   257  -- $WORK/go.mod.retractrationale --
   258  module x.x/y/z
   259  
   260  go 1.15
   261  
   262  // a
   263  retract v1.0.0
   264  
   265  // b
   266  retract (
   267    v1.0.1
   268    v1.0.2 // c
   269  )
   270  -- $WORK/go.mod.retractrationale.json --
   271  {
   272  	"Module": {
   273  		"Path": "x.x/y/z"
   274  	},
   275  	"Go": "1.15",
   276  	"Require": null,
   277  	"Exclude": null,
   278  	"Replace": null,
   279  	"Retract": [
   280  		{
   281  			"Low": "v1.0.0",
   282  			"High": "v1.0.0",
   283  			"Rationale": "a"
   284  		},
   285  		{
   286  			"Low": "v1.0.1",
   287  			"High": "v1.0.1",
   288  			"Rationale": "b"
   289  		},
   290  		{
   291  			"Low": "v1.0.2",
   292  			"High": "v1.0.2",
   293  			"Rationale": "c"
   294  		}
   295  	]
   296  }
   297  -- $WORK/go.mod.deprecation --
   298  // Deprecated: and the new one is not ready yet
   299  module m
   300  -- $WORK/go.mod.deprecation.json --
   301  {
   302  	"Module": {
   303  		"Path": "m",
   304  		"Deprecated": "and the new one is not ready yet"
   305  	},
   306  	"Require": null,
   307  	"Exclude": null,
   308  	"Replace": null,
   309  	"Retract": null
   310  }
   311  -- $WORK/go.mod.empty --
   312  -- $WORK/go.mod.empty.json --
   313  {
   314  	"Module": {
   315  		"Path": ""
   316  	},
   317  	"Require": null,
   318  	"Exclude": null,
   319  	"Replace": null,
   320  	"Retract": null
   321  }
   322  

View as plain text