github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/src/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  cmp go.mod $WORK/go.mod.init
    14  
    15  ! go mod init
    16  cmp 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  cmp 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  cmp go.mod $WORK/go.mod.edit2
    23  
    24  # go mod edit -json
    25  go mod edit -json
    26  cmp stdout $WORK/go.mod.json
    27  
    28  # go mod edit -replace
    29  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
    30  cmp go.mod $WORK/go.mod.edit3
    31  go mod edit -replace=x.1=y.1/v2@v2.3.6
    32  cmp go.mod $WORK/go.mod.edit4
    33  go mod edit -dropreplace=x.1
    34  cmp go.mod $WORK/go.mod.edit5
    35  
    36  # go mod edit -fmt
    37  cp $WORK/go.mod.badfmt go.mod
    38  go mod edit -fmt -print # -print should avoid writing file
    39  cmp stdout $WORK/go.mod.edit4
    40  cmp go.mod $WORK/go.mod.badfmt
    41  go mod edit -fmt # without -print, should write file (and nothing to stdout)
    42  ! stdout .
    43  cmp go.mod $WORK/go.mod.edit4
    44  
    45  -- x.go --
    46  package x
    47  
    48  -- w/w.go --
    49  package w
    50  
    51  -- $WORK/go.mod.init --
    52  module x.x/y/z
    53  -- $WORK/go.mod.edit1 --
    54  module x.x/y/z
    55  
    56  require x.1 v1.0.0
    57  
    58  exclude (
    59  	x.1 v1.2.0
    60  	x.1 v1.2.1
    61  )
    62  
    63  replace (
    64  	x.1 v1.3.0 => y.1 v1.4.0
    65  	x.1 v1.4.0 => ../z
    66  )
    67  -- $WORK/go.mod.edit2 --
    68  module x.x/y/z
    69  
    70  exclude x.1 v1.2.0
    71  
    72  replace x.1 v1.4.0 => ../z
    73  
    74  require x.3 v1.99.0
    75  -- $WORK/go.mod.json --
    76  {
    77  	"Module": {
    78  		"Path": "x.x/y/z"
    79  	},
    80  	"Require": [
    81  		{
    82  			"Path": "x.3",
    83  			"Version": "v1.99.0"
    84  		}
    85  	],
    86  	"Exclude": [
    87  		{
    88  			"Path": "x.1",
    89  			"Version": "v1.2.0"
    90  		}
    91  	],
    92  	"Replace": [
    93  		{
    94  			"Old": {
    95  				"Path": "x.1",
    96  				"Version": "v1.4.0"
    97  			},
    98  			"New": {
    99  				"Path": "../z"
   100  			}
   101  		}
   102  	]
   103  }
   104  -- $WORK/go.mod.edit3 --
   105  module x.x/y/z
   106  
   107  exclude x.1 v1.2.0
   108  
   109  replace (
   110  	x.1 v1.3.0 => y.1/v2 v2.3.5
   111  	x.1 v1.4.0 => y.1/v2 v2.3.5
   112  )
   113  
   114  require x.3 v1.99.0
   115  -- $WORK/go.mod.edit4 --
   116  module x.x/y/z
   117  
   118  exclude x.1 v1.2.0
   119  
   120  replace x.1 => y.1/v2 v2.3.6
   121  
   122  require x.3 v1.99.0
   123  -- $WORK/go.mod.edit5 --
   124  module x.x/y/z
   125  
   126  exclude x.1 v1.2.0
   127  
   128  require x.3 v1.99.0
   129  -- $WORK/go.mod.badfmt --
   130  module     x.x/y/z
   131  
   132  exclude x.1     v1.2.0
   133  
   134  replace x.1    =>   y.1/v2 v2.3.6
   135  
   136  require x.3   v1.99.0