...

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

Documentation: cmd/go/testdata/script

     1env 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.
     9go list -f {{.Dir}} x
    10stdout 'src[\\/]x'
    11
    12# 'go mod vendor' should copy all replaced modules to the vendor directory.
    13go mod vendor -v
    14stderr '^# x v1.0.0 => ./x'
    15stderr '^x'
    16stderr '^# y v1.0.0 => ./y'
    17stderr '^y'
    18stderr '^# z v1.0.0 => ./z'
    19stderr '^z'
    20! stderr '^w'
    21grep '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.
    24go list -mod=mod -f {{.Dir}} x
    25stdout 'src[\\/]x'
    26
    27go list -mod=mod -f {{.Dir}} -m x
    28stdout 'src[\\/]x'
    29
    30# An explicit '-mod=vendor' should report package directories within
    31# the vendor directory.
    32go list -mod=vendor -f {{.Dir}} x
    33stdout '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.
    38go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x
    39stdout '^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
    43stderr '^go: 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
    45stderr '^go: 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
    51stderr 'go: 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.
    55go list -mod=mod -f {{.Dir}} w
    56stdout 'src[\\/]w'
    57! go list -mod=vendor -f {{.Dir}} w
    58stderr 'package w is not in std'
    59
    60go list -mod=mod -f {{.Dir}} diamondright
    61stdout '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.
    70exists vendor/a/foo/AUTHORS.txt
    71exists vendor/a/foo/CONTRIBUTORS
    72exists vendor/a/foo/LICENSE
    73exists vendor/a/foo/PATENTS
    74exists vendor/a/foo/COPYING
    75exists vendor/a/foo/COPYLEFT
    76exists vendor/x/NOTICE!
    77exists 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# 'go mod vendor' should work with an alternative vendor directory if the -o flag is provided.
    86go mod vendor -v -o alternative-vendor-dir
    87exists alternative-vendor-dir/modules.txt
    88exists alternative-vendor-dir/a/foo/LICENSE
    89
    90# 'go mod vendor' should interpret paths relative to the current working directory when the -o flag is provided.
    91mkdir dir1
    92mkdir dir2
    93
    94cd dir1
    95go mod vendor -v -o relative-vendor-dir
    96
    97go mod vendor -v -o ../dir2/relative-vendor-dir
    98
    99cd ..
   100exists dir1/relative-vendor-dir/modules.txt
   101exists dir1/relative-vendor-dir/a/foo/LICENSE
   102exists dir2/relative-vendor-dir/modules.txt
   103exists dir2/relative-vendor-dir/a/foo/LICENSE
   104
   105# 'go mod vendor' should fall back to the default 'vendor' directory when an empty argument is passed to the -o flag
   106# the same behavior should be exhibited both on the module root directory, as well as nested subdirectories
   107
   108go mod vendor -v -o ''
   109exists vendor/modules.txt
   110
   111env GOFLAGS=-o=foo
   112go mod vendor -v -o ''
   113exists vendor/modules.txt
   114env GOFLAGS=''
   115
   116mkdir -p nested/dir
   117cd nested/dir
   118go mod vendor -v -o ''
   119! exists vendor/
   120exists ../../vendor/modules.txt
   121cd ../..
   122
   123# 'go mod vendor' should work with absolute paths as well
   124go mod vendor -v -o $WORK/tmp/absolute-vendor-dir
   125exists $WORK/tmp/absolute-vendor-dir/modules.txt
   126
   127[short] stop
   128
   129# 'go build' and 'go test' using vendored packages should succeed.
   130go build -mod=mod
   131go build -mod=vendor
   132go test -mod=vendor . ./subdir
   133go test -mod=vendor ./...
   134go fmt -mod=vendor ./...
   135
   136-- go.mod --
   137module m
   138
   139go 1.13
   140
   141require (
   142	a v1.0.0
   143	diamondroot v0.0.0
   144	mysite/myname/mypkg v1.0.0
   145	w v1.0.0 // indirect
   146	x v1.0.0
   147	y v1.0.0
   148	z v1.0.0
   149)
   150
   151replace (
   152	a v1.0.0 => ./a
   153	diamondleft => ./diamondleft
   154	diamondpoint => ./diamondpoint
   155	diamondright => ./diamondright
   156	diamondroot => ./diamondroot
   157	mysite/myname/mypkg v1.0.0 => ./mypkg
   158	w v1.0.0 => ./w
   159	x v1.0.0 => ./x
   160	y v1.0.0 => ./y
   161	z v1.0.0 => ./z
   162)
   163
   164-- a/foo/AUTHORS.txt --
   165-- a/foo/CONTRIBUTORS --
   166-- a/foo/LICENSE --
   167-- a/foo/PATENTS --
   168-- a/foo/COPYING --
   169-- a/foo/COPYLEFT --
   170-- a/foo/licensed-to-kill --
   171-- w/LICENSE --
   172-- x/NOTICE! --
   173-- x/x2/LICENSE --
   174-- mypkg/LICENSE.txt --
   175
   176-- a/foo/bar/b/main.go --
   177package b
   178-- a/foo/bar/b/ignored.go --
   179// This file is intended for use with "go run"; it isn't really part of the package.
   180
   181// +build ignore
   182
   183package main
   184
   185func main() {}
   186-- a/foo/bar/b/main_test.go --
   187package b
   188
   189import (
   190	"os"
   191	"testing"
   192)
   193
   194func TestDir(t *testing.T) {
   195	if _, err := os.Stat("../testdata/1"); err != nil {
   196		t.Fatalf("testdata: %v", err)
   197	}
   198}
   199-- a/foo/bar/c/main.go --
   200package c
   201import _ "a/foo/bar/b"
   202-- a/foo/bar/c/main_test.go --
   203package c
   204
   205import (
   206	"os"
   207	"testing"
   208)
   209
   210func TestDir(t *testing.T) {
   211	if _, err := os.Stat("../../../testdata/1"); err != nil {
   212		t.Fatalf("testdata: %v", err)
   213	}
   214	if _, err := os.Stat("./testdata/1"); err != nil {
   215		t.Fatalf("testdata: %v", err)
   216	}
   217}
   218-- a/foo/bar/c/testdata/1 --
   219-- a/foo/bar/testdata/1 --
   220-- a/go.mod --
   221module a
   222-- a/main.go --
   223package a
   224-- a/main_test.go --
   225package a
   226
   227import (
   228	"os"
   229	"testing"
   230)
   231
   232func TestDir(t *testing.T) {
   233	if _, err := os.Stat("./testdata/1"); err != nil {
   234		t.Fatalf("testdata: %v", err)
   235	}
   236}
   237-- a/testdata/1 --
   238-- appengine.go --
   239// +build appengine
   240
   241package m
   242
   243import _ "appengine"
   244import _ "appengine/datastore"
   245-- mypkg/go.mod --
   246module me
   247-- mypkg/mydir/d.go --
   248package mydir
   249-- subdir/v1_test.go --
   250package m
   251
   252import _ "mysite/myname/mypkg/mydir"
   253-- testdata1.go --
   254package m
   255
   256import _ "a"
   257-- testdata2.go --
   258package m
   259
   260import _ "a/foo/bar/c"
   261-- v1.go --
   262package m
   263
   264import _ "x"
   265-- v2.go --
   266// +build abc
   267
   268package mMmMmMm
   269
   270import _ "y"
   271-- v3.go --
   272// +build !abc
   273
   274package m
   275
   276import _ "z"
   277-- v4.go --
   278// +build notmytag
   279
   280package m
   281
   282import _ "x/x1"
   283-- importdiamond.go --
   284package m
   285
   286import _ "diamondroot"
   287-- w/go.mod --
   288module w
   289-- w/w.go --
   290package w
   291-- x/go.mod --
   292module x
   293-- x/testdata/x.txt --
   294placeholder - want directory with no go files
   295-- x/x.go --
   296package x
   297-- x/x1/x1.go --
   298// +build notmytag
   299
   300package x1
   301-- x/x2/dummy.txt --
   302dummy
   303-- x/x_test.go --
   304package x
   305
   306import _ "w"
   307-- y/go.mod --
   308module y
   309-- y/y.go --
   310package y
   311-- z/go.mod --
   312module z
   313-- z/z.go --
   314package z
   315
   316-- diamondroot/go.mod --
   317module diamondroot
   318
   319require (
   320	diamondleft v0.0.0
   321	diamondright v0.0.0
   322)
   323-- diamondroot/x.go --
   324package diamondroot
   325
   326import _ "diamondleft"
   327-- diamondroot/unused/unused.go --
   328package unused
   329
   330import _ "diamondright"
   331-- diamondleft/go.mod --
   332module diamondleft
   333
   334require (
   335	diamondpoint v0.0.0
   336)
   337-- diamondleft/x.go --
   338package diamondleft
   339
   340import _ "diamondpoint"
   341-- diamondright/go.mod --
   342module diamondright
   343
   344require (
   345	diamondpoint v0.0.0
   346)
   347-- diamondright/x.go --
   348package diamondright
   349
   350import _ "diamondpoint"
   351-- diamondpoint/go.mod --
   352module diamondpoint
   353-- diamondpoint/x.go --
   354package diamondpoint

View as plain text