mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
41 lines
805 B
Go
41 lines
805 B
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"runtime"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestSplitArgs(t *testing.T) {
|
||
|
args := splitArgs("ls")
|
||
|
args1 := splitArgs("ls -la")
|
||
|
args2 := splitArgs("bash -c ls")
|
||
|
args3 := splitArgs("bash -c ls -lahF | grep 'cmd'")
|
||
|
|
||
|
assert.Equal(t, 1, len(args))
|
||
|
assert.Equal(t, 2, len(args1))
|
||
|
assert.Equal(t, 3, len(args2))
|
||
|
assert.Equal(t, 3, len(args3))
|
||
|
}
|
||
|
|
||
|
func TestExecCmd(t *testing.T) {
|
||
|
if runtime.GOOS == "windows" {
|
||
|
_, err := ExecCmd("dir")
|
||
|
assert.Nil(t, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
_, err := ExecCmd("ls")
|
||
|
_, err1 := ExecCmd("ls -la")
|
||
|
_, err2 := ExecCmd("bash -c ls")
|
||
|
_, err3 := ExecCmd("bash -c ls -la")
|
||
|
_, err4 := ExecCmd("bash -c ls -la | grep 'cmd'")
|
||
|
|
||
|
assert.Nil(t, err)
|
||
|
assert.Nil(t, err1)
|
||
|
assert.Nil(t, err2)
|
||
|
assert.Nil(t, err3)
|
||
|
assert.Nil(t, err4)
|
||
|
}
|