delve/terminal/command_test.go

54 lines
1012 B
Go
Raw Normal View History

package terminal
2014-05-20 21:28:24 +00:00
2014-05-20 23:09:34 +00:00
import (
"errors"
2014-05-20 23:09:34 +00:00
"testing"
"github.com/derekparker/delve/service"
2014-05-20 23:09:34 +00:00
)
2014-05-20 21:28:24 +00:00
func TestCommandDefault(t *testing.T) {
var (
cmds = Commands{}
2014-05-20 21:28:24 +00:00
cmd = cmds.Find("non-existant-command")
)
err := cmd(nil)
2014-05-20 21:28:24 +00:00
if err == nil {
t.Fatal("cmd() did not default")
}
if err.Error() != "command not available" {
t.Fatal("wrong command output")
}
}
2014-05-20 23:09:34 +00:00
func TestCommandReplay(t *testing.T) {
cmds := DebugCommands(nil)
cmds.Register("foo", func(client service.Client, args ...string) error { return errors.New("registered command") }, "foo command")
cmd := cmds.Find("foo")
err := cmd(nil)
if err.Error() != "registered command" {
t.Fatal("wrong command output")
}
cmd = cmds.Find("")
err = cmd(nil)
if err.Error() != "registered command" {
t.Fatal("wrong command output")
}
}
func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
var (
cmds = DebugCommands(nil)
cmd = cmds.Find("")
err = cmd(nil)
)
if err != nil {
t.Error("Null command not returned", err)
}
}