mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 10:47:27 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package terminal
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/derekparker/delve/service"
 | |
| )
 | |
| 
 | |
| func TestCommandDefault(t *testing.T) {
 | |
| 	var (
 | |
| 		cmds = Commands{}
 | |
| 		cmd  = cmds.Find("non-existant-command")
 | |
| 	)
 | |
| 
 | |
| 	err := cmd(nil)
 | |
| 	if err == nil {
 | |
| 		t.Fatal("cmd() did not default")
 | |
| 	}
 | |
| 
 | |
| 	if err.Error() != "command not available" {
 | |
| 		t.Fatal("wrong command output")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestCommandReplay(t *testing.T) {
 | |
| 	cmds := DebugCommands(nil)
 | |
| 	cmds.Register("foo", func(client service.Client, args ...string) error { return fmt.Errorf("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)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 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())
 | |
| 	}
 | |
| }
 | 
