...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2env GOPROXY=off
     3
     4[!compiler:gc] skip
     5
     6# 'go list' should report imports from _test.go in the TestImports field.
     7go list -f '{{.TestImports}}'
     8stdout net/http # from .TestImports
     9
    10# 'go list' should find standard-vendored packages.
    11go list -f '{{.Dir}}' vendor/golang.org/x/net/http2/hpack
    12stdout $GOROOT[/\\]src[/\\]vendor
    13
    14# 'go list -test' should report vendored transitive dependencies of _test.go
    15# imports in the Deps field.
    16go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}'
    17stdout ^vendor/golang.org/x/crypto # dep of .TestImports
    18
    19
    20# Modules outside the standard library should not use the packages vendored there...
    21cd broken
    22! go build -mod=readonly
    23stderr 'disabled by -mod=readonly'
    24! go build -mod=vendor
    25stderr 'http.go:5:2: cannot find module providing package golang.org/x/net/http2/hpack: import lookup disabled by -mod=vendor'
    26
    27# ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix.
    28cd ../importcmd
    29! go build .
    30stderr 'use of vendored package'
    31
    32cd ../importstd
    33! go build .
    34stderr 'use of vendored package'
    35
    36
    37# When run within the 'std' module, 'go list -test' should report vendored
    38# transitive dependencies at their vendored paths.
    39cd $GOROOT/src
    40go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' net/http
    41! stdout ^golang.org/x/net/http2/hpack
    42stdout ^vendor/golang.org/x/net/http2/hpack
    43
    44-- go.mod --
    45module m
    46
    47-- x.go --
    48package x
    49
    50-- x_test.go --
    51package x
    52import "testing"
    53import _ "net/http"
    54func Test(t *testing.T) {}
    55
    56-- broken/go.mod --
    57module broken
    58-- broken/http.go --
    59package broken
    60
    61import (
    62	_ "net/http"
    63	_ "golang.org/x/net/http2/hpack"
    64)
    65
    66-- importcmd/go.mod --
    67module importcmd
    68-- importcmd/x.go --
    69package importcmd
    70
    71import _ "cmd/vendor/golang.org/x/tools/go/analysis"
    72-- importstd/go.mod --
    73module importvendor
    74-- importstd/x.go --
    75package importstd
    76
    77import _ "vendor/golang.org/x/net/http2/hpack"

View as plain text