From c345f7ff955079c241c2f6ee730351ec627606f4 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 20 Apr 2015 13:34:22 -0400 Subject: [PATCH] cmd/go: make test.bash pass again Fixes #8809. Change-Id: Id443fd406e9c611d5dfabc71a98eb71d1cc0972c Reviewed-on: https://go-review.googlesource.com/9150 Reviewed-by: Ian Lance Taylor --- src/cmd/go/test.bash | 63 ++++++++++++++++++-------------- src/cmd/link/internal/ld/pobj.go | 4 +- src/go/build/build.go | 8 +++- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash index 1d79a3bea6..8e28d11011 100755 --- a/src/cmd/go/test.bash +++ b/src/cmd/go/test.bash @@ -203,7 +203,7 @@ q' | ed $d/src/$config >/dev/null 2>&1 echo "go get -d -u $url succeeded with wrong remote repo" cat $d/err ok=false - elif ! grep 'should be from' $d/err >/dev/null; then + elif ! grep 'is a custom import path for' $d/err >/dev/null; then echo "go get -d -u $url failed for wrong reason" cat $d/err ok=false @@ -222,9 +222,13 @@ q' | ed $d/src/$config >/dev/null 2>&1 rm -rf $d } -testmove hg rsc.io/x86/x86asm x86 rsc.io/x86/.hg/hgrc testmove git rsc.io/pdf pdf rsc.io/pdf/.git/config -testmove svn code.google.com/p/rsc-svn/trunk - - + +# TODO(rsc): Set up a test case on bitbucket for hg. +# testmove hg rsc.io/x86/x86asm x86 rsc.io/x86/.hg/hgrc + +# TODO(rsc): Set up a test case on SourceForge (?) for svn. +# testmove svn code.google.com/p/rsc-svn/trunk - - export GOPATH=$(pwd)/testdata/importcom TEST 'import comment - match' @@ -896,30 +900,32 @@ if ! ./testgo test -c -test.bench=XXX fmt; then fi rm -f fmt.test -TEST 'Issue 7573: cmd/cgo: undefined reference when linking a C-library using gccgo' -d=$(mktemp -d -t testgoXXX) -export GOPATH=$d -mkdir -p $d/src/cgoref -ldflags="-L alibpath -lalib" -echo " -package main -// #cgo LDFLAGS: $ldflags -// void f(void) {} -import \"C\" - -func main() { C.f() } -" >$d/src/cgoref/cgoref.go -go_cmds="$(./testgo build -n -compiler gccgo cgoref 2>&1 1>/dev/null)" -ldflags_count="$(echo "$go_cmds" | egrep -c "^gccgo.*$(echo $ldflags | sed -e 's/-/\\-/g')" || true)" -if [ "$ldflags_count" -lt 1 ]; then - echo "No Go-inline "#cgo LDFLAGS:" (\"$ldflags\") passed to gccgo linking stage." - ok=false +if which gccgo >/dev/null; then + TEST 'Issue 7573: cmd/cgo: undefined reference when linking a C-library using gccgo' + d=$(mktemp -d -t testgoXXX) + export GOPATH=$d + mkdir -p $d/src/cgoref + ldflags="-L alibpath -lalib" + echo " + package main + // #cgo LDFLAGS: $ldflags + // void f(void) {} + import \"C\" + + func main() { C.f() } + " >$d/src/cgoref/cgoref.go + go_cmds="$(./testgo build -n -compiler gccgo cgoref 2>&1 1>/dev/null)" + ldflags_count="$(echo "$go_cmds" | egrep -c "^gccgo.*$(echo $ldflags | sed -e 's/-/\\-/g')" || true)" + if [ "$ldflags_count" -lt 1 ]; then + echo "No Go-inline "#cgo LDFLAGS:" (\"$ldflags\") passed to gccgo linking stage." + ok=false + fi + rm -rf $d + unset ldflags_count + unset go_cmds + unset ldflags + unset GOPATH fi -rm -rf $d -unset ldflags_count -unset go_cmds -unset ldflags -unset GOPATH TEST list template can use context function if ! ./testgo list -f "GOARCH: {{context.GOARCH}}"; then @@ -1049,6 +1055,7 @@ elif ! grep 'File with non-runnable example was built.' testdata/std.out > /dev/ echo "file with non-runnable example was not built" ok=false fi +rm -f testdata/std.out TEST 'go generate handles simple command' if ! ./testgo generate ./testdata/generate/test1.go > testdata/std.out; then @@ -1103,6 +1110,8 @@ rm -rf $d TEST go vet with external tests d=$(mktemp -d -t testgoXXX) +export GOPATH=$d +./testgo get golang.org/x/tools/cmd/vet export GOPATH=$(pwd)/testdata if ./testgo vet vetpkg >$d/err 2>&1; then echo "go vet vetpkg passes incorrectly" @@ -1127,7 +1136,7 @@ rm -rf $d # clean up if $started; then stop; fi -rm -rf testdata/bin testdata/bin1 +rm -rf testdata/bin testdata/bin1 testdata/std.out rm -f testgo if $allok; then diff --git a/src/cmd/link/internal/ld/pobj.go b/src/cmd/link/internal/ld/pobj.go index 5b24428059..cbb4fa2109 100644 --- a/src/cmd/link/internal/ld/pobj.go +++ b/src/cmd/link/internal/ld/pobj.go @@ -60,12 +60,12 @@ func Ldmain() { INITENTRY = "" Linkmode = LinkAuto - // For testing behavior of go command when tools crash. + // For testing behavior of go command when tools crash silently. // Undocumented, not in standard flag parser to avoid // exposing in usage message. for _, arg := range os.Args { if arg == "-crash_for_testing" { - *(*int)(nil) = 0 + os.Exit(2) } } diff --git a/src/go/build/build.go b/src/go/build/build.go index db6bdcf923..bd84c57a4a 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -492,9 +492,13 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa p.Dir = ctxt.joinPath(srcDir, path) } // Determine canonical import path, if any. + // Exclude results where the import path would include /testdata/. + inTestdata := func(sub string) bool { + return strings.Contains(sub, "/testdata/") || strings.HasSuffix(sub, "/testdata") || strings.HasPrefix(sub, "testdata/") || sub == "testdata" + } if ctxt.GOROOT != "" { root := ctxt.joinPath(ctxt.GOROOT, "src") - if sub, ok := ctxt.hasSubdir(root, p.Dir); ok { + if sub, ok := ctxt.hasSubdir(root, p.Dir); ok && !inTestdata(sub) { p.Goroot = true p.ImportPath = sub p.Root = ctxt.GOROOT @@ -504,7 +508,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa all := ctxt.gopath() for i, root := range all { rootsrc := ctxt.joinPath(root, "src") - if sub, ok := ctxt.hasSubdir(rootsrc, p.Dir); ok { + if sub, ok := ctxt.hasSubdir(rootsrc, p.Dir); ok && !inTestdata(sub) { // We found a potential import path for dir, // but check that using it wouldn't find something // else first.