1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 00:32:27 +08:00

fix: fix ExecCommand bug in windows

This commit is contained in:
dudaodong
2022-12-09 19:10:55 +08:00
parent af5cfe6da1
commit 09d98745b0
2 changed files with 64 additions and 20 deletions

View File

@@ -11,10 +11,10 @@ func TestOsDetection(t *testing.T) {
assert := internal.NewAssert(t, "TestOsJudgment")
osType, _, _ := ExecCommand("echo $OSTYPE")
if strings.Index(osType, "linux") != -1 {
if strings.Contains(osType, "linux") {
assert.Equal(true, IsLinux())
}
if strings.Index(osType, "darwin") != -1 {
if strings.Contains(osType, "darwin") {
assert.Equal(true, IsMac())
}
}
@@ -44,21 +44,27 @@ func TestOsEnvOperation(t *testing.T) {
func TestExecCommand(t *testing.T) {
assert := internal.NewAssert(t, "TestExecCommand")
out, errout, err := ExecCommand("ls")
t.Log("std out: ", out)
t.Log("std err: ", errout)
// linux or mac
stdout, stderr, err := ExecCommand("ls")
t.Log("std out: ", stdout)
t.Log("std err: ", stderr)
assert.Equal("", stderr)
assert.IsNil(err)
out, errout, err = ExecCommand("abc")
t.Log("std out: ", out)
t.Log("std err: ", errout)
if err != nil {
t.Logf("error: %v\n", err)
}
// windows
stdout, stderr, err = ExecCommand("dir")
t.Log("std out: ", stdout)
t.Log("std err: ", stderr)
assert.IsNil(err)
if !IsWindows() {
assert.IsNotNil(err)
}
// error command
stdout, stderr, err = ExecCommand("abc")
t.Log("std out: ", stdout)
t.Log("std err: ", stderr)
// if err != nil {
// t.Log(err.Error())
// }
assert.IsNotNil(err)
}
func TestGetOsBits(t *testing.T) {