...

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

Documentation: cmd/go/testdata/script

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

View as plain text