mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
test: add TestExecCommandWithOption
This commit is contained in:
@@ -4,18 +4,11 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func WithForeground() Option {
|
func WithForeground() Option {
|
||||||
return func(c *exec.Cmd) {
|
return func(c *exec.Cmd) {
|
||||||
if c.SysProcAttr == nil {
|
|
||||||
c.SysProcAttr = &syscall.SysProcAttr{
|
|
||||||
Foreground: true,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
c.SysProcAttr.Foreground = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,16 @@ func TestExecCommand(t *testing.T) {
|
|||||||
assert.IsNotNil(err)
|
assert.IsNotNil(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExecCommandWithOption(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestExecCommand")
|
||||||
|
|
||||||
|
stdout, stderr, err := ExecCommand("ls", WithForeground())
|
||||||
|
t.Log("std out: ", stdout)
|
||||||
|
t.Log("std err: ", stderr)
|
||||||
|
assert.Equal("", stderr)
|
||||||
|
assert.IsNil(err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetOsBits(t *testing.T) {
|
func TestGetOsBits(t *testing.T) {
|
||||||
osBits := GetOsBits()
|
osBits := GetOsBits()
|
||||||
switch osBits {
|
switch osBits {
|
||||||
|
|||||||
@@ -18,3 +18,9 @@ func WithWinHide() Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithForeground() Option {
|
||||||
|
return func(c *exec.Cmd) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user