Commit c345f7ff authored by Russ Cox's avatar Russ Cox

cmd/go: make test.bash pass again

Fixes #8809.

Change-Id: Id443fd406e9c611d5dfabc71a98eb71d1cc0972c
Reviewed-on: https://go-review.googlesource.com/9150Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 107aab6c
...@@ -203,7 +203,7 @@ q' | ed $d/src/$config >/dev/null 2>&1 ...@@ -203,7 +203,7 @@ q' | ed $d/src/$config >/dev/null 2>&1
echo "go get -d -u $url succeeded with wrong remote repo" echo "go get -d -u $url succeeded with wrong remote repo"
cat $d/err cat $d/err
ok=false 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" echo "go get -d -u $url failed for wrong reason"
cat $d/err cat $d/err
ok=false ok=false
...@@ -222,9 +222,13 @@ q' | ed $d/src/$config >/dev/null 2>&1 ...@@ -222,9 +222,13 @@ q' | ed $d/src/$config >/dev/null 2>&1
rm -rf $d 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 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 export GOPATH=$(pwd)/testdata/importcom
TEST 'import comment - match' TEST 'import comment - match'
...@@ -896,30 +900,32 @@ if ! ./testgo test -c -test.bench=XXX fmt; then ...@@ -896,30 +900,32 @@ if ! ./testgo test -c -test.bench=XXX fmt; then
fi fi
rm -f fmt.test rm -f fmt.test
TEST 'Issue 7573: cmd/cgo: undefined reference when linking a C-library using gccgo' if which gccgo >/dev/null; then
d=$(mktemp -d -t testgoXXX) TEST 'Issue 7573: cmd/cgo: undefined reference when linking a C-library using gccgo'
export GOPATH=$d d=$(mktemp -d -t testgoXXX)
mkdir -p $d/src/cgoref export GOPATH=$d
ldflags="-L alibpath -lalib" mkdir -p $d/src/cgoref
echo " ldflags="-L alibpath -lalib"
package main echo "
// #cgo LDFLAGS: $ldflags package main
// void f(void) {} // #cgo LDFLAGS: $ldflags
import \"C\" // void f(void) {}
import \"C\"
func main() { C.f() }
" >$d/src/cgoref/cgoref.go func main() { C.f() }
go_cmds="$(./testgo build -n -compiler gccgo cgoref 2>&1 1>/dev/null)" " >$d/src/cgoref/cgoref.go
ldflags_count="$(echo "$go_cmds" | egrep -c "^gccgo.*$(echo $ldflags | sed -e 's/-/\\-/g')" || true)" go_cmds="$(./testgo build -n -compiler gccgo cgoref 2>&1 1>/dev/null)"
if [ "$ldflags_count" -lt 1 ]; then ldflags_count="$(echo "$go_cmds" | egrep -c "^gccgo.*$(echo $ldflags | sed -e 's/-/\\-/g')" || true)"
echo "No Go-inline "#cgo LDFLAGS:" (\"$ldflags\") passed to gccgo linking stage." if [ "$ldflags_count" -lt 1 ]; then
ok=false 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 fi
rm -rf $d
unset ldflags_count
unset go_cmds
unset ldflags
unset GOPATH
TEST list template can use context function TEST list template can use context function
if ! ./testgo list -f "GOARCH: {{context.GOARCH}}"; then 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/ ...@@ -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" echo "file with non-runnable example was not built"
ok=false ok=false
fi fi
rm -f testdata/std.out
TEST 'go generate handles simple command' TEST 'go generate handles simple command'
if ! ./testgo generate ./testdata/generate/test1.go > testdata/std.out; then if ! ./testgo generate ./testdata/generate/test1.go > testdata/std.out; then
...@@ -1103,6 +1110,8 @@ rm -rf $d ...@@ -1103,6 +1110,8 @@ rm -rf $d
TEST go vet with external tests TEST go vet with external tests
d=$(mktemp -d -t testgoXXX) d=$(mktemp -d -t testgoXXX)
export GOPATH=$d
./testgo get golang.org/x/tools/cmd/vet
export GOPATH=$(pwd)/testdata export GOPATH=$(pwd)/testdata
if ./testgo vet vetpkg >$d/err 2>&1; then if ./testgo vet vetpkg >$d/err 2>&1; then
echo "go vet vetpkg passes incorrectly" echo "go vet vetpkg passes incorrectly"
...@@ -1127,7 +1136,7 @@ rm -rf $d ...@@ -1127,7 +1136,7 @@ rm -rf $d
# clean up # clean up
if $started; then stop; fi if $started; then stop; fi
rm -rf testdata/bin testdata/bin1 rm -rf testdata/bin testdata/bin1 testdata/std.out
rm -f testgo rm -f testgo
if $allok; then if $allok; then
......
...@@ -60,12 +60,12 @@ func Ldmain() { ...@@ -60,12 +60,12 @@ func Ldmain() {
INITENTRY = "" INITENTRY = ""
Linkmode = LinkAuto 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 // Undocumented, not in standard flag parser to avoid
// exposing in usage message. // exposing in usage message.
for _, arg := range os.Args { for _, arg := range os.Args {
if arg == "-crash_for_testing" { if arg == "-crash_for_testing" {
*(*int)(nil) = 0 os.Exit(2)
} }
} }
......
...@@ -492,9 +492,13 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa ...@@ -492,9 +492,13 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
p.Dir = ctxt.joinPath(srcDir, path) p.Dir = ctxt.joinPath(srcDir, path)
} }
// Determine canonical import path, if any. // 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 != "" { if ctxt.GOROOT != "" {
root := ctxt.joinPath(ctxt.GOROOT, "src") 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.Goroot = true
p.ImportPath = sub p.ImportPath = sub
p.Root = ctxt.GOROOT p.Root = ctxt.GOROOT
...@@ -504,7 +508,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa ...@@ -504,7 +508,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
all := ctxt.gopath() all := ctxt.gopath()
for i, root := range all { for i, root := range all {
rootsrc := ctxt.joinPath(root, "src") 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, // We found a potential import path for dir,
// but check that using it wouldn't find something // but check that using it wouldn't find something
// else first. // else first.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment