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

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

View as plain text