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

     1  # In GOPATH mode, vendored packages can replace std packages.
     2  env GO111MODULE=off
     3  cd vend/hello
     4  go test -v
     5  stdout TestMsgInternal
     6  stdout TestMsgExternal
     7  
     8  # In module mode, they cannot.
     9  env GO111MODULE=on
    10  ! go test -mod=vendor
    11  stderr 'undefined: strings.Msg'
    12  
    13  -- vend/hello/go.mod --
    14  module vend/hello
    15  
    16  go 1.16
    17  -- vend/hello/hello.go --
    18  package main
    19  
    20  import (
    21  	"fmt"
    22  	"strings" // really ../vendor/strings
    23  )
    24  
    25  func main() {
    26  	fmt.Printf("%s\n", strings.Msg)
    27  }
    28  -- vend/hello/hello_test.go --
    29  package main
    30  
    31  import (
    32  	"strings" // really ../vendor/strings
    33  	"testing"
    34  )
    35  
    36  func TestMsgInternal(t *testing.T) {
    37  	if strings.Msg != "hello, world" {
    38  		t.Fatalf("unexpected msg: %v", strings.Msg)
    39  	}
    40  }
    41  -- vend/hello/hellox_test.go --
    42  package main_test
    43  
    44  import (
    45  	"strings" // really ../vendor/strings
    46  	"testing"
    47  )
    48  
    49  func TestMsgExternal(t *testing.T) {
    50  	if strings.Msg != "hello, world" {
    51  		t.Fatalf("unexpected msg: %v", strings.Msg)
    52  	}
    53  }
    54  -- vend/vendor/strings/msg.go --
    55  package strings
    56  
    57  var Msg = "hello, world"
    58  

View as plain text