You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/nsys/cmdr/cmd_test.go

36 lines
740 B
Go

package cmdr_test
import (
"fmt"
"git.noahlan.cn/noahlan/ntool/nsys/cmdr"
"git.noahlan.cn/noahlan/ntool/ntest/assert"
"testing"
)
func TestNewCmd(t *testing.T) {
c := cmdr.NewCmd("ls").
WithArg("-l").
WithArgs([]string{"-h"}).
AddArg("-a").
AddArgf("%s", "./")
assert.Eq(t, "ls", c.BinName())
assert.Eq(t, "ls", c.IDString())
assert.StrContains(t, "ls", c.BinOrPath())
assert.NotContains(t, c.OnlyArgs(), "ls")
c.OnBefore(func(c *cmdr.Cmd) {
assert.Eq(t, "ls -l -h -a ./", c.Cmdline())
})
out := c.SafeOutput()
fmt.Println(out)
assert.NotEmpty(t, out)
assert.NotEmpty(t, cmdr.OutputLines(out))
assert.NotEmpty(t, cmdr.FirstLine(out))
c.ResetArgs()
assert.Len(t, c.Args, 1)
assert.Empty(t, c.OnlyArgs())
}