From 98728d8fe18a7b61eeffd3fda1b7bac22162cd23 Mon Sep 17 00:00:00 2001 From: polinasok <51177946+polinasok@users.noreply.github.com> Date: Sun, 21 Feb 2021 08:00:05 -0800 Subject: [PATCH] service/dap: improve test coverage for evaluateName feature based on known vscode-go bugs (#2341) * DAP test for github.com/golang/vscode-go/issues/1056 * DAP test for github.com/golang/vscode-go/issues/884 * DAP test for github.com/golang/vscode-go/issues/851 * DAP test for github.com/golang/vscode-go/issues/1053 * DAP test for github.com/golang/vscode-go/issues/1054 * Make DeepSource happy Co-authored-by: Polina Sokolova --- _fixtures/testvariables2.go | 3 +- service/dap/server_test.go | 87 ++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/_fixtures/testvariables2.go b/_fixtures/testvariables2.go index 7efb06aa..4fcee1cf 100644 --- a/_fixtures/testvariables2.go +++ b/_fixtures/testvariables2.go @@ -144,6 +144,7 @@ func main() { f1 := 3.0 i3 := 3 p1 := &i1 + pp1 := &p1 s1 := []string{"one", "two", "three", "four", "five"} s3 := make([]int, 0, 6) a0 := [0]int{} @@ -357,5 +358,5 @@ func main() { } runtime.Breakpoint() - fmt.Println(i1, i2, i3, p1, amb1, s1, s3, a0, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr, ch1, chnil, m1, mnil, m2, m3, m4, upnil, up1, i4, i5, i6, err1, err2, errnil, iface1, iface2, ifacenil, arr1, parr, cpx1, const1, iface3, iface4, recursive1, recursive1.x, iface5, iface2fn1, iface2fn2, bencharr, benchparr, mapinf, mainMenu, b, b2, sd, anonstruct1, anonstruct2, anoniface1, anonfunc, mapanonstruct1, ifacearr, efacearr, ni8, ni16, ni32, ni64, pinf, ninf, nan, zsvmap, zsslice, zsvar, tm, errtypednil, emptyslice, emptymap, byteslice, runeslice, bytearray, runearray, longstr, nilstruct, as2, as2.NonPointerRecieverMethod, s4, iface2map, issue1578, ll, unread, w2, w3, w4, w5) + fmt.Println(i1, i2, i3, p1, pp1, amb1, s1, s3, a0, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr, ch1, chnil, m1, mnil, m2, m3, m4, upnil, up1, i4, i5, i6, err1, err2, errnil, iface1, iface2, ifacenil, arr1, parr, cpx1, const1, iface3, iface4, recursive1, recursive1.x, iface5, iface2fn1, iface2fn2, bencharr, benchparr, mapinf, mainMenu, b, b2, sd, anonstruct1, anonstruct2, anoniface1, anonfunc, mapanonstruct1, ifacearr, efacearr, ni8, ni16, ni32, ni64, pinf, ninf, nan, zsvmap, zsslice, zsvar, tm, errtypednil, emptyslice, emptymap, byteslice, runeslice, bytearray, runearray, longstr, nilstruct, as2, as2.NonPointerRecieverMethod, s4, iface2map, issue1578, ll, unread, w2, w3, w4, w5) } diff --git a/service/dap/server_test.go b/service/dap/server_test.go index aecf5520..2f2220bf 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -1139,6 +1139,20 @@ func TestScopesAndVariablesRequests2(t *testing.T) { expectVarRegex(t, err1, 0, "data", `err1\.\(data\)`, `<\*main\.astruct>\(0x[0-9a-f]+\)`, hasChildren) validateEvaluateName(t, client, err1, 0) } + ref = expectVarRegex(t, locals, -1, "ptrinf", "ptrinf", `<\*interface {}>\(0x[0-9a-f]+\)`, hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + ptrinf_val := client.ExpectVariablesResponse(t) + expectChildren(t, ptrinf_val, "*ptrinf", 1) + ref = expectVarExact(t, ptrinf_val, 0, "", "(*ptrinf)", "", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + ptrinf_val_data := client.ExpectVariablesResponse(t) + expectChildren(t, ptrinf_val_data, "(*ptrinf).data", 1) + expectVarRegex(t, ptrinf_val_data, 0, "data", `\(\*ptrinf\)\.\(data\)`, `<\*\*interface {}>\(0x[0-9a-f]+\)`, hasChildren) + validateEvaluateName(t, client, ptrinf_val_data, 0) + } + } // reflect.Kind == Map expectVarExact(t, locals, -1, "mnil", "mnil", "nil ", noChildren) // key - scalar, value - compound @@ -1217,7 +1231,21 @@ func TestScopesAndVariablesRequests2(t *testing.T) { } } expectVarExact(t, locals, -1, "emptymap", "emptymap", " (length: 0)", noChildren) - // reflect.Kind == Ptr - see testvariables + // reflect.Kind == Ptr + ref = expectVarRegex(t, locals, -1, "pp1", "pp1", `<\*\*int>\(0x[0-9a-f]+\)`, hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + pp1val := client.ExpectVariablesResponse(t) + expectChildren(t, pp1val, "*pp1", 1) + ref = expectVarRegex(t, pp1val, 0, "", `\(\*pp1\)`, `<\*int>\(0x[0-9a-f]+\)`, hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + pp1valval := client.ExpectVariablesResponse(t) + expectChildren(t, pp1valval, "*(*pp1)", 1) + expectVarExact(t, pp1valval, 0, "", "(*(*pp1))", "1", noChildren) + validateEvaluateName(t, client, pp1valval, 0) + } + } // reflect.Kind == Slice ref = expectVarExact(t, locals, -1, "zsslice", "zsslice", "<[]struct {}> (length: 3, cap: 3)", hasChildren) if ref > 0 { @@ -1255,6 +1283,63 @@ func TestScopesAndVariablesRequests2(t *testing.T) { m1 := client.ExpectVariablesResponse(t) expectChildren(t, m1, "m1", 64) // TODO(polina): should be 66. } + + ref = expectVarExact(t, locals, -1, "c1", "c1", "", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + c1 := client.ExpectVariablesResponse(t) + expectChildren(t, c1, "c1", 2) + ref = expectVarExact(t, c1, 1, "sa", "c1.sa", "<[]*main.astruct> (length: 3, cap: 3)", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + c1sa := client.ExpectVariablesResponse(t) + expectChildren(t, c1sa, "c1.sa", 3) + ref = expectVarRegex(t, c1sa, 0, `\[0\]`, `c1\.sa\[0\]`, `<\*main\.astruct>\(0x[0-9a-f]+\)`, hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + c1sa0 := client.ExpectVariablesResponse(t) + expectChildren(t, c1sa0, "c1.sa[0]", 1) + // TODO(polina): there should be a child here once we support auto loading + expectVarExact(t, c1sa0, 0, "", "(*c1.sa[0])", "", noChildren) + } + } + } + + ref = expectVarExact(t, locals, -1, "aas", "aas", "<[]main.a> (length: 1, cap: 1)", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + aas := client.ExpectVariablesResponse(t) + expectChildren(t, aas, "aas", 1) + ref = expectVarExact(t, aas, 0, "[0]", "aas[0]", "", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + aas0 := client.ExpectVariablesResponse(t) + expectChildren(t, aas0, "aas[0]", 1) + ref = expectVarExact(t, aas0, 0, "aas", "aas[0].aas", "<[]main.a> (length: 1, cap: 1)", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + aas0aas := client.ExpectVariablesResponse(t) + expectChildren(t, aas0aas, "aas[0].aas", 1) + // TODO(polina): there should be a child here once we support auto loading - test for "aas[0].aas[0].aas" + expectVarExact(t, aas0aas, 0, "[0]", "aas[0].aas[0]", "", noChildren) + } + } + } + + ref = expectVarExact(t, locals, -1, "tm", "tm", "", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + tm := client.ExpectVariablesResponse(t) + expectChildren(t, tm, "tm", 1) + ref = expectVarExact(t, tm, 0, "v", "tm.v", "<[]map[string]main.astruct> (length: 1, cap: 1)", hasChildren) + if ref > 0 { + client.VariablesRequest(ref) + tm_v := client.ExpectVariablesResponse(t) + expectChildren(t, tm_v, "tm.v", 1) + // TODO(polina): there should be children here once we support auto loading - test for "tm.v[0]["gutters"]" + expectVarExact(t, tm_v, 0, "[0]", "tm.v[0]", " (length: 66)", noChildren) + } + } }, disconnect: true, }})