11env GO111MODULE=on
22
3+ # Without vendoring, a build should succeed unless -mod=vendor is set.
34[!short] go build
45[!short] ! go build -mod=vendor
56
7+ # Without vendoring, 'go list' should report the replacement directory for
8+ # a package in a replaced module.
69go list -f {{.Dir}} x
710stdout 'src[\\/]x'
811
12+ # 'go mod vendor' should copy all replaced modules to the vendor directory.
913go mod vendor -v
1014stderr '^# x v1.0.0 => ./x'
1115stderr '^x'
@@ -16,28 +20,38 @@ stderr '^z'
1620! stderr '^w'
1721grep 'a/foo/bar/b\na/foo/bar/c' vendor/modules.txt # must be sorted
1822
23+ # An explicit '-mod=mod' should ignore the vendor directory.
1924go list -mod=mod -f {{.Dir}} x
2025stdout 'src[\\/]x'
2126
2227go list -mod=mod -f {{.Dir}} -m x
2328stdout 'src[\\/]x'
2429
30+ # An explicit '-mod=vendor' should report package directories within
31+ # the vendor directory.
2532go list -mod=vendor -f {{.Dir}} x
2633stdout 'src[\\/]vendor[\\/]x'
2734
28- go list -mod=vendor -f {{.Dir}} -m x
29- stdout 'src[\\/]vendor[\\/]x'
35+ # 'go list -mod=vendor -m' does not have enough information to list modules
36+ # accurately, and should fail.
37+ ! go list -mod=vendor -f {{.Dir}} -m x
38+ stderr 'can''t list modules with -mod=vendor\n\tuse -mod=mod or -mod=readonly to ignore the vendor directory'
3039
31- go list -mod=mod -f {{.Dir}} -m w
40+ # 'go list -mod=mod' should report packages outside the import graph,
41+ # but 'go list -mod=vendor' should error out for them.
42+ go list -mod=mod -f {{.Dir}} w
3243stdout 'src[\\/]w'
3344
3445! go list -mod=vendor -f {{.Dir}} w
3546stderr 'src[\\/]vendor[\\/]w'
3647
48+ # Test dependencies should not be copied.
3749! exists vendor/x/testdata
3850! exists vendor/a/foo/bar/b/ignored.go
3951! exists vendor/a/foo/bar/b/main_test.go
4052
53+ # Licenses and other metadata for each module should be copied
54+ # if any package within their module is copied.
4155exists vendor/a/foo/AUTHORS.txt
4256exists vendor/a/foo/CONTRIBUTORS
4357exists vendor/a/foo/LICENSE
@@ -55,7 +69,8 @@ exists vendor/mysite/myname/mypkg/LICENSE.txt
5569
5670[short] stop
5771
58- go build
72+ # 'go build' and 'go test' using vendored packages should succeed.
73+ go build -mod=mod
5974go build -mod=vendor
6075go test -mod=vendor . ./subdir
6176go test -mod=vendor ./...
0 commit comments