未验证 提交 79e6f7fa 编写于 作者: P polinasok 提交者: GitHub

service/dap: minor test refactoring (#2421)

上级 c4b9c858
...@@ -50,18 +50,18 @@ func (c *Client) ReadMessage() (dap.Message, error) { ...@@ -50,18 +50,18 @@ func (c *Client) ReadMessage() (dap.Message, error) {
return dap.ReadProtocolMessage(c.reader) return dap.ReadProtocolMessage(c.reader)
} }
func (c *Client) expectReadProtocolMessage(t *testing.T) dap.Message { func (c *Client) ExpectMessage(t *testing.T) dap.Message {
t.Helper() t.Helper()
m, err := dap.ReadProtocolMessage(c.reader) m, err := dap.ReadProtocolMessage(c.reader)
if err != nil { if err != nil {
t.Error(err) t.Fatal(err)
} }
return m return m
} }
func (c *Client) ExpectErrorResponse(t *testing.T) *dap.ErrorResponse { func (c *Client) ExpectErrorResponse(t *testing.T) *dap.ErrorResponse {
t.Helper() t.Helper()
er := c.expectReadProtocolMessage(t).(*dap.ErrorResponse) er := c.ExpectMessage(t).(*dap.ErrorResponse)
if er.Body.Error.ShowUser { if er.Body.Error.ShowUser {
t.Errorf("\ngot %#v\nwant ShowUser=false", er) t.Errorf("\ngot %#v\nwant ShowUser=false", er)
} }
...@@ -70,7 +70,7 @@ func (c *Client) ExpectErrorResponse(t *testing.T) *dap.ErrorResponse { ...@@ -70,7 +70,7 @@ func (c *Client) ExpectErrorResponse(t *testing.T) *dap.ErrorResponse {
func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse { func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
t.Helper() t.Helper()
er := c.expectReadProtocolMessage(t).(*dap.ErrorResponse) er := c.ExpectMessage(t).(*dap.ErrorResponse)
if !er.Body.Error.ShowUser { if !er.Body.Error.ShowUser {
t.Errorf("\ngot %#v\nwant ShowUser=true", er) t.Errorf("\ngot %#v\nwant ShowUser=true", er)
} }
...@@ -79,7 +79,7 @@ func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse { ...@@ -79,7 +79,7 @@ func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
func (c *Client) expectErrorResponse(t *testing.T, id int, message string) *dap.ErrorResponse { func (c *Client) expectErrorResponse(t *testing.T, id int, message string) *dap.ErrorResponse {
t.Helper() t.Helper()
er := c.expectReadProtocolMessage(t).(*dap.ErrorResponse) er := c.ExpectMessage(t).(*dap.ErrorResponse)
if er.Body.Error.Id != id || er.Message != message { if er.Body.Error.Id != id || er.Message != message {
t.Errorf("\ngot %#v\nwant Id=%d Message=%q", er, id, message) t.Errorf("\ngot %#v\nwant Id=%d Message=%q", er, id, message)
} }
...@@ -98,37 +98,37 @@ func (c *Client) ExpectUnsupportedCommandErrorResponse(t *testing.T) *dap.ErrorR ...@@ -98,37 +98,37 @@ func (c *Client) ExpectUnsupportedCommandErrorResponse(t *testing.T) *dap.ErrorR
func (c *Client) ExpectDisconnectResponse(t *testing.T) *dap.DisconnectResponse { func (c *Client) ExpectDisconnectResponse(t *testing.T) *dap.DisconnectResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.DisconnectResponse) return c.ExpectMessage(t).(*dap.DisconnectResponse)
} }
func (c *Client) ExpectContinueResponse(t *testing.T) *dap.ContinueResponse { func (c *Client) ExpectContinueResponse(t *testing.T) *dap.ContinueResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ContinueResponse) return c.ExpectMessage(t).(*dap.ContinueResponse)
} }
func (c *Client) ExpectNextResponse(t *testing.T) *dap.NextResponse { func (c *Client) ExpectNextResponse(t *testing.T) *dap.NextResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.NextResponse) return c.ExpectMessage(t).(*dap.NextResponse)
} }
func (c *Client) ExpectStepInResponse(t *testing.T) *dap.StepInResponse { func (c *Client) ExpectStepInResponse(t *testing.T) *dap.StepInResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.StepInResponse) return c.ExpectMessage(t).(*dap.StepInResponse)
} }
func (c *Client) ExpectStepOutResponse(t *testing.T) *dap.StepOutResponse { func (c *Client) ExpectStepOutResponse(t *testing.T) *dap.StepOutResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.StepOutResponse) return c.ExpectMessage(t).(*dap.StepOutResponse)
} }
func (c *Client) ExpectTerminatedEvent(t *testing.T) *dap.TerminatedEvent { func (c *Client) ExpectTerminatedEvent(t *testing.T) *dap.TerminatedEvent {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.TerminatedEvent) return c.ExpectMessage(t).(*dap.TerminatedEvent)
} }
func (c *Client) ExpectInitializeResponse(t *testing.T) *dap.InitializeResponse { func (c *Client) ExpectInitializeResponse(t *testing.T) *dap.InitializeResponse {
t.Helper() t.Helper()
initResp := c.expectReadProtocolMessage(t).(*dap.InitializeResponse) initResp := c.ExpectMessage(t).(*dap.InitializeResponse)
if !initResp.Body.SupportsConfigurationDoneRequest { if !initResp.Body.SupportsConfigurationDoneRequest {
t.Errorf("got %#v, want SupportsConfigurationDoneRequest=true", initResp) t.Errorf("got %#v, want SupportsConfigurationDoneRequest=true", initResp)
} }
...@@ -137,167 +137,167 @@ func (c *Client) ExpectInitializeResponse(t *testing.T) *dap.InitializeResponse ...@@ -137,167 +137,167 @@ func (c *Client) ExpectInitializeResponse(t *testing.T) *dap.InitializeResponse
func (c *Client) ExpectInitializedEvent(t *testing.T) *dap.InitializedEvent { func (c *Client) ExpectInitializedEvent(t *testing.T) *dap.InitializedEvent {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.InitializedEvent) return c.ExpectMessage(t).(*dap.InitializedEvent)
} }
func (c *Client) ExpectLaunchResponse(t *testing.T) *dap.LaunchResponse { func (c *Client) ExpectLaunchResponse(t *testing.T) *dap.LaunchResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.LaunchResponse) return c.ExpectMessage(t).(*dap.LaunchResponse)
} }
func (c *Client) ExpectAttachResponse(t *testing.T) *dap.AttachResponse { func (c *Client) ExpectAttachResponse(t *testing.T) *dap.AttachResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.AttachResponse) return c.ExpectMessage(t).(*dap.AttachResponse)
} }
func (c *Client) ExpectSetExceptionBreakpointsResponse(t *testing.T) *dap.SetExceptionBreakpointsResponse { func (c *Client) ExpectSetExceptionBreakpointsResponse(t *testing.T) *dap.SetExceptionBreakpointsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.SetExceptionBreakpointsResponse) return c.ExpectMessage(t).(*dap.SetExceptionBreakpointsResponse)
} }
func (c *Client) ExpectSetBreakpointsResponse(t *testing.T) *dap.SetBreakpointsResponse { func (c *Client) ExpectSetBreakpointsResponse(t *testing.T) *dap.SetBreakpointsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.SetBreakpointsResponse) return c.ExpectMessage(t).(*dap.SetBreakpointsResponse)
} }
func (c *Client) ExpectStoppedEvent(t *testing.T) *dap.StoppedEvent { func (c *Client) ExpectStoppedEvent(t *testing.T) *dap.StoppedEvent {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.StoppedEvent) return c.ExpectMessage(t).(*dap.StoppedEvent)
} }
func (c *Client) ExpectOutputEvent(t *testing.T) *dap.OutputEvent { func (c *Client) ExpectOutputEvent(t *testing.T) *dap.OutputEvent {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.OutputEvent) return c.ExpectMessage(t).(*dap.OutputEvent)
} }
func (c *Client) ExpectConfigurationDoneResponse(t *testing.T) *dap.ConfigurationDoneResponse { func (c *Client) ExpectConfigurationDoneResponse(t *testing.T) *dap.ConfigurationDoneResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ConfigurationDoneResponse) return c.ExpectMessage(t).(*dap.ConfigurationDoneResponse)
} }
func (c *Client) ExpectThreadsResponse(t *testing.T) *dap.ThreadsResponse { func (c *Client) ExpectThreadsResponse(t *testing.T) *dap.ThreadsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ThreadsResponse) return c.ExpectMessage(t).(*dap.ThreadsResponse)
} }
func (c *Client) ExpectStackTraceResponse(t *testing.T) *dap.StackTraceResponse { func (c *Client) ExpectStackTraceResponse(t *testing.T) *dap.StackTraceResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.StackTraceResponse) return c.ExpectMessage(t).(*dap.StackTraceResponse)
} }
func (c *Client) ExpectScopesResponse(t *testing.T) *dap.ScopesResponse { func (c *Client) ExpectScopesResponse(t *testing.T) *dap.ScopesResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ScopesResponse) return c.ExpectMessage(t).(*dap.ScopesResponse)
} }
func (c *Client) ExpectVariablesResponse(t *testing.T) *dap.VariablesResponse { func (c *Client) ExpectVariablesResponse(t *testing.T) *dap.VariablesResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.VariablesResponse) return c.ExpectMessage(t).(*dap.VariablesResponse)
} }
func (c *Client) ExpectEvaluateResponse(t *testing.T) *dap.EvaluateResponse { func (c *Client) ExpectEvaluateResponse(t *testing.T) *dap.EvaluateResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.EvaluateResponse) return c.ExpectMessage(t).(*dap.EvaluateResponse)
} }
func (c *Client) ExpectTerminateResponse(t *testing.T) *dap.TerminateResponse { func (c *Client) ExpectTerminateResponse(t *testing.T) *dap.TerminateResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.TerminateResponse) return c.ExpectMessage(t).(*dap.TerminateResponse)
} }
func (c *Client) ExpectRestartResponse(t *testing.T) *dap.RestartResponse { func (c *Client) ExpectRestartResponse(t *testing.T) *dap.RestartResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.RestartResponse) return c.ExpectMessage(t).(*dap.RestartResponse)
} }
func (c *Client) ExpectSetFunctionBreakpointsResponse(t *testing.T) *dap.SetFunctionBreakpointsResponse { func (c *Client) ExpectSetFunctionBreakpointsResponse(t *testing.T) *dap.SetFunctionBreakpointsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.SetFunctionBreakpointsResponse) return c.ExpectMessage(t).(*dap.SetFunctionBreakpointsResponse)
} }
func (c *Client) ExpectStepBackResponse(t *testing.T) *dap.StepBackResponse { func (c *Client) ExpectStepBackResponse(t *testing.T) *dap.StepBackResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.StepBackResponse) return c.ExpectMessage(t).(*dap.StepBackResponse)
} }
func (c *Client) ExpectReverseContinueResponse(t *testing.T) *dap.ReverseContinueResponse { func (c *Client) ExpectReverseContinueResponse(t *testing.T) *dap.ReverseContinueResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ReverseContinueResponse) return c.ExpectMessage(t).(*dap.ReverseContinueResponse)
} }
func (c *Client) ExpectRestartFrameResponse(t *testing.T) *dap.RestartFrameResponse { func (c *Client) ExpectRestartFrameResponse(t *testing.T) *dap.RestartFrameResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.RestartFrameResponse) return c.ExpectMessage(t).(*dap.RestartFrameResponse)
} }
func (c *Client) ExpectSetExpressionResponse(t *testing.T) *dap.SetExpressionResponse { func (c *Client) ExpectSetExpressionResponse(t *testing.T) *dap.SetExpressionResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.SetExpressionResponse) return c.ExpectMessage(t).(*dap.SetExpressionResponse)
} }
func (c *Client) ExpectTerminateThreadsResponse(t *testing.T) *dap.TerminateThreadsResponse { func (c *Client) ExpectTerminateThreadsResponse(t *testing.T) *dap.TerminateThreadsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.TerminateThreadsResponse) return c.ExpectMessage(t).(*dap.TerminateThreadsResponse)
} }
func (c *Client) ExpectStepInTargetsResponse(t *testing.T) *dap.StepInTargetsResponse { func (c *Client) ExpectStepInTargetsResponse(t *testing.T) *dap.StepInTargetsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.StepInTargetsResponse) return c.ExpectMessage(t).(*dap.StepInTargetsResponse)
} }
func (c *Client) ExpectGotoTargetsResponse(t *testing.T) *dap.GotoTargetsResponse { func (c *Client) ExpectGotoTargetsResponse(t *testing.T) *dap.GotoTargetsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.GotoTargetsResponse) return c.ExpectMessage(t).(*dap.GotoTargetsResponse)
} }
func (c *Client) ExpectCompletionsResponse(t *testing.T) *dap.CompletionsResponse { func (c *Client) ExpectCompletionsResponse(t *testing.T) *dap.CompletionsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.CompletionsResponse) return c.ExpectMessage(t).(*dap.CompletionsResponse)
} }
func (c *Client) ExpectExceptionInfoResponse(t *testing.T) *dap.ExceptionInfoResponse { func (c *Client) ExpectExceptionInfoResponse(t *testing.T) *dap.ExceptionInfoResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ExceptionInfoResponse) return c.ExpectMessage(t).(*dap.ExceptionInfoResponse)
} }
func (c *Client) ExpectLoadedSourcesResponse(t *testing.T) *dap.LoadedSourcesResponse { func (c *Client) ExpectLoadedSourcesResponse(t *testing.T) *dap.LoadedSourcesResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.LoadedSourcesResponse) return c.ExpectMessage(t).(*dap.LoadedSourcesResponse)
} }
func (c *Client) ExpectDataBreakpointInfoResponse(t *testing.T) *dap.DataBreakpointInfoResponse { func (c *Client) ExpectDataBreakpointInfoResponse(t *testing.T) *dap.DataBreakpointInfoResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.DataBreakpointInfoResponse) return c.ExpectMessage(t).(*dap.DataBreakpointInfoResponse)
} }
func (c *Client) ExpectSetDataBreakpointsResponse(t *testing.T) *dap.SetDataBreakpointsResponse { func (c *Client) ExpectSetDataBreakpointsResponse(t *testing.T) *dap.SetDataBreakpointsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.SetDataBreakpointsResponse) return c.ExpectMessage(t).(*dap.SetDataBreakpointsResponse)
} }
func (c *Client) ExpectReadMemoryResponse(t *testing.T) *dap.ReadMemoryResponse { func (c *Client) ExpectReadMemoryResponse(t *testing.T) *dap.ReadMemoryResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ReadMemoryResponse) return c.ExpectMessage(t).(*dap.ReadMemoryResponse)
} }
func (c *Client) ExpectDisassembleResponse(t *testing.T) *dap.DisassembleResponse { func (c *Client) ExpectDisassembleResponse(t *testing.T) *dap.DisassembleResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.DisassembleResponse) return c.ExpectMessage(t).(*dap.DisassembleResponse)
} }
func (c *Client) ExpectCancelResponse(t *testing.T) *dap.CancelResponse { func (c *Client) ExpectCancelResponse(t *testing.T) *dap.CancelResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.CancelResponse) return c.ExpectMessage(t).(*dap.CancelResponse)
} }
func (c *Client) ExpectBreakpointLocationsResponse(t *testing.T) *dap.BreakpointLocationsResponse { func (c *Client) ExpectBreakpointLocationsResponse(t *testing.T) *dap.BreakpointLocationsResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.BreakpointLocationsResponse) return c.ExpectMessage(t).(*dap.BreakpointLocationsResponse)
} }
func (c *Client) ExpectModulesResponse(t *testing.T) *dap.ModulesResponse { func (c *Client) ExpectModulesResponse(t *testing.T) *dap.ModulesResponse {
t.Helper() t.Helper()
return c.expectReadProtocolMessage(t).(*dap.ModulesResponse) return c.ExpectMessage(t).(*dap.ModulesResponse)
} }
// InitializeRequest sends an 'initialize' request. // InitializeRequest sends an 'initialize' request.
...@@ -317,7 +317,7 @@ func (c *Client) InitializeRequest() { ...@@ -317,7 +317,7 @@ func (c *Client) InitializeRequest() {
} }
// LaunchRequest sends a 'launch' request with the specified args. // LaunchRequest sends a 'launch' request with the specified args.
func (c *Client) LaunchRequest(mode string, program string, stopOnEntry bool) { func (c *Client) LaunchRequest(mode, program string, stopOnEntry bool) {
request := &dap.LaunchRequest{Request: *c.newRequest("launch")} request := &dap.LaunchRequest{Request: *c.newRequest("launch")}
request.Arguments = map[string]interface{}{ request.Arguments = map[string]interface{}{
"request": "launch", "request": "launch",
......
...@@ -2236,12 +2236,7 @@ func TestStepOutPreservesGoroutine(t *testing.T) { ...@@ -2236,12 +2236,7 @@ func TestStepOutPreservesGoroutine(t *testing.T) {
client.StepOutRequest(goroutineId) client.StepOutRequest(goroutineId)
client.ExpectStepOutResponse(t) client.ExpectStepOutResponse(t)
m, err := client.ReadMessage() switch e := client.ExpectMessage(t).(type) {
if err != nil {
t.Fatal(err)
}
switch e := m.(type) {
case *dap.StoppedEvent: case *dap.StoppedEvent:
if e.Body.ThreadId != goroutineId { if e.Body.ThreadId != goroutineId {
t.Fatalf("StepOut did not continue on the selected goroutine, expected %d got %d", goroutineId, e.Body.ThreadId) t.Fatalf("StepOut did not continue on the selected goroutine, expected %d got %d", goroutineId, e.Body.ThreadId)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册