1
0
mirror of https://github.com/golang/go synced 2024-09-29 19:14:28 -06:00

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 <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2020-01-06 15:33:38 -05:00
parent 2cfc5e2b2f
commit c6d281e5ac
37 changed files with 476 additions and 428 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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'

View File

@ -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"

View File

@ -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

View File

@ -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:'

View File

@ -1,3 +0,0 @@
package vend
import _ "r"

View File

@ -1 +0,0 @@
package dir1

View File

@ -1,3 +0,0 @@
package vend
import _ "p"

View File

@ -1,10 +0,0 @@
package main
import (
"fmt"
"strings" // really ../vendor/strings
)
func main() {
fmt.Printf("%s\n", strings.Msg)
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -1,3 +0,0 @@
package subdir
import _ "r"

View File

@ -1,3 +0,0 @@
package subdir
import _ "p"

View File

@ -1 +0,0 @@
package p

View File

@ -1 +0,0 @@
package q

View File

@ -1,3 +0,0 @@
package strings
var Msg = "hello, world"

View File

@ -1 +0,0 @@
package dir2

View File

@ -1,3 +0,0 @@
package invalid
import "vend/x/invalid/vendor/foo"

View File

@ -1 +0,0 @@
package p

View File

@ -1,3 +0,0 @@
package p
import _ "notfound"

View File

@ -1 +0,0 @@
package r

View File

@ -1,7 +0,0 @@
package x
import _ "p"
import _ "q"
import _ "r"
import _ "vend/dir1" // not vendored
import _ "vend/dir1/dir2" // vendored

View File

@ -1,6 +0,0 @@
package p
import (
_ "q/y"
_ "q/z"
)

View File

@ -1 +0,0 @@
package x

View File

@ -1,3 +0,0 @@
package y
import _ "x"

View File

@ -1,3 +0,0 @@
package z
import _ "q/vendor/x"

View File

@ -1,3 +0,0 @@
package p
import "x"

View File

@ -1 +0,0 @@
package x

View File

@ -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")