]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: make test.bash pass again
authorRuss Cox <rsc@golang.org>
Mon, 20 Apr 2015 17:34:22 +0000 (13:34 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 3 Jun 2015 20:33:30 +0000 (20:33 +0000)
Fixes #8809.

Change-Id: Id443fd406e9c611d5dfabc71a98eb71d1cc0972c
Reviewed-on: https://go-review.googlesource.com/9150
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/test.bash
src/cmd/link/internal/ld/pobj.go
src/go/build/build.go

index 1d79a3bea66401b31615d5cc7ee945619698f22a..8e28d11011e27a12a8b676045d67809e821e3f55 100755 (executable)
@@ -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
index 5b24428059eaab48a72c5f62b2f3414fbfe06346..cbb4fa210978259e22c0b09e982e965d9f6ad212 100644 (file)
@@ -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)
                }
        }
 
index db6bdcf923b7df338dc79528a37cd18f4e1a860d..bd84c57a4a60ae112897d62bddb19a94fa5ef99a 100644 (file)
@@ -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.