Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     1  env GO111MODULE=on
     2  
     3  # Without vendoring, a build should succeed unless -mod=vendor is set.
     4  [!short] go build
     5  [!short] ! go build -mod=vendor
     6  
     7  # Without vendoring, 'go list' should report the replacement directory for
     8  # a package in a replaced module.
     9  go list -f {{.Dir}} x
    10  stdout 'src[\\/]x'
    11  
    12  # 'go mod vendor' should copy all replaced modules to the vendor directory.
    13  go mod vendor -v
    14  stderr '^# x v1.0.0 => ./x'
    15  stderr '^x'
    16  stderr '^# y v1.0.0 => ./y'
    17  stderr '^y'
    18  stderr '^# z v1.0.0 => ./z'
    19  stderr '^z'
    20  ! stderr '^w'
    21  grep 'a/foo/bar/b\na/foo/bar/c' vendor/modules.txt # must be sorted
    22  
    23  # An explicit '-mod=mod' should ignore the vendor directory.
    24  go list -mod=mod -f {{.Dir}} x
    25  stdout 'src[\\/]x'
    26  
    27  go list -mod=mod -f {{.Dir}} -m x
    28  stdout 'src[\\/]x'
    29  
    30  # An explicit '-mod=vendor' should report package directories within
    31  # the vendor directory.
    32  go list -mod=vendor -f {{.Dir}} x
    33  stdout 'src[\\/]vendor[\\/]x'
    34  
    35  # 'go list -mod=vendor -m' should successfully list vendored modules,
    36  # but should not provide a module directory because no directory contains
    37  # the complete module.
    38  go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x
    39  stdout '^v1.0.0 $'
    40  
    41  # -mod=vendor should cause 'go list' flags that look up versions to fail.
    42  ! go list -mod=vendor -versions -m x
    43  stderr '^go list -m: can''t determine available versions using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
    44  ! go list -mod=vendor -u -m x
    45  stderr '^go list -m: can''t determine available upgrades using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
    46  
    47  # 'go list -mod=vendor -m' on a transitive dependency that does not
    48  # provide vendored packages should give a helpful error rather than
    49  # 'not a known dependency'.
    50  ! go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m diamondright
    51  stderr 'go list -m: module diamondright: can''t resolve module using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)'
    52  
    53  # 'go list -mod=mod' should report packages outside the import graph,
    54  # but 'go list -mod=vendor' should error out for them.
    55  go list -mod=mod -f {{.Dir}} w
    56  stdout 'src[\\/]w'
    57  ! go list -mod=vendor -f {{.Dir}} w
    58  stderr 'src[\\/]vendor[\\/]w'
    59  
    60  go list -mod=mod -f {{.Dir}} diamondright
    61  stdout 'src[\\/]diamondright'
    62  
    63  # Test dependencies should not be copied.
    64  ! exists vendor/x/testdata
    65  ! exists vendor/a/foo/bar/b/ignored.go
    66  ! exists vendor/a/foo/bar/b/main_test.go
    67  
    68  # Licenses and other metadata for each module should be copied
    69  # if any package within their module is copied.
    70  exists vendor/a/foo/AUTHORS.txt
    71  exists vendor/a/foo/CONTRIBUTORS
    72  exists vendor/a/foo/LICENSE
    73  exists vendor/a/foo/PATENTS
    74  exists vendor/a/foo/COPYING
    75  exists vendor/a/foo/COPYLEFT
    76  exists vendor/x/NOTICE!
    77  exists vendor/mysite/myname/mypkg/LICENSE.txt
    78  
    79  ! exists vendor/a/foo/licensed-to-kill
    80  ! exists vendor/w
    81  ! exists vendor/w/LICENSE
    82  ! exists vendor/x/x2
    83  ! exists vendor/x/x2/LICENSE
    84  
    85  [short] stop
    86  
    87  # 'go build' and 'go test' using vendored packages should succeed.
    88  go build -mod=mod
    89  go build -mod=vendor
    90  go test -mod=vendor . ./subdir
    91  go test -mod=vendor ./...
    92  go fmt -mod=vendor ./...
    93  
    94  -- go.mod --
    95  module m
    96  
    97  go 1.13
    98  
    99  require (
   100  	a v1.0.0
   101  	diamondroot v0.0.0
   102  	mysite/myname/mypkg v1.0.0
   103  	w v1.0.0 // indirect
   104  	x v1.0.0
   105  	y v1.0.0
   106  	z v1.0.0
   107  )
   108  
   109  replace (
   110  	a v1.0.0 => ./a
   111  	diamondleft => ./diamondleft
   112  	diamondpoint => ./diamondpoint
   113  	diamondright => ./diamondright
   114  	diamondroot => ./diamondroot
   115  	mysite/myname/mypkg v1.0.0 => ./mypkg
   116  	w v1.0.0 => ./w
   117  	x v1.0.0 => ./x
   118  	y v1.0.0 => ./y
   119  	z v1.0.0 => ./z
   120  )
   121  
   122  -- a/foo/AUTHORS.txt --
   123  -- a/foo/CONTRIBUTORS --
   124  -- a/foo/LICENSE --
   125  -- a/foo/PATENTS --
   126  -- a/foo/COPYING --
   127  -- a/foo/COPYLEFT --
   128  -- a/foo/licensed-to-kill --
   129  -- w/LICENSE --
   130  -- x/NOTICE! --
   131  -- x/x2/LICENSE --
   132  -- mypkg/LICENSE.txt --
   133  
   134  -- a/foo/bar/b/main.go --
   135  package b
   136  -- a/foo/bar/b/ignored.go --
   137  // This file is intended for use with "go run"; it isn't really part of the package.
   138  
   139  // +build ignore
   140  
   141  package main
   142  
   143  func main() {}
   144  -- a/foo/bar/b/main_test.go --
   145  package b
   146  
   147  import (
   148  	"os"
   149  	"testing"
   150  )
   151  
   152  func TestDir(t *testing.T) {
   153  	if _, err := os.Stat("../testdata/1"); err != nil {
   154  		t.Fatalf("testdata: %v", err)
   155  	}
   156  }
   157  -- a/foo/bar/c/main.go --
   158  package c
   159  import _ "a/foo/bar/b"
   160  -- a/foo/bar/c/main_test.go --
   161  package c
   162  
   163  import (
   164  	"os"
   165  	"testing"
   166  )
   167  
   168  func TestDir(t *testing.T) {
   169  	if _, err := os.Stat("../../../testdata/1"); err != nil {
   170  		t.Fatalf("testdata: %v", err)
   171  	}
   172  	if _, err := os.Stat("./testdata/1"); err != nil {
   173  		t.Fatalf("testdata: %v", err)
   174  	}
   175  }
   176  -- a/foo/bar/c/testdata/1 --
   177  -- a/foo/bar/testdata/1 --
   178  -- a/go.mod --
   179  module a
   180  -- a/main.go --
   181  package a
   182  -- a/main_test.go --
   183  package a
   184  
   185  import (
   186  	"os"
   187  	"testing"
   188  )
   189  
   190  func TestDir(t *testing.T) {
   191  	if _, err := os.Stat("./testdata/1"); err != nil {
   192  		t.Fatalf("testdata: %v", err)
   193  	}
   194  }
   195  -- a/testdata/1 --
   196  -- appengine.go --
   197  // +build appengine
   198  
   199  package m
   200  
   201  import _ "appengine"
   202  import _ "appengine/datastore"
   203  -- mypkg/go.mod --
   204  module me
   205  -- mypkg/mydir/d.go --
   206  package mydir
   207  -- subdir/v1_test.go --
   208  package m
   209  
   210  import _ "mysite/myname/mypkg/mydir"
   211  -- testdata1.go --
   212  package m
   213  
   214  import _ "a"
   215  -- testdata2.go --
   216  package m
   217  
   218  import _ "a/foo/bar/c"
   219  -- v1.go --
   220  package m
   221  
   222  import _ "x"
   223  -- v2.go --
   224  // +build abc
   225  
   226  package mMmMmMm
   227  
   228  import _ "y"
   229  -- v3.go --
   230  // +build !abc
   231  
   232  package m
   233  
   234  import _ "z"
   235  -- v4.go --
   236  // +build notmytag
   237  
   238  package m
   239  
   240  import _ "x/x1"
   241  -- importdiamond.go --
   242  package m
   243  
   244  import _ "diamondroot"
   245  -- w/go.mod --
   246  module w
   247  -- w/w.go --
   248  package w
   249  -- x/go.mod --
   250  module x
   251  -- x/testdata/x.txt --
   252  placeholder - want directory with no go files
   253  -- x/x.go --
   254  package x
   255  -- x/x1/x1.go --
   256  // +build notmytag
   257  
   258  package x1
   259  -- x/x2/dummy.txt --
   260  dummy
   261  -- x/x_test.go --
   262  package x
   263  
   264  import _ "w"
   265  -- y/go.mod --
   266  module y
   267  -- y/y.go --
   268  package y
   269  -- z/go.mod --
   270  module z
   271  -- z/z.go --
   272  package z
   273  
   274  -- diamondroot/go.mod --
   275  module diamondroot
   276  
   277  require (
   278  	diamondleft v0.0.0
   279  	diamondright v0.0.0
   280  )
   281  -- diamondroot/x.go --
   282  package diamondroot
   283  
   284  import _ "diamondleft"
   285  -- diamondroot/unused/unused.go --
   286  package unused
   287  
   288  import _ "diamondright"
   289  -- diamondleft/go.mod --
   290  module diamondleft
   291  
   292  require (
   293  	diamondpoint v0.0.0
   294  )
   295  -- diamondleft/x.go --
   296  package diamondleft
   297  
   298  import _ "diamondpoint"
   299  -- diamondright/go.mod --
   300  module diamondright
   301  
   302  require (
   303  	diamondpoint v0.0.0
   304  )
   305  -- diamondright/x.go --
   306  package diamondright
   307  
   308  import _ "diamondpoint"
   309  -- diamondpoint/go.mod --
   310  module diamondpoint
   311  -- diamondpoint/x.go --
   312  package diamondpoint
   313  

View as plain text