Skip to content

Commit

Permalink
cmd/callgraph: add test of -algo=vta
Browse files Browse the repository at this point in the history
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 <adonovan@google.com>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
  • Loading branch information
adonovan committed Jun 2, 2022
1 parent 76325da commit af82757
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/callgraph/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`<root> --> pkg.init`,
Expand All @@ -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{
`<root> --> pkg.test.main`,
`<root> --> pkg.main`,
Expand All @@ -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)
}
}
Expand Down

0 comments on commit af82757

Please sign in to comment.