]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: give full import stack for errors in dependencies of test dependencies
authorRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 05:56:51 +0000 (01:56 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 04:28:00 +0000 (04:28 +0000)
Fixes #9558.

Change-Id: I68506af58088155d38d492b49b19c5fc2048b087
Reviewed-on: https://go-review.googlesource.com/12176
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/go/go_test.go
src/cmd/go/test.go

index 59e90b7f6037d91a7837b4cea8159bc381f12017..c8741ca2ff1ff168ffb0f5866ffa2aa2f0026120 100644 (file)
@@ -2094,3 +2094,17 @@ func TestGoTestRaceInstallCgo(t *testing.T) {
                t.Fatalf("go test -i runtime/race reinstalled cmd/cgo")
        }
 }
+
+func TestGoTestImportErrorStack(t *testing.T) {
+       const out = `package testdep/p1 (test)
+       imports testdep/p2
+       imports testdep/p3: no buildable Go source files`
+
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+       tg.runFail("test", "testdep/p1")
+       if !strings.Contains(tg.stderr.String(), out) {
+               t.Fatal("did not give full import stack:\n\n%s", tg.stderr.String())
+       }
+}
index e62f4bd19d4f1647b7c356206ae5414678741158..aeb422860022d2142c34ea5590728f9cdab35387 100644 (file)
@@ -578,6 +578,11 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                if p1.Error != nil {
                        return nil, nil, nil, p1.Error
                }
+               if len(p1.DepsErrors) > 0 {
+                       err := p1.DepsErrors[0]
+                       err.Pos = "" // show full import stack
+                       return nil, nil, nil, err
+               }
                if contains(p1.Deps, p.ImportPath) || p1.ImportPath == p.ImportPath {
                        // Same error that loadPackage returns (via reusePackage) in pkg.go.
                        // Can't change that code, because that code is only for loading the
@@ -604,6 +609,11 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                if p1.Error != nil {
                        return nil, nil, nil, p1.Error
                }
+               if len(p1.DepsErrors) > 0 {
+                       err := p1.DepsErrors[0]
+                       err.Pos = "" // show full import stack
+                       return nil, nil, nil, err
+               }
                ximports = append(ximports, p1)
                p.XTestImports[i] = p1.ImportPath
        }