]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: diagnose trivial test import cycle
authorRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 02:39:17 +0000 (22:39 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 04:13:55 +0000 (04:13 +0000)
Was detecting only non-trivial ones.

Fixes #9690.

Change-Id: I662d81dd4818ddf29592057c090805772c84287b
Reviewed-on: https://go-review.googlesource.com/12147
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/go/go_test.go
src/cmd/go/test.go
src/cmd/go/testdata/src/testcycle/q1/q1.go [new file with mode: 0644]
src/cmd/go/testdata/src/testcycle/q1/q1_test.go [new file with mode: 0644]

index 59c2cffa9ff76cbb03360ac55c1addc99f37c761..bb22076ce4d6d815ae40e3ba3c46cb1084e5dd94 100644 (file)
@@ -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) {
index 1f138bc3f5f5e6d830ea3d8d2eb5499a4757f3b4..7ea8d53ad17ce3f9acc3c7e468bbb5cbe3409898 100644 (file)
@@ -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.
diff --git a/src/cmd/go/testdata/src/testcycle/q1/q1.go b/src/cmd/go/testdata/src/testcycle/q1/q1.go
new file mode 100644 (file)
index 0000000..7a471f0
--- /dev/null
@@ -0,0 +1 @@
+package q1
diff --git a/src/cmd/go/testdata/src/testcycle/q1/q1_test.go b/src/cmd/go/testdata/src/testcycle/q1/q1_test.go
new file mode 100644 (file)
index 0000000..ca81bd2
--- /dev/null
@@ -0,0 +1,6 @@
+package q1
+
+import "testing"
+import _ "testcycle/q1"
+
+func Test(t *testing.T) {}