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

     1  # Test overlays that affect go.mod files
     2  
     3  # The go.mod file can exist only in the overlay.
     4  cd $WORK/gopath/src/no-go-mod
     5  go list -overlay overlay.json .
     6  stdout example.com/simple
     7  
     8  # Check content of overlaid go.mod is used.
     9  cd $WORK/gopath/src/overlay-go-mod
    10  go list -overlay overlay.json .
    11  stdout use.this/module/name
    12  
    13  # Check content of overlaid go.mod in a replacement module is used.
    14  # The go.mod in the replacement module is missing a requirement
    15  # that the overlay has, so it will fail to list without the overlay.
    16  cd $WORK/gopath/src/overlay-replaced-go-mod
    17  ! go list -deps .
    18  go list -deps -overlay overlay.json .
    19  
    20  # Overlaid go.mod is not rewritten by 'go get'.
    21  cd $WORK/gopath/src/get-doesnt-add-dep
    22  cp $WORK/overlay/get_doesnt_add_dep_go_mod $WORK/want_go_mod
    23  ! go get -overlay overlay.json .
    24  stderr '^go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay$'
    25  cmp $WORK/overlay/get_doesnt_add_dep_go_mod $WORK/want_go_mod
    26  
    27  # Content of overlaid go.sum is used.
    28  # The go.sum in the module directory has garbage values for its
    29  # hashes, but the overlaid file has the correct values. If
    30  # the correct go.sum is used with the overlay, 'go get .' should
    31  # not report a security error.
    32  cd $WORK/gopath/src/overlay-sum-used
    33  ! go get .
    34  stderr 'SECURITY ERROR'
    35  ! go mod verify
    36  stderr 'SECURITY ERROR'
    37  go get -overlay overlay.json .
    38  go mod verify -overlay overlay.json
    39  # Overlaid go.sum is not rewritten.
    40  # Copy an incomplete file to the overlay file, and expect an error
    41  # attempting to update the file
    42  cp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums
    43  ! go get -overlay overlay.json .
    44  stderr '^go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay$'
    45  cmp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums
    46  ! go mod tidy -overlay overlay.json
    47  stderr '^go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay$'
    48  cmp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums
    49  
    50  # -overlay works with -modfile.
    51  # There's an empty go.mod file in the directory, and the file alternate.mod is
    52  # overlaid to the true go.mod file, so the -modfile flag and the overlay
    53  # mechanism need to work together to determine the name of the module.
    54  cd $WORK/gopath/src/overlay-and-dash-modfile
    55  go list -modfile=alternate.mod -overlay overlay.json .
    56  stdout 'found.the/module'
    57  # Even with -modfile, overlaid files can't be opened for write.
    58  ! go get -modfile=alternate.mod -overlay overlay.json rsc.io/quote
    59  stderr '^go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay$'
    60  
    61  # Carving out a module by adding an overlaid go.mod file
    62  cd $WORK/gopath/src/carve
    63  go list ./... # without an overlay, hasmod is carved out and nomod isn't
    64  stdout carve/nomod
    65  ! stdout carve/hasmod
    66  go list -overlay overlay_carve_module.json ./... # The overlay carves out nomod, leaving nothing
    67  ! stdout .
    68  stderr 'matched no packages'
    69  go list -overlay overlay_uncarve_module.json ./... # The overlay uncarves out hasmod
    70  stdout carve/nomod
    71  stdout carve/hasmod
    72  
    73  # Carving out a module by adding an overlaid go.mod file and using
    74  # -modfile to write to that file.
    75  cd $WORK/gopath/src/carve2/nomod
    76  go list -overlay overlay.json all
    77  ! stdout ^carve2$
    78  stdout ^carve2/nomod$
    79  # Editing go.mod file fails because overlay is read only
    80  ! go get -overlay overlay.json rsc.io/quote
    81  stderr '^go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay$'
    82  ! grep rsc.io/quote $WORK/overlay/carve2-nomod-go.mod
    83  # Editing go.mod file succeeds because we use -modfile to redirect to same file
    84  go get -overlay overlay.json -modfile $WORK/overlay/carve2-nomod-go.mod rsc.io/quote
    85  grep rsc.io/quote $WORK/overlay/carve2-nomod-go.mod
    86  
    87  -- no-go-mod/file.go --
    88  package simple
    89  -- no-go-mod/overlay.json --
    90  {
    91  	"Replace": {
    92  		"go.mod": "../../../overlay/simple_go_mod"
    93  	}
    94  }
    95  -- $WORK/overlay/simple_go_mod --
    96  module example.com/simple
    97  -- overlay-go-mod/file.go --
    98  package name
    99  -- overlay-go-mod/go.mod --
   100  module dont.use/this/module/name
   101  -- overlay-go-mod/overlay.json --
   102  {
   103  	"Replace": {
   104  		"go.mod": "../../../overlay/use_this_go_mod"
   105  	}
   106  }
   107  -- $WORK/overlay/use_this_go_mod --
   108  module use.this/module/name
   109  -- overlay-replaced-go-mod/go.mod --
   110  module m
   111  
   112  go 1.15
   113  
   114  require replaced/mod v1.0.0
   115  replace replaced/mod v1.0.0 => ../replaced-mod
   116  replace dep/mod v1.0.0 => ../dep-mod
   117  -- overlay-replaced-go-mod/source.go --
   118  package m
   119  
   120  import "replaced/mod/foo"
   121  
   122  func main() {
   123  	foo.f()
   124  }
   125  -- overlay-replaced-go-mod/overlay.json --
   126  {
   127  	"Replace": {
   128  		"../replaced-mod/go.mod": "../../../overlay/replacement_module_go_mod"
   129  	}
   130  }
   131  -- replaced-mod/go.mod --
   132  module replaced/mod
   133  -- replaced-mod/foo/foo.go --
   134  package foo
   135  
   136  import "dep/mod/foo"
   137  
   138  func f() { foo.g() }
   139  -- dep-mod/go.mod --
   140  invalid
   141  -- dep-mod/foo/foo.go --
   142  package foo
   143  
   144  func g() { fmt.Println("hello") }
   145  -- $WORK/overlay/replacement_module_go_mod --
   146  module replaced/mod
   147  
   148  require dep/mod v1.0.0
   149  
   150  -- get-doesnt-add-dep/overlay.json --
   151  {
   152  	"Replace": {
   153  		"go.mod": "../../../overlay/get_doesnt_add_dep_go_mod"
   154  	}
   155  }
   156  -- get-doesnt-add-dep/p.go --
   157  package p
   158  
   159  import "dependency/mod"
   160  
   161  func f() { mod.G() }
   162  -- get-doesnt-add-dep-dependency/go.mod --
   163  module dependency/mod
   164  -- get-doesnt-add-dep-dependency/mod.go --
   165  package mod
   166  
   167  func G() {}
   168  -- $WORK/overlay/get_doesnt_add_dep_go_mod --
   169  module get.doesnt/add/dep
   170  
   171  replace dependency/mod v1.0.0 => ../get-doesnt-add-dep-dependency
   172  -- overlay-sum-used/go.mod --
   173  module overlay.sum/used
   174  
   175  require rsc.io/quote v1.5.0
   176  -- overlay-sum-used/p.go --
   177  package p
   178  
   179  import "rsc.io/quote"
   180  
   181  func f() string {
   182  	return quote.Hello()
   183  }
   184  -- overlay-sum-used/incomplete-sum-file --
   185  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw=
   186  rsc.io/quote v1.5.0 h1:6fJa6E+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE=
   187  rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII=
   188  -- overlay-sum-used/overlay.json --
   189  {
   190  	"Replace": {
   191  		"go.sum": "../../../overlay/overlay-sum-used-correct-sums"
   192  	}
   193  }
   194  -- overlay-sum-used/go.sum --
   195  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:garbage+hash
   196  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:garbage+hash
   197  rsc.io/quote v1.5.0 h1:garbage+hash
   198  rsc.io/quote v1.5.0/go.mod h1:garbage+hash
   199  rsc.io/sampler v1.3.0 h1:garbage+hash
   200  rsc.io/sampler v1.3.0/go.mod h1:garbage+hash
   201  -- $WORK/overlay/overlay-sum-used-correct-sums --
   202  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw=
   203  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
   204  rsc.io/quote v1.5.0 h1:6fJa6E+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE=
   205  rsc.io/quote v1.5.0/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
   206  rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII=
   207  rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
   208  -- overlay-and-dash-modfile/p.go --
   209  package module
   210  -- overlay-and-dash-modfile/go.mod --
   211  -- overlay-and-dash-modfile/overlay.json --
   212  {
   213  	"Replace": {
   214  		"alternate.mod": "../../../overlay/overlay-and-dash-modfile-alternate-mod"
   215  	}
   216  }
   217  -- $WORK/overlay/overlay-and-dash-modfile-alternate-mod --
   218  module found.the/module
   219  -- carve/go.mod --
   220  module carve
   221  -- carve/overlay_carve_module.json --
   222  {
   223  	"Replace": {
   224  		"nomod/go.mod": "../../../overlay/carve-nomod-go-mod"
   225  	}
   226  }
   227  -- carve/overlay_uncarve_module.json --
   228  {
   229  	"Replace": {
   230  		"hasmod/go.mod": ""
   231  	}
   232  }
   233  -- carve/hasmod/a.go --
   234  package hasmod
   235  -- carve/hasmod/go.mod --
   236  module carve/hasmod
   237  -- carve/nomod/b.go --
   238  package nomod
   239  -- $WORK/overlay/carve-nomod-go-mod --
   240  module carve/nomod
   241  -- carve2/go.mod --
   242  module carve2
   243  -- carve2/p.go --
   244  package p
   245  -- carve2/nomod/overlay.json --
   246  {
   247  	"Replace": {
   248  		"go.mod": "../../../../overlay/carve2-nomod-go.mod"
   249  	}
   250  }
   251  -- carve2/nomod/b.go --
   252  package nomod
   253  -- $WORK/overlay/carve2-nomod-go.mod --
   254  module carve2/nomod
   255  

View as plain text