From fec4d1f60d661c44ff920425ed99d24c8aaec863 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 18 Sep 2014 10:05:26 -0400 Subject: [PATCH] refactor/importgraph: add test of cycles Nodes in a strongly connected component (which includes most stdlib packages) appear in results of both "forward" and "reverse" searches from any other node in the same SCC. LGTM=sameer R=sameer CC=golang-codereviews, gri https://golang.org/cl/136470044 --- refactor/importgraph/graph_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/refactor/importgraph/graph_test.go b/refactor/importgraph/graph_test.go index 739565a9..694fbdb6 100644 --- a/refactor/importgraph/graph_test.go +++ b/refactor/importgraph/graph_test.go @@ -59,6 +59,20 @@ func TestBuild(t *testing.T) { } } + // Test strongly-connected components. Because A's external + // test package can depend on B, and vice versa, most of the + // standard libraries are mutually dependent when their external + // tests are considered. + // + // For any nodes x, y in the same SCC, y appears in the results + // of both forward and reverse searches starting from x + if !forward.Search("fmt")["io"] || + !forward.Search("io")["fmt"] || + !reverse.Search("fmt")["io"] || + !reverse.Search("io")["fmt"] { + t.Errorf("fmt and io are not mutually reachable despite being in the same SCC") + } + // debugging if false { for path, err := range errors { @@ -76,6 +90,6 @@ func TestBuild(t *testing.T) { } } printSorted("forward", forward, this) - printSorted("forward", reverse, this) + printSorted("reverse", reverse, this) } }