From af82757ce06909d72478bb74408412eb3ed4828a Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 2 Jun 2022 17:53:23 -0400 Subject: [PATCH] cmd/callgraph: add test of -algo=vta This should have been included in https://go-review.googlesource.com/c/tools/+/410138 Change-Id: Ic8a4f1b5dbcdb320fb872b24484b830dcb56fd41 Reviewed-on: https://go-review.googlesource.com/c/tools/+/410123 Run-TryBot: Alan Donovan Reviewed-by: Tim King gopls-CI: kokoro TryBot-Result: Gopher Robot Reviewed-by: Zvonimir Pavlinovic --- cmd/callgraph/main_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/callgraph/main_test.go b/cmd/callgraph/main_test.go index cd9838a5e7f..c8bee87e2b9 100644 --- a/cmd/callgraph/main_test.go +++ b/cmd/callgraph/main_test.go @@ -59,6 +59,12 @@ func TestCallgraph(t *testing.T) { `pkg.main2 --> (pkg.C).f`, `pkg.main2 --> (pkg.D).f`, }}, + {"vta", false, []string{ + // vta distinguishes main->C, main2->D. + "pkg.main --> (pkg.C).f", + "pkg.main --> pkg.main2", + "pkg.main2 --> (pkg.D).f", + }}, {"pta", false, []string{ // pta distinguishes main->C, main2->D. Also has a root node. ` --> pkg.init`, @@ -75,6 +81,12 @@ func TestCallgraph(t *testing.T) { `pkg.Example --> (pkg.C).f`, `pkg.main --> (pkg.C).f`, }}, + {"vta", true, []string{ + `pkg.test.main --> testing.MainStart`, + `testing.runExample --> pkg.Example`, + `pkg.Example --> (pkg.C).f`, + `pkg.main --> (pkg.C).f`, + }}, {"pta", true, []string{ ` --> pkg.test.main`, ` --> pkg.main`, @@ -95,13 +107,15 @@ func TestCallgraph(t *testing.T) { for _, line := range strings.Split(fmt.Sprint(stdout), "\n") { edges[line] = true } + ok := true for _, edge := range test.want { if !edges[edge] { + ok = false t.Errorf("callgraph(%q, %t): missing edge: %s", test.algo, test.tests, edge) } } - if t.Failed() { + if !ok { t.Log("got:\n", stdout) } }