blob: fb954d74edbe9e76aa4f0a45e1eabf20a29d0adb [file] [log] [blame]
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.
cd $GOROOT/src
go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' net/http
stdout ^golang.org/x/net/http2/hpack
! stdout ^vendor/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"