Commit 023047d1 authored by Russ Cox's avatar Russ Cox

cmd/go: diagnose trivial test import cycle

Was detecting only non-trivial ones.

Fixes #9690.

Change-Id: I662d81dd4818ddf29592057c090805772c84287b
Reviewed-on: https://go-review.googlesource.com/12147Reviewed-by: 's avatarRob Pike <r@golang.org>
parent ea918ef5
......@@ -1848,6 +1848,9 @@ func TestGoTestDetectsTestOnlyImportCycles(t *testing.T) {
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "-c", "testcycle/p3")
tg.grepStderr("import cycle not allowed in test", "go test testcycle/p3 produced unexpected error")
tg.runFail("test", "-c", "testcycle/q1")
tg.grepStderr("import cycle not allowed in test", "go test testcycle/q1 produced unexpected error")
}
func TestGoTestFooTestWorks(t *testing.T) {
......
......@@ -578,7 +578,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
if p1.Error != nil {
return nil, nil, nil, p1.Error
}
if contains(p1.Deps, p.ImportPath) {
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
// non-test copy of a package.
......
package q1
import "testing"
import _ "testcycle/q1"
func Test(t *testing.T) {}
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