From e60942a39d2485275cc75f9518932a8208dc5e2d Mon Sep 17 00:00:00 2001 From: Wesley Merkel Date: Wed, 6 Apr 2016 09:26:10 -0700 Subject: [PATCH] terminal: show message if there are no vars/locals/args When the vars, locals, or args commands return no results, nothing is printed out to the terminal. This commit makes these commands print a message like `(no locals)` when there is nothing to show. This feedback is more descriptive of what is being returned than an empty string. --- terminal/command.go | 13 ++++++++++--- terminal/command_test.go | 12 +++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/terminal/command.go b/terminal/command.go index 2ec893a9..41793806 100644 --- a/terminal/command.go +++ b/terminal/command.go @@ -682,7 +682,7 @@ func args(t *Term, ctx callContext, filter string) ([]string, error) { if err != nil { return nil, err } - return filterVariables(vars, filter), nil + return describeNoVars("args", filterVariables(vars, filter)), nil } func locals(t *Term, ctx callContext, filter string) ([]string, error) { @@ -690,7 +690,7 @@ func locals(t *Term, ctx callContext, filter string) ([]string, error) { if err != nil { return nil, err } - return filterVariables(locals, filter), nil + return describeNoVars("locals", filterVariables(locals, filter)), nil } func vars(t *Term, ctx callContext, filter string) ([]string, error) { @@ -698,7 +698,7 @@ func vars(t *Term, ctx callContext, filter string) ([]string, error) { if err != nil { return nil, err } - return filterVariables(vars, filter), nil + return describeNoVars("vars", filterVariables(vars, filter)), nil } func regs(t *Term, ctx callContext, args string) error { @@ -1153,3 +1153,10 @@ func formatBreakpointLocation(bp *api.Breakpoint) string { } return fmt.Sprintf("%#v for %s:%d", bp.Addr, p, bp.Line) } + +func describeNoVars(varType string, data []string) []string { + if len(data) == 0 { + return []string{fmt.Sprintf("(no %s)", varType)} + } + return data +} diff --git a/terminal/command_test.go b/terminal/command_test.go index eea6bdeb..c37b90a1 100644 --- a/terminal/command_test.go +++ b/terminal/command_test.go @@ -269,7 +269,7 @@ func TestScopePrefix(t *testing.T) { if fid < 0 { t.Fatalf("Could not find frame for goroutine %d: %v", gid, stackOut) } - term.AssertExec(fmt.Sprintf("goroutine %d frame %d locals", gid, fid), "") + term.AssertExec(fmt.Sprintf("goroutine %d frame %d locals", gid, fid), "(no locals)\n") argsOut := strings.Split(term.MustExec(fmt.Sprintf("goroutine %d frame %d args", gid, fid)), "\n") if len(argsOut) != 4 || argsOut[3] != "" { t.Fatalf("Wrong number of arguments in goroutine %d frame %d: %v", gid, fid, argsOut) @@ -347,3 +347,13 @@ func TestOnPrefix(t *testing.T) { } }) } + +func TestNoVars(t *testing.T) { + withTestTerminal("locationsUpperCase", t, func(term *FakeTerminal) { + term.MustExec("b main.main") + term.MustExec("continue") + term.AssertExec("args", "(no args)\n") + term.AssertExec("locals", "(no locals)\n") + term.AssertExec("vars filterThatMatchesNothing", "(no vars)\n") + }) +} -- GitLab