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/runner_test.go

42 lines
819 B
Go

1 year ago
package cmdr_test
import (
"bytes"
"fmt"
"git.noahlan.cn/noahlan/ntool/nsys/cmdr"
"git.noahlan.cn/noahlan/ntool/ntest/assert"
"testing"
)
func TestRunner_Run(t *testing.T) {
buf := new(bytes.Buffer)
rr := cmdr.NewRunner()
rr.Add(&cmdr.Task{
ID: "task1",
Cmd: cmdr.NewCmd("id").WithOutput(buf, buf),
})
rr.AddCmd(cmdr.NewCmd("ls").
AddArgs([]string{"-l", "-h"}).
WithOutput(buf, buf).
OnBefore(cmdr.PrintCmdline))
task, err := rr.Task("task1")
assert.NoErr(t, err)
assert.NoErr(t, task.Err())
assert.True(t, task.IsSuccess())
ids := rr.TaskIDs()
// dump.P(rr.TaskIDs())
assert.Len(t, ids, 2)
assert.NotEmpty(t, ids)
assert.Contains(t, ids, task.ID)
err = rr.Run()
assert.NoErr(t, err)
assert.NoErr(t, rr.Errs.One())
assert.True(t, rr.Errs.IsEmpty())
fmt.Println(buf.String())
}