aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_std_vendor.txt
blob: 5986cff594665aa34bdeddac4019c261a10a7bd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
env GO111MODULE=on
env GOPROXY=off

[!gc] skip

# 'go list' should report imports from _test.go in the TestImports field.
go list -f '{{.TestImports}}'
stdout net/http # from .TestImports

# 'go list' should find standard-vendored packages.
go list -f '{{.Dir}}' vendor/golang.org/x/net/http2/hpack
stdout $GOROOT[/\\]src[/\\]vendor

# 'go list -test' should report vendored transitive dependencies of _test.go
# imports in the Deps field.
go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}'
stdout ^vendor/golang.org/x/crypto # dep of .TestImports


# Modules outside the standard library should not use the packages vendored there...
cd broken
! go build -mod=readonly
stderr 'disabled by -mod=readonly'
! go build -mod=vendor
stderr 'cannot find package'
stderr 'hpack'

# ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix.
cd ../importcmd
! go build .
stderr 'use of vendored package'

cd ../importstd
! go build .
stderr 'use of vendored package'


# When run within the 'std' module, 'go list -test' should report vendored
# transitive dependencies at their original module paths.
# TODO(golang.org/issue/30241): Make that work.
# Today, they're standard packages as long as they exist.
cd $GOROOT/src
go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' net/http
stdout ^vendor/golang.org/x/net/http2/hpack  # TODO: remove vendor/ prefix
! stdout ^golang.org/x/net/http2/hpack

-- go.mod --
module m

-- x.go --
package x

-- x_test.go --
package x
import "testing"
import _ "net/http"
func Test(t *testing.T) {}

-- broken/go.mod --
module broken
-- broken/http.go --
package broken

import (
	_ "net/http"
	_ "golang.org/x/net/http2/hpack"
)

-- importcmd/go.mod --
module importcmd
-- importcmd/x.go --
package importcmd

import _ "cmd/vendor/golang.org/x/tools/go/analysis"
-- importstd/go.mod --
module importvendor
-- importstd/x.go --
package importstd

import _ "vendor/golang.org/x/net/http2/hpack"