2015-03-20 21:11:11 +00:00
|
|
|
package terminal
|
2014-05-20 21:28:24 +00:00
|
|
|
|
2014-05-20 23:09:34 +00:00
|
|
|
import (
|
2015-05-04 22:31:13 +00:00
|
|
|
"fmt"
|
2014-05-20 23:09:34 +00:00
|
|
|
"testing"
|
|
|
|
)
|
2014-05-20 21:28:24 +00:00
|
|
|
|
|
|
|
func TestCommandDefault(t *testing.T) {
|
|
|
|
var (
|
2014-11-14 05:51:32 +00:00
|
|
|
cmds = Commands{}
|
2014-05-20 21:28:24 +00:00
|
|
|
cmd = cmds.Find("non-existant-command")
|
|
|
|
)
|
|
|
|
|
2014-06-25 19:58:45 +00:00
|
|
|
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
|
|
|
|
2014-05-21 15:15:58 +00:00
|
|
|
func TestCommandReplay(t *testing.T) {
|
2015-03-20 21:11:11 +00:00
|
|
|
cmds := DebugCommands(nil)
|
2015-09-30 05:42:06 +00:00
|
|
|
cmds.Register("foo", func(t *Term, args ...string) error { return fmt.Errorf("registered command") }, "foo command")
|
2014-05-21 15:15:58 +00:00
|
|
|
cmd := cmds.Find("foo")
|
|
|
|
|
2014-06-25 19:58:45 +00:00
|
|
|
err := cmd(nil)
|
2014-05-21 15:15:58 +00:00
|
|
|
if err.Error() != "registered command" {
|
|
|
|
t.Fatal("wrong command output")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = cmds.Find("")
|
2014-06-25 19:58:45 +00:00
|
|
|
err = cmd(nil)
|
2014-05-21 15:15:58 +00:00
|
|
|
if err.Error() != "registered command" {
|
|
|
|
t.Fatal("wrong command output")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
|
|
|
|
var (
|
2015-03-20 21:11:11 +00:00
|
|
|
cmds = DebugCommands(nil)
|
2014-05-21 15:15:58 +00:00
|
|
|
cmd = cmds.Find("")
|
2014-06-25 19:58:45 +00:00
|
|
|
err = cmd(nil)
|
2014-05-21 15:15:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Null command not returned", err)
|
|
|
|
}
|
|
|
|
}
|
2015-05-30 07:23:41 +00:00
|
|
|
|
|
|
|
func TestCommandThread(t *testing.T) {
|
|
|
|
var (
|
|
|
|
cmds = DebugCommands(nil)
|
|
|
|
cmd = cmds.Find("thread")
|
|
|
|
)
|
|
|
|
|
|
|
|
err := cmd(nil)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("thread terminal command did not default")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err.Error() != "you must specify a thread" {
|
|
|
|
t.Fatal("wrong command output: ", err.Error())
|
|
|
|
}
|
|
|
|
}
|