Skip to content

Commit 48abc3e

Browse files
adonovanfindleyr
authored andcommitted
[gopls-release-branch.0.16] go/callgraph/vta: fix test under GODEBUG=gotypesalias=1
The test expectations depend on whether aliases are materialized; update them, and suppress the test when gotypesalias=0. Also, clarify the failure message. Fixes golang/go#68799 Change-Id: I4cb9429377e5423d04651c45a99d0c3fee5bef5e Reviewed-on: https://go-review.googlesource.com/c/tools/+/604257 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Zvonimir Pavlinovic <[email protected]> Auto-Submit: Alan Donovan <[email protected]> (cherry picked from commit 4dc9194) Reviewed-on: https://go-review.googlesource.com/c/tools/+/609417
1 parent 7765a37 commit 48abc3e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

go/callgraph/vta/testdata/src/callgraph_type_aliases.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// This file is the same as callgraph_interfaces.go except for
88
// types J, X, Y, and Z aliasing types I, A, B, and C, resp.
9+
// This test requires GODEBUG=gotypesalias=1 (the default in go1.23).
910

1011
package testdata
1112

@@ -57,11 +58,11 @@ func Baz(b bool) {
5758

5859
// func Do(b bool) I:
5960
// ...
60-
// t1 = (C).Foo(struct{}{}:C)
61+
// t1 = (C).Foo(struct{}{}:Z)
6162
// t2 = NewY()
6263
// t3 = make I <- B (t2)
6364
// return t3
6465

6566
// WANT:
6667
// Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
67-
// Do: (C).Foo(struct{}{}:C) -> C.Foo; NewY() -> NewY
68+
// Do: (C).Foo(struct{}{}:Z) -> C.Foo; NewY() -> NewY

go/callgraph/vta/vta_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
package vta
66

77
import (
8+
"strings"
89
"testing"
910

11+
"github.com/google/go-cmp/cmp"
1012
"golang.org/x/tools/go/analysis"
1113
"golang.org/x/tools/go/analysis/analysistest"
1214
"golang.org/x/tools/go/analysis/passes/buildssa"
1315
"golang.org/x/tools/go/callgraph/cha"
1416
"golang.org/x/tools/go/ssa"
1517
"golang.org/x/tools/go/ssa/ssautil"
18+
"golang.org/x/tools/internal/aliases"
1619
)
1720

1821
func TestVTACallGraph(t *testing.T) {
@@ -30,6 +33,11 @@ func TestVTACallGraph(t *testing.T) {
3033
"testdata/src/callgraph_type_aliases.go",
3134
} {
3235
t.Run(file, func(t *testing.T) {
36+
// https://github.com/golang/go/issues/68799
37+
if !aliases.Enabled() && file == "testdata/src/callgraph_type_aliases.go" {
38+
t.Skip("callgraph_type_aliases.go requires gotypesalias=1")
39+
}
40+
3341
prog, want, err := testProg(file, ssa.BuilderMode(0))
3442
if err != nil {
3543
t.Fatalf("couldn't load test file '%s': %s", file, err)
@@ -40,8 +48,12 @@ func TestVTACallGraph(t *testing.T) {
4048

4149
g := CallGraph(ssautil.AllFunctions(prog), cha.CallGraph(prog))
4250
got := callGraphStr(g)
43-
if diff := setdiff(want, got); len(diff) > 0 {
44-
t.Errorf("computed callgraph %v\nshould contain\n%v\n(diff: %v)", got, want, diff)
51+
if missing := setdiff(want, got); len(missing) > 0 {
52+
t.Errorf("got:\n%s\n\nwant:\n%s\n\nmissing:\n%s\n\ndiff:\n%s",
53+
strings.Join(got, "\n"),
54+
strings.Join(want, "\n"),
55+
strings.Join(missing, "\n"),
56+
cmp.Diff(got, want)) // to aid debugging
4557
}
4658
})
4759
}

0 commit comments

Comments
 (0)