From 0b38b5d4ec9d7f00c6ddf50806536d6a0979f933 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 23 Jun 2021 14:21:19 -0400 Subject: [PATCH] service/dap: fix error string format (#2549) --- service/dap/server.go | 6 +++--- service/dap/server_test.go | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/service/dap/server.go b/service/dap/server.go index d5e1aeff..f7c8cb42 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -1072,7 +1072,7 @@ func (s *Server) onSetBreakpointsRequest(request *dap.SetBreakpointsRequest) { continue } if _, ok := bpAdded[reqString]; ok { - err = fmt.Errorf("Breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column) + err = fmt.Errorf("breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column) } else { got.Cond = want.Condition got.HitCond = want.HitCondition @@ -1099,7 +1099,7 @@ func (s *Server) onSetBreakpointsRequest(request *dap.SetBreakpointsRequest) { var got *api.Breakpoint var err error if _, ok := bpAdded[reqString]; ok { - err = fmt.Errorf("Breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column) + err = fmt.Errorf("breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column) } else { // Create new breakpoints. got, err = s.debugger.CreateBreakpoint( @@ -1167,7 +1167,7 @@ func (s *Server) onSetFunctionBreakpointsRequest(request *dap.SetFunctionBreakpo continue } if _, ok := bpAdded[reqString]; ok { - err = fmt.Errorf("Breakpoint exists at function %q", want.Name) + err = fmt.Errorf("breakpoint exists at function %q", want.Name) } else { got.Cond = want.Condition got.HitCond = want.HitCondition diff --git a/service/dap/server_test.go b/service/dap/server_test.go index b1670435..0e042a87 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -1947,7 +1947,7 @@ func checkBreakpoints(t *testing.T, client *daptest.Client, bps []Breakpoint, br } for i, bp := range breakpoints { if bps[i].line < 0 && !bps[i].verified { - if bp.Verified != bps[i].verified || !strings.Contains(bp.Message, bps[i].msgPrefix) { + if bp.Verified != bps[i].verified || !stringContainsCaseInsensitive(bp.Message, bps[i].msgPrefix) { t.Errorf("got breakpoints[%d] = %#v, \nwant %#v", i, bp, bps[i]) } continue @@ -1990,7 +1990,7 @@ func TestSetBreakpoint(t *testing.T) { // Set another breakpoint inside the loop in loop(), twice to trigger error client.SetBreakpointsRequest(fixture.Source, []int{8, 8}) - expectSetBreakpointsResponse(t, client, []Breakpoint{{8, fixture.Source, true, ""}, {-1, "", false, "Breakpoint exists"}}) + expectSetBreakpointsResponse(t, client, []Breakpoint{{8, fixture.Source, true, ""}, {-1, "", false, "breakpoint exists"}}) // Continue into the loop client.ContinueRequest(1) @@ -2037,6 +2037,10 @@ func TestSetBreakpoint(t *testing.T) { }) } +func stringContainsCaseInsensitive(got, want string) bool { + return strings.Contains(strings.ToLower(got), strings.ToLower(want)) +} + // TestSetFunctionBreakpoints is inspired by service/test.TestClientServer_FindLocations. func TestSetFunctionBreakpoints(t *testing.T) { runTest(t, "locationsprog", func(client *daptest.Client, fixture protest.Fixture) { @@ -2066,7 +2070,7 @@ func TestSetFunctionBreakpoints(t *testing.T) { } for i, bp := range got.Body.Breakpoints { if bps[i].line < 0 && !bps[i].verified { - if bp.Verified != bps[i].verified || !strings.Contains(bp.Message, bps[i].errMsg) { + if bp.Verified != bps[i].verified || !stringContainsCaseInsensitive(bp.Message, bps[i].errMsg) { t.Errorf("got breakpoints[%d] = %#v, \nwant %#v", i, bp, bps[i]) } continue @@ -2213,7 +2217,7 @@ func TestSetFunctionBreakpoints(t *testing.T) { client.SetFunctionBreakpointsRequest([]dap.FunctionBreakpoint{ {Name: "SomeType.String"}, {Name: "(*SomeType).String"}, }) - expectSetFunctionBreakpointsResponse([]Breakpoint{{14, filepath.Base(fixture.Source), true, ""}, {-1, "", false, "Breakpoint exists"}}) + expectSetFunctionBreakpointsResponse([]Breakpoint{{14, filepath.Base(fixture.Source), true, ""}, {-1, "", false, "breakpoint exists"}}) // Set two breakpoints at SomeType.String and SomeType.SomeFunction. client.SetFunctionBreakpointsRequest([]dap.FunctionBreakpoint{ @@ -3701,7 +3705,7 @@ func TestLaunchDebugRequest(t *testing.T) { // BinaryInfo.Close(), but it appears that it is still in use (by Windows?) // shortly after. gobuild.Remove has a delay to address this, but // to avoid any test flakiness we guard against this failure here as well. - if runtime.GOOS != "windows" || !strings.Contains(rmErr, "Access is denied") { + if runtime.GOOS != "windows" || !stringContainsCaseInsensitive(rmErr, "Access is denied") { t.Fatalf("Binary removal failure:\n%s\n", rmErr) } } else { @@ -4014,7 +4018,7 @@ func (h *helperForSetVariable) failSetVariable0(ref int, name, value, wantErrInf h.c.ExpectStoppedEvent(h.t) } resp := h.c.ExpectErrorResponse(h.t) - if got := resp.Body.Error.Format; !strings.Contains(got, wantErrInfo) { + if got := resp.Body.Error.Format; !stringContainsCaseInsensitive(got, wantErrInfo) { h.t.Errorf("got %#v, want error string containing %v", got, wantErrInfo) } }