github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/mod_edit.txt (about)

     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 -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z'
    20  cmpenv go.mod $WORK/go.mod.edit1
    21  go mod edit -droprequire=x.1 -dropexclude=x.1@v1.2.1 -dropreplace=x.1@v1.3.0 -require=x.3@v1.99.0
    22  cmpenv go.mod $WORK/go.mod.edit2
    23  
    24  # go mod edit -json
    25  go mod edit -json
    26  cmpenv stdout $WORK/go.mod.json
    27  
    28  # go mod edit -json (empty mod file)
    29  go mod edit -json $WORK/go.mod.empty
    30  cmp stdout $WORK/go.mod.empty.json
    31  
    32  # go mod edit -replace
    33  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
    34  cmpenv go.mod $WORK/go.mod.edit3
    35  go mod edit -replace=x.1=y.1/v2@v2.3.6
    36  cmpenv go.mod $WORK/go.mod.edit4
    37  go mod edit -dropreplace=x.1
    38  cmpenv go.mod $WORK/go.mod.edit5
    39  
    40  # go mod edit -fmt
    41  cp $WORK/go.mod.badfmt go.mod
    42  go mod edit -fmt -print # -print should avoid writing file
    43  cmpenv stdout $WORK/go.mod.edit6
    44  cmp go.mod $WORK/go.mod.badfmt
    45  go mod edit -fmt # without -print, should write file (and nothing to stdout)
    46  ! stdout .
    47  cmpenv go.mod $WORK/go.mod.edit6
    48  
    49  # go mod edit -module
    50  cd $WORK/m
    51  go mod init a.a/b/c
    52  go mod edit -module x.x/y/z
    53  cmpenv go.mod go.mod.edit
    54  
    55  # golang.org/issue/30513: don't require go-gettable module paths.
    56  cd $WORK/local
    57  go mod init foo
    58  go mod edit -module local-only -require=other-local@v1.0.0 -replace other-local@v1.0.0=./other
    59  cmpenv go.mod go.mod.edit
    60  
    61  -- x.go --
    62  package x
    63  
    64  -- w/w.go --
    65  package w
    66  
    67  -- $WORK/go.mod.init --
    68  module x.x/y/z
    69  
    70  go $goversion
    71  -- $WORK/go.mod.edit1 --
    72  module x.x/y/z
    73  
    74  go $goversion
    75  
    76  require x.1 v1.0.0
    77  
    78  exclude (
    79  	x.1 v1.2.0
    80  	x.1 v1.2.1
    81  )
    82  
    83  replace (
    84  	x.1 v1.3.0 => y.1 v1.4.0
    85  	x.1 v1.4.0 => ../z
    86  )
    87  -- $WORK/go.mod.edit2 --
    88  module x.x/y/z
    89  
    90  go $goversion
    91  
    92  exclude x.1 v1.2.0
    93  
    94  replace x.1 v1.4.0 => ../z
    95  
    96  require x.3 v1.99.0
    97  -- $WORK/go.mod.json --
    98  {
    99  	"Module": {
   100  		"Path": "x.x/y/z"
   101  	},
   102  	"Go": "$goversion",
   103  	"Require": [
   104  		{
   105  			"Path": "x.3",
   106  			"Version": "v1.99.0"
   107  		}
   108  	],
   109  	"Exclude": [
   110  		{
   111  			"Path": "x.1",
   112  			"Version": "v1.2.0"
   113  		}
   114  	],
   115  	"Replace": [
   116  		{
   117  			"Old": {
   118  				"Path": "x.1",
   119  				"Version": "v1.4.0"
   120  			},
   121  			"New": {
   122  				"Path": "../z"
   123  			}
   124  		}
   125  	]
   126  }
   127  -- $WORK/go.mod.edit3 --
   128  module x.x/y/z
   129  
   130  go $goversion
   131  
   132  exclude x.1 v1.2.0
   133  
   134  replace (
   135  	x.1 v1.3.0 => y.1/v2 v2.3.5
   136  	x.1 v1.4.0 => y.1/v2 v2.3.5
   137  )
   138  
   139  require x.3 v1.99.0
   140  -- $WORK/go.mod.edit4 --
   141  module x.x/y/z
   142  
   143  go $goversion
   144  
   145  exclude x.1 v1.2.0
   146  
   147  replace x.1 => y.1/v2 v2.3.6
   148  
   149  require x.3 v1.99.0
   150  -- $WORK/go.mod.edit5 --
   151  module x.x/y/z
   152  
   153  go $goversion
   154  
   155  exclude x.1 v1.2.0
   156  
   157  require x.3 v1.99.0
   158  -- $WORK/go.mod.edit6 --
   159  module x.x/y/z
   160  
   161  go 1.10
   162  
   163  exclude x.1 v1.2.0
   164  
   165  replace x.1 => y.1/v2 v2.3.6
   166  
   167  require x.3 v1.99.0
   168  -- $WORK/local/go.mod.edit --
   169  module local-only
   170  
   171  go $goversion
   172  
   173  require other-local v1.0.0
   174  
   175  replace other-local v1.0.0 => ./other
   176  -- $WORK/go.mod.badfmt --
   177  module     x.x/y/z
   178  
   179  go 1.10
   180  
   181  exclude x.1     v1.2.0
   182  
   183  replace x.1    =>   y.1/v2 v2.3.6
   184  
   185  require x.3   v1.99.0
   186  -- $WORK/m/go.mod.edit --
   187  module x.x/y/z
   188  
   189  go $goversion
   190  -- $WORK/go.mod.empty --
   191  -- $WORK/go.mod.empty.json --
   192  {
   193  	"Module": {
   194  		"Path": ""
   195  	},
   196  	"Require": null,
   197  	"Exclude": null,
   198  	"Replace": null
   199  }