Skip to content

Commit 2b2a44e

Browse files
committed
gopls/internal/test: avoid panic in TestDoubleParamReturnCompletion
An invalid assumption in this test led to an out of bounds error, which likely masked a real error or timeout. Update the test to not panic, and factor. Fixes golang/go#71906 Change-Id: Ib01d3b75df8bdb71984457807312cfe1d27ddf73 Reviewed-on: https://go-review.googlesource.com/c/tools/+/651896 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 739a5af commit 2b2a44e

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

Diff for: gopls/internal/test/integration/completion/completion_test.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -1212,25 +1212,21 @@ func TestDoubleParamReturnCompletion(t *testing.T) {
12121212
Run(t, src, func(t *testing.T, env *Env) {
12131213
env.OpenFile("a.go")
12141214

1215-
compl := env.RegexpSearch("a.go", `DoubleWrap\[()\]\(\)`)
1216-
result := env.Completion(compl)
1217-
1218-
wantLabel := []string{"InterfaceA", "TypeA", "InterfaceB", "TypeB", "TypeC"}
1219-
1220-
for i, item := range result.Items[:len(wantLabel)] {
1221-
if diff := cmp.Diff(wantLabel[i], item.Label); diff != "" {
1222-
t.Errorf("Completion: unexpected label mismatch (-want +got):\n%s", diff)
1223-
}
1215+
tests := map[string][]string{
1216+
`DoubleWrap\[()\]\(\)`: {"InterfaceA", "TypeA", "InterfaceB", "TypeB", "TypeC"},
1217+
`DoubleWrap\[InterfaceA, (_)\]\(\)`: {"InterfaceB", "TypeB", "TypeX", "InterfaceA", "TypeA"},
12241218
}
12251219

1226-
compl = env.RegexpSearch("a.go", `DoubleWrap\[InterfaceA, (_)\]\(\)`)
1227-
result = env.Completion(compl)
1228-
1229-
wantLabel = []string{"InterfaceB", "TypeB", "TypeX", "InterfaceA", "TypeA"}
1230-
1231-
for i, item := range result.Items[:len(wantLabel)] {
1232-
if diff := cmp.Diff(wantLabel[i], item.Label); diff != "" {
1233-
t.Errorf("Completion: unexpected label mismatch (-want +got):\n%s", diff)
1220+
for re, wantLabels := range tests {
1221+
compl := env.RegexpSearch("a.go", re)
1222+
result := env.Completion(compl)
1223+
if len(result.Items) < len(wantLabels) {
1224+
t.Fatalf("Completion(%q) returned mismatching labels: got %v, want at least labels %v", re, result.Items, wantLabels)
1225+
}
1226+
for i, item := range result.Items[:len(wantLabels)] {
1227+
if diff := cmp.Diff(wantLabels[i], item.Label); diff != "" {
1228+
t.Errorf("Completion(%q): unexpected label mismatch (-want +got):\n%s", re, diff)
1229+
}
12341230
}
12351231
}
12361232
})

0 commit comments

Comments
 (0)