From c6d281e5acbaa658b01c9dc03fd51d7228fe7360 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Mon, 6 Jan 2020 15:33:38 -0500 Subject: [PATCH] cmd/go: convert some tests in vendor_test to the script framework Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: I601e0fcee32b8c5bf2107b520d1dfbe12a19ad3f Reviewed-on: https://go-review.googlesource.com/c/go/+/213223 Reviewed-by: Jay Conrod --- src/cmd/go/testdata/script/build_vendor.txt | 41 +++ src/cmd/go/testdata/script/get_vendor.txt | 94 +++++ src/cmd/go/testdata/script/run_vendor.txt | 33 ++ src/cmd/go/testdata/script/test_vendor.txt | 47 +++ .../script/vendor_gopath_issue11409.txt | 51 +++ src/cmd/go/testdata/script/vendor_import.txt | 103 ++++++ .../testdata/script/vendor_import_missing.txt | 7 + .../testdata/script/vendor_import_wrong.txt | 9 + .../go/testdata/script/vendor_issue12156.txt | 15 + .../script/vendor_list_issue11977.txt | 16 + src/cmd/go/testdata/script/vendor_resolve.txt | 20 + .../script/vendor_test_issue11864.txt | 19 + .../script/vendor_test_issue14613.txt | 21 ++ src/cmd/go/testdata/src/vend/bad.go | 3 - src/cmd/go/testdata/src/vend/dir1/dir1.go | 1 - src/cmd/go/testdata/src/vend/good.go | 3 - src/cmd/go/testdata/src/vend/hello/hello.go | 10 - .../go/testdata/src/vend/hello/hello_test.go | 12 - .../go/testdata/src/vend/hello/hellox_test.go | 12 - src/cmd/go/testdata/src/vend/subdir/bad.go | 3 - src/cmd/go/testdata/src/vend/subdir/good.go | 3 - src/cmd/go/testdata/src/vend/vendor/p/p.go | 1 - src/cmd/go/testdata/src/vend/vendor/q/q.go | 1 - .../testdata/src/vend/vendor/strings/msg.go | 3 - .../src/vend/vendor/vend/dir1/dir2/dir2.go | 1 - .../go/testdata/src/vend/x/invalid/invalid.go | 3 - src/cmd/go/testdata/src/vend/x/vendor/p/p.go | 1 - .../go/testdata/src/vend/x/vendor/p/p/p.go | 3 - src/cmd/go/testdata/src/vend/x/vendor/r/r.go | 1 - src/cmd/go/testdata/src/vend/x/x.go | 7 - src/cmd/go/testdata/testvendor/src/p/p.go | 6 - .../testdata/testvendor/src/q/vendor/x/x.go | 1 - src/cmd/go/testdata/testvendor/src/q/y/y.go | 3 - src/cmd/go/testdata/testvendor/src/q/z/z.go | 3 - src/cmd/go/testdata/testvendor2/src/p/p.go | 3 - src/cmd/go/testdata/testvendor2/vendor/x/x.go | 1 - src/cmd/go/vendor_test.go | 343 ------------------ 37 files changed, 476 insertions(+), 428 deletions(-) create mode 100644 src/cmd/go/testdata/script/build_vendor.txt create mode 100644 src/cmd/go/testdata/script/get_vendor.txt create mode 100644 src/cmd/go/testdata/script/run_vendor.txt create mode 100644 src/cmd/go/testdata/script/test_vendor.txt create mode 100644 src/cmd/go/testdata/script/vendor_gopath_issue11409.txt create mode 100644 src/cmd/go/testdata/script/vendor_import.txt create mode 100644 src/cmd/go/testdata/script/vendor_import_missing.txt create mode 100644 src/cmd/go/testdata/script/vendor_import_wrong.txt create mode 100644 src/cmd/go/testdata/script/vendor_issue12156.txt create mode 100644 src/cmd/go/testdata/script/vendor_list_issue11977.txt create mode 100644 src/cmd/go/testdata/script/vendor_resolve.txt create mode 100644 src/cmd/go/testdata/script/vendor_test_issue11864.txt create mode 100644 src/cmd/go/testdata/script/vendor_test_issue14613.txt delete mode 100644 src/cmd/go/testdata/src/vend/bad.go delete mode 100644 src/cmd/go/testdata/src/vend/dir1/dir1.go delete mode 100644 src/cmd/go/testdata/src/vend/good.go delete mode 100644 src/cmd/go/testdata/src/vend/hello/hello.go delete mode 100644 src/cmd/go/testdata/src/vend/hello/hello_test.go delete mode 100644 src/cmd/go/testdata/src/vend/hello/hellox_test.go delete mode 100644 src/cmd/go/testdata/src/vend/subdir/bad.go delete mode 100644 src/cmd/go/testdata/src/vend/subdir/good.go delete mode 100644 src/cmd/go/testdata/src/vend/vendor/p/p.go delete mode 100644 src/cmd/go/testdata/src/vend/vendor/q/q.go delete mode 100644 src/cmd/go/testdata/src/vend/vendor/strings/msg.go delete mode 100644 src/cmd/go/testdata/src/vend/vendor/vend/dir1/dir2/dir2.go delete mode 100644 src/cmd/go/testdata/src/vend/x/invalid/invalid.go delete mode 100644 src/cmd/go/testdata/src/vend/x/vendor/p/p.go delete mode 100644 src/cmd/go/testdata/src/vend/x/vendor/p/p/p.go delete mode 100644 src/cmd/go/testdata/src/vend/x/vendor/r/r.go delete mode 100644 src/cmd/go/testdata/src/vend/x/x.go delete mode 100644 src/cmd/go/testdata/testvendor/src/p/p.go delete mode 100644 src/cmd/go/testdata/testvendor/src/q/vendor/x/x.go delete mode 100644 src/cmd/go/testdata/testvendor/src/q/y/y.go delete mode 100644 src/cmd/go/testdata/testvendor/src/q/z/z.go delete mode 100644 src/cmd/go/testdata/testvendor2/src/p/p.go delete mode 100644 src/cmd/go/testdata/testvendor2/vendor/x/x.go diff --git a/src/cmd/go/testdata/script/build_vendor.txt b/src/cmd/go/testdata/script/build_vendor.txt new file mode 100644 index 0000000000..726ecd75b9 --- /dev/null +++ b/src/cmd/go/testdata/script/build_vendor.txt @@ -0,0 +1,41 @@ +# Build +go build vend/x +! stdout . +! stderr . + +-- vend/dir1/dir1.go -- +package dir1 +-- vend/subdir/bad.go -- +package subdir + +import _ "r" +-- vend/subdir/good.go -- +package subdir + +import _ "p" +-- vend/vendor/p/p.go -- +package p +-- vend/vendor/q/q.go -- +package q +-- vend/vendor/vend/dir1/dir2/dir2.go -- +package dir2 +-- vend/x/invalid/invalid.go -- +package invalid + +import "vend/x/invalid/vendor/foo" +-- vend/x/vendor/p/p/p.go -- +package p + +import _ "notfound" +-- vend/x/vendor/p/p.go -- +package p +-- vend/x/vendor/r/r.go -- +package r +-- vend/x/x.go -- +package x + +import _ "p" +import _ "q" +import _ "r" +import _ "vend/dir1" // not vendored +import _ "vend/dir1/dir2" // vendored diff --git a/src/cmd/go/testdata/script/get_vendor.txt b/src/cmd/go/testdata/script/get_vendor.txt new file mode 100644 index 0000000000..a6f0a70c48 --- /dev/null +++ b/src/cmd/go/testdata/script/get_vendor.txt @@ -0,0 +1,94 @@ +[short] skip + +cd $GOPATH/src/v +go run m.go +go test +go list -f '{{.Imports}}' +stdout 'v/vendor/vendor.org/p' +go list -f '{{.TestImports}}' +stdout 'v/vendor/vendor.org/p' +go get -d +go get -t -d + +[!net] stop +[!exec:git] stop + +cd $GOPATH/src + +# Update +go get 'github.com/rsc/go-get-issue-11864' +go get -u 'github.com/rsc/go-get-issue-11864' +exists github.com/rsc/go-get-issue-11864/vendor + +# get -u +rm $GOPATH +mkdir $GOPATH/src +go get -u 'github.com/rsc/go-get-issue-11864' +exists github.com/rsc/go-get-issue-11864/vendor + +# get -t -u +rm $GOPATH +mkdir $GOPATH/src +go get -t -u 'github.com/rsc/go-get-issue-11864/...' +exists github.com/rsc/go-get-issue-11864/vendor + +# Submodules +rm $GOPATH +mkdir $GOPATH/src +go get -d 'github.com/rsc/go-get-issue-12612' +go get -u -d 'github.com/rsc/go-get-issue-12612' +exists github.com/rsc/go-get-issue-12612/vendor/golang.org/x/crypto/.git + +# Bad vendor (bad/imp) +rm $GOPATH +mkdir $GOPATH/src +! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp' +stderr 'must be imported as' +! exists github.com/rsc/go-get-issue-11864/vendor + +# Bad vendor (bad/imp2) +rm $GOPATH +mkdir $GOPATH/src +! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp2' +stderr 'must be imported as' +! exists github.com/rsc/go-get-issue-11864/vendor + +# Bad vendor (bad/imp3) +rm $GOPATH +mkdir $GOPATH/src +! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp3' +stderr 'must be imported as' +! exists github.com/rsc/go-get-issue-11864/vendor + +# Bad vendor (bad/...) +rm $GOPATH +mkdir $GOPATH/src +! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/...' +stderr 'must be imported as' +! exists github.com/rsc/go-get-issue-11864/vendor + +-- v/m.go -- +package main + +import ( + "fmt" + "vendor.org/p" +) + +func main() { + fmt.Println(p.C) +} +-- v/m_test.go -- +package main +import ( + "fmt" + "testing" + "vendor.org/p" +) + +func TestNothing(t *testing.T) { + fmt.Println(p.C) +} +-- v/vendor/vendor.org/p/p.go -- +package p +const C = 1 \ No newline at end of file diff --git a/src/cmd/go/testdata/script/run_vendor.txt b/src/cmd/go/testdata/script/run_vendor.txt new file mode 100644 index 0000000000..8544281db9 --- /dev/null +++ b/src/cmd/go/testdata/script/run_vendor.txt @@ -0,0 +1,33 @@ +# Run +cd vend/hello +go run hello.go +stdout 'hello, world' + +-- vend/hello/hello.go -- +package main + +import ( + "fmt" + "strings" // really ../vendor/strings +) + +func main() { + fmt.Printf("%s\n", strings.Msg) +} +-- vend/hello/hello_test.go -- +package main + +import ( + "strings" // really ../vendor/strings + "testing" +) + +func TestMsgInternal(t *testing.T) { + if strings.Msg != "hello, world" { + t.Fatalf("unexpected msg: %v", strings.Msg) + } +} +-- vend/vendor/strings/msg.go -- +package strings + +var Msg = "hello, world" diff --git a/src/cmd/go/testdata/script/test_vendor.txt b/src/cmd/go/testdata/script/test_vendor.txt new file mode 100644 index 0000000000..d72d672827 --- /dev/null +++ b/src/cmd/go/testdata/script/test_vendor.txt @@ -0,0 +1,47 @@ +# Test +cd vend/hello +go test -v +stdout TestMsgInternal +stdout TestMsgExternal + +-- vend/hello/hello.go -- +package main + +import ( + "fmt" + "strings" // really ../vendor/strings +) + +func main() { + fmt.Printf("%s\n", strings.Msg) +} +-- vend/hello/hello_test.go -- +package main + +import ( + "strings" // really ../vendor/strings + "testing" +) + +func TestMsgInternal(t *testing.T) { + if strings.Msg != "hello, world" { + t.Fatalf("unexpected msg: %v", strings.Msg) + } +} +-- vend/hello/hellox_test.go -- +package main_test + +import ( + "strings" // really ../vendor/strings + "testing" +) + +func TestMsgExternal(t *testing.T) { + if strings.Msg != "hello, world" { + t.Fatalf("unexpected msg: %v", strings.Msg) + } +} +-- vend/vendor/strings/msg.go -- +package strings + +var Msg = "hello, world" diff --git a/src/cmd/go/testdata/script/vendor_gopath_issue11409.txt b/src/cmd/go/testdata/script/vendor_gopath_issue11409.txt new file mode 100644 index 0000000000..746a34a744 --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_gopath_issue11409.txt @@ -0,0 +1,51 @@ +[!windows] [short] stop 'this test only applies to Windows' + +go build run_go.go +exec ./run_go$GOEXE $GOPATH $GOPATH/src/vend/hello +stdout 'hello, world' + +-- run_go.go -- +package main + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func changeVolume(s string, f func(s string) string) string { + vol := filepath.VolumeName(s) + return f(vol) + s[len(vol):] +} + +func main() { + gopath := changeVolume(os.Args[1], strings.ToLower) + dir := changeVolume(os.Args[2], strings.ToUpper) + cmd := exec.Command("go", "run", "hello.go") + cmd.Dir = dir + cmd.Env = append(os.Environ(), "GOPATH="+gopath) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +-- vend/hello/hello.go -- +package main + +import ( + "fmt" + "strings" // really ../vendor/strings +) + +func main() { + fmt.Printf("%s\n", strings.Msg) +} +-- vend/vendor/strings/msg.go -- +package strings + +var Msg = "hello, world" diff --git a/src/cmd/go/testdata/script/vendor_import.txt b/src/cmd/go/testdata/script/vendor_import.txt new file mode 100644 index 0000000000..35419f36f1 --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_import.txt @@ -0,0 +1,103 @@ +# Imports +go list -f '{{.ImportPath}} {{.Imports}}' 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...' +cmp stdout want_vendor_imports.txt + +-- want_vendor_imports.txt -- +vend [vend/vendor/p r] +vend/dir1 [] +vend/hello [fmt vend/vendor/strings] +vend/subdir [vend/vendor/p r] +vend/x [vend/x/vendor/p vend/vendor/q vend/x/vendor/r vend/dir1 vend/vendor/vend/dir1/dir2] +vend/x/invalid [vend/x/invalid/vendor/foo] +vend/vendor/p [] +vend/vendor/q [] +vend/vendor/strings [] +vend/vendor/vend/dir1/dir2 [] +vend/x/vendor/p [] +vend/x/vendor/p/p [notfound] +vend/x/vendor/r [] +-- vend/bad.go -- +package vend + +import _ "r" +-- vend/dir1/dir1.go -- +package dir1 +-- vend/good.go -- +package vend + +import _ "p" +-- vend/hello/hello.go -- +package main + +import ( + "fmt" + "strings" // really ../vendor/strings +) + +func main() { + fmt.Printf("%s\n", strings.Msg) +} +-- vend/hello/hello_test.go -- +package main + +import ( + "strings" // really ../vendor/strings + "testing" +) + +func TestMsgInternal(t *testing.T) { + if strings.Msg != "hello, world" { + t.Fatalf("unexpected msg: %v", strings.Msg) + } +} +-- vend/hello/hellox_test.go -- +package main_test + +import ( + "strings" // really ../vendor/strings + "testing" +) + +func TestMsgExternal(t *testing.T) { + if strings.Msg != "hello, world" { + t.Fatalf("unexpected msg: %v", strings.Msg) + } +} +-- vend/subdir/bad.go -- +package subdir + +import _ "r" +-- vend/subdir/good.go -- +package subdir + +import _ "p" +-- vend/vendor/p/p.go -- +package p +-- vend/vendor/q/q.go -- +package q +-- vend/vendor/strings/msg.go -- +package strings + +var Msg = "hello, world" +-- vend/vendor/vend/dir1/dir2/dir2.go -- +package dir2 +-- vend/x/invalid/invalid.go -- +package invalid + +import "vend/x/invalid/vendor/foo" +-- vend/x/vendor/p/p/p.go -- +package p + +import _ "notfound" +-- vend/x/vendor/p/p.go -- +package p +-- vend/x/vendor/r/r.go -- +package r +-- vend/x/x.go -- +package x + +import _ "p" +import _ "q" +import _ "r" +import _ "vend/dir1" // not vendored +import _ "vend/dir1/dir2" // vendored diff --git a/src/cmd/go/testdata/script/vendor_import_missing.txt b/src/cmd/go/testdata/script/vendor_import_missing.txt new file mode 100644 index 0000000000..8e50dfe9d7 --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_import_missing.txt @@ -0,0 +1,7 @@ +# Missing package error message +! go build vend/x/vendor/p/p + +-- vend/x/vendor/p/p/p.go -- +package p + +import _ "notfound" diff --git a/src/cmd/go/testdata/script/vendor_import_wrong.txt b/src/cmd/go/testdata/script/vendor_import_wrong.txt new file mode 100644 index 0000000000..aba6269784 --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_import_wrong.txt @@ -0,0 +1,9 @@ +# Wrong import path +! go build vend/x/invalid +stderr 'must be imported as foo' + +-- vend/x/invalid/invalid.go -- +package invalid + +import "vend/x/invalid/vendor/foo" + diff --git a/src/cmd/go/testdata/script/vendor_issue12156.txt b/src/cmd/go/testdata/script/vendor_issue12156.txt new file mode 100644 index 0000000000..49eb235ba5 --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_issue12156.txt @@ -0,0 +1,15 @@ +# Tests issue #12156, a former index out of range panic. + +env GOPATH=$WORK/gopath/src/testvendor2 # vendor/x is directly in $GOPATH, not in $GOPATH/src +cd $WORK/gopath/src/testvendor2/src/p + +! go build p.go +! stderr panic # Make sure it doesn't panic +stderr 'cannot find package "x"' + +-- testvendor2/src/p/p.go -- +package p + +import "x" +-- testvendor2/vendor/x/x.go -- +package x diff --git a/src/cmd/go/testdata/script/vendor_list_issue11977.txt b/src/cmd/go/testdata/script/vendor_list_issue11977.txt new file mode 100644 index 0000000000..d97c6518b4 --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_list_issue11977.txt @@ -0,0 +1,16 @@ +[!net] skip +[!exec:git] skip + +go get github.com/rsc/go-get-issue-11864 + +go list -f '{{join .TestImports "\n"}}' github.com/rsc/go-get-issue-11864/t +stdout 'go-get-issue-11864/vendor/vendor.org/p' + +go list -f '{{join .XTestImports "\n"}}' github.com/rsc/go-get-issue-11864/tx +stdout 'go-get-issue-11864/vendor/vendor.org/p' + +go list -f '{{join .XTestImports "\n"}}' github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2 +stdout 'go-get-issue-11864/vendor/vendor.org/tx2' + +go list -f '{{join .XTestImports "\n"}}' github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx3 +stdout 'go-get-issue-11864/vendor/vendor.org/tx3' \ No newline at end of file diff --git a/src/cmd/go/testdata/script/vendor_resolve.txt b/src/cmd/go/testdata/script/vendor_resolve.txt new file mode 100644 index 0000000000..220b92f80b --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_resolve.txt @@ -0,0 +1,20 @@ +! go build p +stderr 'must be imported as x' + +-- p/p.go -- +package p + +import ( + _ "q/y" + _ "q/z" +) +-- q/vendor/x/x.go -- +package x +-- q/y/y.go -- +package y + +import _ "x" +-- q/z/z.go -- +package z + +import _ "q/vendor/x" diff --git a/src/cmd/go/testdata/script/vendor_test_issue11864.txt b/src/cmd/go/testdata/script/vendor_test_issue11864.txt new file mode 100644 index 0000000000..f11d790e6f --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_test_issue11864.txt @@ -0,0 +1,19 @@ +[!net] skip +[!exec:git] skip + +go get github.com/rsc/go-get-issue-11864 + +# build -i should work +go build -i github.com/rsc/go-get-issue-11864 +go build -i github.com/rsc/go-get-issue-11864/t + +# test -i should work like build -i (golang.org/issue/11988) +go test -i github.com/rsc/go-get-issue-11864 +go test -i github.com/rsc/go-get-issue-11864/t + +# test should work too +go test github.com/rsc/go-get-issue-11864 +go test github.com/rsc/go-get-issue-11864/t + +# external tests should observe internal test exports (golang.org/issue/11977) +go test github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2 \ No newline at end of file diff --git a/src/cmd/go/testdata/script/vendor_test_issue14613.txt b/src/cmd/go/testdata/script/vendor_test_issue14613.txt new file mode 100644 index 0000000000..4e5e066d6b --- /dev/null +++ b/src/cmd/go/testdata/script/vendor_test_issue14613.txt @@ -0,0 +1,21 @@ +[!net] skip +[!exec:git] skip + +cd $GOPATH + +go get github.com/clsung/go-vendor-issue-14613 +go build -o $WORK/a.out -i github.com/clsung/go-vendor-issue-14613 + +# test folder should work +go test -i github.com/clsung/go-vendor-issue-14613 +go test github.com/clsung/go-vendor-issue-14613 + +# test with specified _test.go should work too +cd $GOPATH/src +go test -i github.com/clsung/go-vendor-issue-14613/vendor_test.go +go test github.com/clsung/go-vendor-issue-14613/vendor_test.go + +# test with imported and not used +go test -i github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go +! go test github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go +stderr 'imported and not used:' diff --git a/src/cmd/go/testdata/src/vend/bad.go b/src/cmd/go/testdata/src/vend/bad.go deleted file mode 100644 index 57cc595220..0000000000 --- a/src/cmd/go/testdata/src/vend/bad.go +++ /dev/null @@ -1,3 +0,0 @@ -package vend - -import _ "r" diff --git a/src/cmd/go/testdata/src/vend/dir1/dir1.go b/src/cmd/go/testdata/src/vend/dir1/dir1.go deleted file mode 100644 index b719eadc09..0000000000 --- a/src/cmd/go/testdata/src/vend/dir1/dir1.go +++ /dev/null @@ -1 +0,0 @@ -package dir1 diff --git a/src/cmd/go/testdata/src/vend/good.go b/src/cmd/go/testdata/src/vend/good.go deleted file mode 100644 index 952ada3108..0000000000 --- a/src/cmd/go/testdata/src/vend/good.go +++ /dev/null @@ -1,3 +0,0 @@ -package vend - -import _ "p" diff --git a/src/cmd/go/testdata/src/vend/hello/hello.go b/src/cmd/go/testdata/src/vend/hello/hello.go deleted file mode 100644 index 41dc03e0ce..0000000000 --- a/src/cmd/go/testdata/src/vend/hello/hello.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import ( - "fmt" - "strings" // really ../vendor/strings -) - -func main() { - fmt.Printf("%s\n", strings.Msg) -} diff --git a/src/cmd/go/testdata/src/vend/hello/hello_test.go b/src/cmd/go/testdata/src/vend/hello/hello_test.go deleted file mode 100644 index 7190f599d6..0000000000 --- a/src/cmd/go/testdata/src/vend/hello/hello_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "strings" // really ../vendor/strings - "testing" -) - -func TestMsgInternal(t *testing.T) { - if strings.Msg != "hello, world" { - t.Fatalf("unexpected msg: %v", strings.Msg) - } -} diff --git a/src/cmd/go/testdata/src/vend/hello/hellox_test.go b/src/cmd/go/testdata/src/vend/hello/hellox_test.go deleted file mode 100644 index 3f2165bd38..0000000000 --- a/src/cmd/go/testdata/src/vend/hello/hellox_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package main_test - -import ( - "strings" // really ../vendor/strings - "testing" -) - -func TestMsgExternal(t *testing.T) { - if strings.Msg != "hello, world" { - t.Fatalf("unexpected msg: %v", strings.Msg) - } -} diff --git a/src/cmd/go/testdata/src/vend/subdir/bad.go b/src/cmd/go/testdata/src/vend/subdir/bad.go deleted file mode 100644 index d0ddaacfea..0000000000 --- a/src/cmd/go/testdata/src/vend/subdir/bad.go +++ /dev/null @@ -1,3 +0,0 @@ -package subdir - -import _ "r" diff --git a/src/cmd/go/testdata/src/vend/subdir/good.go b/src/cmd/go/testdata/src/vend/subdir/good.go deleted file mode 100644 index edd04543a2..0000000000 --- a/src/cmd/go/testdata/src/vend/subdir/good.go +++ /dev/null @@ -1,3 +0,0 @@ -package subdir - -import _ "p" diff --git a/src/cmd/go/testdata/src/vend/vendor/p/p.go b/src/cmd/go/testdata/src/vend/vendor/p/p.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/vend/vendor/p/p.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/vend/vendor/q/q.go b/src/cmd/go/testdata/src/vend/vendor/q/q.go deleted file mode 100644 index 946e6d9910..0000000000 --- a/src/cmd/go/testdata/src/vend/vendor/q/q.go +++ /dev/null @@ -1 +0,0 @@ -package q diff --git a/src/cmd/go/testdata/src/vend/vendor/strings/msg.go b/src/cmd/go/testdata/src/vend/vendor/strings/msg.go deleted file mode 100644 index 438126ba2b..0000000000 --- a/src/cmd/go/testdata/src/vend/vendor/strings/msg.go +++ /dev/null @@ -1,3 +0,0 @@ -package strings - -var Msg = "hello, world" diff --git a/src/cmd/go/testdata/src/vend/vendor/vend/dir1/dir2/dir2.go b/src/cmd/go/testdata/src/vend/vendor/vend/dir1/dir2/dir2.go deleted file mode 100644 index 6fe35e9e59..0000000000 --- a/src/cmd/go/testdata/src/vend/vendor/vend/dir1/dir2/dir2.go +++ /dev/null @@ -1 +0,0 @@ -package dir2 diff --git a/src/cmd/go/testdata/src/vend/x/invalid/invalid.go b/src/cmd/go/testdata/src/vend/x/invalid/invalid.go deleted file mode 100644 index e250d5bb31..0000000000 --- a/src/cmd/go/testdata/src/vend/x/invalid/invalid.go +++ /dev/null @@ -1,3 +0,0 @@ -package invalid - -import "vend/x/invalid/vendor/foo" diff --git a/src/cmd/go/testdata/src/vend/x/vendor/p/p.go b/src/cmd/go/testdata/src/vend/x/vendor/p/p.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/vend/x/vendor/p/p.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/vend/x/vendor/p/p/p.go b/src/cmd/go/testdata/src/vend/x/vendor/p/p/p.go deleted file mode 100644 index e12e12c2f4..0000000000 --- a/src/cmd/go/testdata/src/vend/x/vendor/p/p/p.go +++ /dev/null @@ -1,3 +0,0 @@ -package p - -import _ "notfound" diff --git a/src/cmd/go/testdata/src/vend/x/vendor/r/r.go b/src/cmd/go/testdata/src/vend/x/vendor/r/r.go deleted file mode 100644 index 838c177a57..0000000000 --- a/src/cmd/go/testdata/src/vend/x/vendor/r/r.go +++ /dev/null @@ -1 +0,0 @@ -package r diff --git a/src/cmd/go/testdata/src/vend/x/x.go b/src/cmd/go/testdata/src/vend/x/x.go deleted file mode 100644 index bdcde575c9..0000000000 --- a/src/cmd/go/testdata/src/vend/x/x.go +++ /dev/null @@ -1,7 +0,0 @@ -package x - -import _ "p" -import _ "q" -import _ "r" -import _ "vend/dir1" // not vendored -import _ "vend/dir1/dir2" // vendored diff --git a/src/cmd/go/testdata/testvendor/src/p/p.go b/src/cmd/go/testdata/testvendor/src/p/p.go deleted file mode 100644 index e740715186..0000000000 --- a/src/cmd/go/testdata/testvendor/src/p/p.go +++ /dev/null @@ -1,6 +0,0 @@ -package p - -import ( - _ "q/y" - _ "q/z" -) diff --git a/src/cmd/go/testdata/testvendor/src/q/vendor/x/x.go b/src/cmd/go/testdata/testvendor/src/q/vendor/x/x.go deleted file mode 100644 index 823aafd071..0000000000 --- a/src/cmd/go/testdata/testvendor/src/q/vendor/x/x.go +++ /dev/null @@ -1 +0,0 @@ -package x diff --git a/src/cmd/go/testdata/testvendor/src/q/y/y.go b/src/cmd/go/testdata/testvendor/src/q/y/y.go deleted file mode 100644 index 4f84223767..0000000000 --- a/src/cmd/go/testdata/testvendor/src/q/y/y.go +++ /dev/null @@ -1,3 +0,0 @@ -package y - -import _ "x" diff --git a/src/cmd/go/testdata/testvendor/src/q/z/z.go b/src/cmd/go/testdata/testvendor/src/q/z/z.go deleted file mode 100644 index a8d4924936..0000000000 --- a/src/cmd/go/testdata/testvendor/src/q/z/z.go +++ /dev/null @@ -1,3 +0,0 @@ -package z - -import _ "q/vendor/x" diff --git a/src/cmd/go/testdata/testvendor2/src/p/p.go b/src/cmd/go/testdata/testvendor2/src/p/p.go deleted file mode 100644 index 220b2b2a07..0000000000 --- a/src/cmd/go/testdata/testvendor2/src/p/p.go +++ /dev/null @@ -1,3 +0,0 @@ -package p - -import "x" diff --git a/src/cmd/go/testdata/testvendor2/vendor/x/x.go b/src/cmd/go/testdata/testvendor2/vendor/x/x.go deleted file mode 100644 index 823aafd071..0000000000 --- a/src/cmd/go/testdata/testvendor2/vendor/x/x.go +++ /dev/null @@ -1 +0,0 @@ -package x diff --git a/src/cmd/go/vendor_test.go b/src/cmd/go/vendor_test.go index 8b67de06ca..9d568b906a 100644 --- a/src/cmd/go/vendor_test.go +++ b/src/cmd/go/vendor_test.go @@ -7,354 +7,11 @@ package main_test import ( - "bytes" - "fmt" "internal/testenv" "os" - "path/filepath" - "regexp" - "strings" "testing" ) -func TestVendorImports(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - tg.run("list", "-f", "{{.ImportPath}} {{.Imports}}", "vend/...", "vend/vendor/...", "vend/x/vendor/...") - want := ` - vend [vend/vendor/p r] - vend/dir1 [] - vend/hello [fmt vend/vendor/strings] - vend/subdir [vend/vendor/p r] - vend/x [vend/x/vendor/p vend/vendor/q vend/x/vendor/r vend/dir1 vend/vendor/vend/dir1/dir2] - vend/x/invalid [vend/x/invalid/vendor/foo] - vend/vendor/p [] - vend/vendor/q [] - vend/vendor/strings [] - vend/vendor/vend/dir1/dir2 [] - vend/x/vendor/p [] - vend/x/vendor/p/p [notfound] - vend/x/vendor/r [] - ` - want = strings.ReplaceAll(want+"\t", "\n\t\t", "\n") - want = strings.TrimPrefix(want, "\n") - - have := tg.stdout.String() - - if have != want { - t.Errorf("incorrect go list output:\n%s", diffSortedOutputs(have, want)) - } -} - -func TestVendorBuild(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - tg.run("build", "vend/x") -} - -func TestVendorRun(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - tg.cd(filepath.Join(tg.pwd(), "testdata/src/vend/hello")) - tg.run("run", "hello.go") - tg.grepStdout("hello, world", "missing hello world output") -} - -func TestVendorGOPATH(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - changeVolume := func(s string, f func(s string) string) string { - vol := filepath.VolumeName(s) - return f(vol) + s[len(vol):] - } - gopath := changeVolume(filepath.Join(tg.pwd(), "testdata"), strings.ToLower) - tg.setenv("GOPATH", gopath) - cd := changeVolume(filepath.Join(tg.pwd(), "testdata/src/vend/hello"), strings.ToUpper) - tg.cd(cd) - tg.run("run", "hello.go") - tg.grepStdout("hello, world", "missing hello world output") -} - -func TestVendorTest(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - tg.cd(filepath.Join(tg.pwd(), "testdata/src/vend/hello")) - tg.run("test", "-v") - tg.grepStdout("TestMsgInternal", "missing use in internal test") - tg.grepStdout("TestMsgExternal", "missing use in external test") -} - -func TestVendorInvalid(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - - tg.runFail("build", "vend/x/invalid") - tg.grepStderr("must be imported as foo", "missing vendor import error") -} - -func TestVendorImportError(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - - tg.runFail("build", "vend/x/vendor/p/p") - - re := regexp.MustCompile(`cannot find package "notfound" in any of: - .*[\\/]testdata[\\/]src[\\/]vend[\\/]x[\\/]vendor[\\/]notfound \(vendor tree\) - .*[\\/]testdata[\\/]src[\\/]vend[\\/]vendor[\\/]notfound - .*[\\/]src[\\/]notfound \(from \$GOROOT\) - .*[\\/]testdata[\\/]src[\\/]notfound \(from \$GOPATH\)`) - - if !re.MatchString(tg.stderr.String()) { - t.Errorf("did not find expected search list in error text") - } -} - -// diffSortedOutput prepares a diff of the already sorted outputs haveText and wantText. -// The diff shows common lines prefixed by a tab, lines present only in haveText -// prefixed by "unexpected: ", and lines present only in wantText prefixed by "missing: ". -func diffSortedOutputs(haveText, wantText string) string { - var diff bytes.Buffer - have := splitLines(haveText) - want := splitLines(wantText) - for len(have) > 0 || len(want) > 0 { - if len(want) == 0 || len(have) > 0 && have[0] < want[0] { - fmt.Fprintf(&diff, "unexpected: %s\n", have[0]) - have = have[1:] - continue - } - if len(have) == 0 || len(want) > 0 && want[0] < have[0] { - fmt.Fprintf(&diff, "missing: %s\n", want[0]) - want = want[1:] - continue - } - fmt.Fprintf(&diff, "\t%s\n", want[0]) - want = want[1:] - have = have[1:] - } - return diff.String() -} - -func splitLines(s string) []string { - x := strings.Split(s, "\n") - if x[len(x)-1] == "" { - x = x[:len(x)-1] - } - return x -} - -func TestVendorGet(t *testing.T) { - tooSlow(t) - tg := testgo(t) - defer tg.cleanup() - tg.tempFile("src/v/m.go", ` - package main - import ("fmt"; "vendor.org/p") - func main() { - fmt.Println(p.C) - }`) - tg.tempFile("src/v/m_test.go", ` - package main - import ("fmt"; "testing"; "vendor.org/p") - func TestNothing(t *testing.T) { - fmt.Println(p.C) - }`) - tg.tempFile("src/v/vendor/vendor.org/p/p.go", ` - package p - const C = 1`) - tg.setenv("GOPATH", tg.path(".")) - tg.cd(tg.path("src/v")) - tg.run("run", "m.go") - tg.run("test") - tg.run("list", "-f", "{{.Imports}}") - tg.grepStdout("v/vendor/vendor.org/p", "import not in vendor directory") - tg.run("list", "-f", "{{.TestImports}}") - tg.grepStdout("v/vendor/vendor.org/p", "test import not in vendor directory") - tg.run("get", "-d") - tg.run("get", "-t", "-d") -} - -func TestVendorGetUpdate(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "github.com/rsc/go-get-issue-11864") - tg.run("get", "-u", "github.com/rsc/go-get-issue-11864") -} - -func TestVendorGetU(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "-u", "github.com/rsc/go-get-issue-11864") -} - -func TestVendorGetTU(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "-t", "-u", "github.com/rsc/go-get-issue-11864/...") -} - -func TestVendorGetBadVendor(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - for _, suffix := range []string{"bad/imp", "bad/imp2", "bad/imp3", "..."} { - t.Run(suffix, func(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.runFail("get", "-t", "-u", "github.com/rsc/go-get-issue-18219/"+suffix) - tg.grepStderr("must be imported as", "did not find error about vendor import") - tg.mustNotExist(tg.path("src/github.com/rsc/vendor")) - }) - } -} - -func TestGetSubmodules(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "-d", "github.com/rsc/go-get-issue-12612") - tg.run("get", "-u", "-d", "github.com/rsc/go-get-issue-12612") - tg.mustExist(tg.path("src/github.com/rsc/go-get-issue-12612/vendor/golang.org/x/crypto/.git")) -} - -func TestVendorCache(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/testvendor")) - tg.runFail("build", "p") - tg.grepStderr("must be imported as x", "did not fail to build p") -} - -func TestVendorTest2(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "github.com/rsc/go-get-issue-11864") - - // build -i should work - tg.run("build", "-i", "github.com/rsc/go-get-issue-11864") - tg.run("build", "-i", "github.com/rsc/go-get-issue-11864/t") - - // test -i should work like build -i (golang.org/issue/11988) - tg.run("test", "-i", "github.com/rsc/go-get-issue-11864") - tg.run("test", "-i", "github.com/rsc/go-get-issue-11864/t") - - // test should work too - tg.run("test", "github.com/rsc/go-get-issue-11864") - tg.run("test", "github.com/rsc/go-get-issue-11864/t") - - // external tests should observe internal test exports (golang.org/issue/11977) - tg.run("test", "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2") -} - -func TestVendorTest3(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "github.com/clsung/go-vendor-issue-14613") - - tg.run("build", "-o", tg.path("a.out"), "-i", "github.com/clsung/go-vendor-issue-14613") - - // test folder should work - tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613") - tg.run("test", "github.com/clsung/go-vendor-issue-14613") - - // test with specified _test.go should work too - tg.cd(filepath.Join(tg.path("."), "src")) - tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor_test.go") - tg.run("test", "github.com/clsung/go-vendor-issue-14613/vendor_test.go") - - // test with imported and not used - tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go") - tg.runFail("test", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go") - tg.grepStderr("imported and not used:", `should say "imported and not used"`) -} - -func TestVendorList(t *testing.T) { - testenv.MustHaveExternalNetwork(t) - testenv.MustHaveExecPath(t, "git") - - tg := testgo(t) - defer tg.cleanup() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.run("get", "github.com/rsc/go-get-issue-11864") - - tg.run("list", "-f", `{{join .TestImports "\n"}}`, "github.com/rsc/go-get-issue-11864/t") - tg.grepStdout("go-get-issue-11864/vendor/vendor.org/p", "did not find vendor-expanded p") - - tg.run("list", "-f", `{{join .XTestImports "\n"}}`, "github.com/rsc/go-get-issue-11864/tx") - tg.grepStdout("go-get-issue-11864/vendor/vendor.org/p", "did not find vendor-expanded p") - - tg.run("list", "-f", `{{join .XTestImports "\n"}}`, "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2") - tg.grepStdout("go-get-issue-11864/vendor/vendor.org/tx2", "did not find vendor-expanded tx2") - - tg.run("list", "-f", `{{join .XTestImports "\n"}}`, "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx3") - tg.grepStdout("go-get-issue-11864/vendor/vendor.org/tx3", "did not find vendor-expanded tx3") -} - -func TestVendor12156(t *testing.T) { - // Former index out of range panic. - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/testvendor2")) - tg.cd(filepath.Join(tg.pwd(), "testdata/testvendor2/src/p")) - tg.runFail("build", "p.go") - tg.grepStderrNot("panic", "panicked") - tg.grepStderr(`cannot find package "x"`, "wrong error") -} - -// Module legacy support does path rewriting very similar to vendoring. - -func TestLegacyMod(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/modlegacy")) - tg.run("list", "-f", "{{.Imports}}", "old/p1") - tg.grepStdout("new/p1", "old/p1 should import new/p1") - tg.run("list", "-f", "{{.Imports}}", "new/p1") - tg.grepStdout("new/p2", "new/p1 should import new/p2 (not new/v2/p2)") - tg.grepStdoutNot("new/v2", "new/p1 should NOT import new/v2*") - tg.grepStdout("new/sub/x/v1/y", "new/p1 should import new/sub/x/v1/y (not new/sub/v2/x/v1/y)") - tg.grepStdoutNot("new/sub/v2", "new/p1 should NOT import new/sub/v2*") - tg.grepStdout("new/sub/inner/x", "new/p1 should import new/sub/inner/x (no rewrites)") - tg.run("build", "old/p1", "new/p1") -} - func TestLegacyModGet(t *testing.T) { testenv.MustHaveExternalNetwork(t) testenv.MustHaveExecPath(t, "git") -- 2.50.0