github.com/trevoraustin/hub@v2.2.0-preview1.0.20141105230840-96d8bfc654cc+incompatible/commands/runner_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/bmizerany/assert"
     5  	"testing"
     6  )
     7  
     8  func TestRunner_splitAliasCmd(t *testing.T) {
     9  	words, err := splitAliasCmd("!source ~/.zshrc")
    10  	assert.NotEqual(t, nil, err)
    11  
    12  	words, err = splitAliasCmd("log --pretty=oneline --abbrev-commit --graph --decorate")
    13  	assert.Equal(t, nil, err)
    14  	assert.Equal(t, 5, len(words))
    15  
    16  	words, err = splitAliasCmd("")
    17  	assert.NotEqual(t, nil, err)
    18  }
    19  
    20  func TestRunnerUseCommands(t *testing.T) {
    21  	r := NewRunner()
    22  	c := &Command{Usage: "foo"}
    23  	r.Use(c)
    24  
    25  	assert.Equal(t, c, r.Lookup("foo"))
    26  }
    27  
    28  func TestRunnerCallCommands(t *testing.T) {
    29  	var result string
    30  	f := func(c *Command, args *Args) {
    31  		result = args.FirstParam()
    32  		args.Replace("echo", "", "true")
    33  	}
    34  
    35  	r := NewRunner()
    36  	c := &Command{Usage: "foo", Run: f}
    37  	r.Use(c)
    38  
    39  	args := NewArgs([]string{"foo", "bar"})
    40  	err := r.Call(c, args)
    41  
    42  	assert.Equal(t, 0, err.ExitCode)
    43  	assert.Equal(t, "bar", result)
    44  }