github.com/metacubex/mihomo@v1.18.5/common/cmd/cmd_test.go (about) 1 package cmd 2 3 import ( 4 "runtime" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestSplitArgs(t *testing.T) { 11 args := splitArgs("ls") 12 args1 := splitArgs("ls -la") 13 args2 := splitArgs("bash -c ls") 14 args3 := splitArgs("bash -c ls -lahF | grep 'cmd'") 15 16 assert.Equal(t, 1, len(args)) 17 assert.Equal(t, 2, len(args1)) 18 assert.Equal(t, 3, len(args2)) 19 assert.Equal(t, 3, len(args3)) 20 } 21 22 func TestExecCmd(t *testing.T) { 23 if runtime.GOOS == "windows" { 24 _, err := ExecCmd("cmd -c 'dir'") 25 assert.Nil(t, err) 26 return 27 } 28 29 _, err := ExecCmd("ls") 30 _, err1 := ExecCmd("ls -la") 31 _, err2 := ExecCmd("bash -c ls") 32 _, err3 := ExecCmd("bash -c ls -la") 33 _, err4 := ExecCmd("bash -c ls -la | grep 'cmd'") 34 35 assert.Nil(t, err) 36 assert.Nil(t, err1) 37 assert.Nil(t, err2) 38 assert.Nil(t, err3) 39 assert.Nil(t, err4) 40 }