Skip to content

Commit

Permalink
修正不重要的錯誤而導致測試沒過的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonSlovoka committed Jan 27, 2024
1 parent 1988a30 commit 0331fa7
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions v2/os/exec/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,50 @@ import (
)

func ExampleTaskKill() {
testApp := "powershell.exe" // 如果用taskmgr.exe(Task manager)會需要提升管理權限才有辦法運行,否則會有錯誤: The requested operation requires elevation.
if err := exec.Command(testApp).Start(); err != nil { // please run with admin
panic(err) // The requested operation requires elevation.
testApp := "powershell.exe" // 如果用taskmgr.exe(Task manager)會需要提升管理權限才有辦法運行,否則會有錯誤: The requested operation requires elevation.

var err error

defer func() {
if err != nil {
log.Println(err)
}
}()

if err = exec.Command(testApp).Start(); err != nil { // please run with admin
return // The requested operation requires elevation.
}
time.Sleep(250 * time.Millisecond)
if err := TaskKill(testApp); err != nil {
panic(err)
if err = TaskKill(testApp); err != nil {
return
}
if IsTaskRunning(testApp) {
panic("The program was still alive.")
err = fmt.Errorf("the program was still alive")
}

// Output:
}

func ExampleIsTaskRunning() {
testApp := "taskmgr.exe" // Task manager
if err := exec.Command(testApp).Start(); err != nil { // please run with admin
panic(err) // The requested operation requires elevation.
testApp := "taskmgr.exe" // Task manager

var err error
defer func() {
if err != nil {
log.Println(err)
}
}()

if err = exec.Command(testApp).Start(); err != nil { // please run with admin
return // The requested operation requires elevation.
}
time.Sleep(250 * time.Millisecond)
if err := TaskKill(testApp); err != nil {
panic(err)
if err = TaskKill(testApp); err != nil {
return
}
if IsTaskRunning(testApp) {
panic("The program was still alive.")
err = fmt.Errorf("the program was still alive")
return
}
}

Expand Down

0 comments on commit 0331fa7

Please sign in to comment.