2023-03-03 07:48:01 +08:00
|
|
|
//go:build unix
|
2020-03-30 06:20:51 +08:00
|
|
|
|
2020-09-03 13:48:39 +08:00
|
|
|
package eval_test
|
2020-03-30 06:20:51 +08:00
|
|
|
|
|
|
|
import (
|
2020-03-31 06:39:03 +08:00
|
|
|
"fmt"
|
2020-03-31 06:48:07 +08:00
|
|
|
"runtime"
|
2020-03-31 06:39:03 +08:00
|
|
|
"syscall"
|
2020-03-30 06:20:51 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
. "src.elv.sh/pkg/eval"
|
2020-09-03 13:48:39 +08:00
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
"src.elv.sh/pkg/tt"
|
2020-03-30 06:20:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExternalCmdExit_Error(t *testing.T) {
|
|
|
|
tt.Test(t, tt.Fn("Error", error.Error), tt.Table{
|
2022-03-25 10:41:49 +08:00
|
|
|
Args(ExternalCmdExit{0x0, "ls", 1}).Rets("ls exited with 0"),
|
|
|
|
Args(ExternalCmdExit{0x100, "ls", 1}).Rets("ls exited with 1"),
|
2020-07-11 01:41:14 +08:00
|
|
|
// Note: all Unix'es have SIGINT = 2, but syscall package has different
|
|
|
|
// string in gccgo("Interrupt") and gc("interrupt").
|
2022-03-25 10:41:49 +08:00
|
|
|
Args(ExternalCmdExit{0x2, "ls", 1}).Rets("ls killed by signal " + syscall.SIGINT.String()),
|
2020-03-31 06:39:03 +08:00
|
|
|
// 0x80 + signal for core dumped
|
2022-03-25 10:41:49 +08:00
|
|
|
Args(ExternalCmdExit{0x82, "ls", 1}).Rets("ls killed by signal " + syscall.SIGINT.String() + " (core dumped)"),
|
2020-03-31 06:39:03 +08:00
|
|
|
// 0x7f + signal<<8 for stopped
|
2022-03-25 10:41:49 +08:00
|
|
|
Args(ExternalCmdExit{0x27f, "ls", 1}).Rets("ls stopped by signal " + syscall.SIGINT.String() + " (pid=1)"),
|
2020-03-30 06:20:51 +08:00
|
|
|
})
|
2020-03-31 06:48:07 +08:00
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
tt.Test(t, tt.Fn("Error", error.Error), tt.Table{
|
|
|
|
// 0x057f + cause<<16 for trapped. SIGTRAP is 5 on all Unix'es but have
|
|
|
|
// different string representations on different OSes.
|
2022-03-25 10:41:49 +08:00
|
|
|
Args(ExternalCmdExit{0x1057f, "ls", 1}).Rets(fmt.Sprintf(
|
2020-03-31 06:48:07 +08:00
|
|
|
"ls stopped by signal %s (pid=1) (trapped 1)", syscall.SIGTRAP)),
|
|
|
|
// 0xff is the only exit code that is not exited, signaled or stopped.
|
2022-03-25 10:41:49 +08:00
|
|
|
Args(ExternalCmdExit{0xff, "ls", 1}).Rets("ls has unknown WaitStatus 255"),
|
2020-03-31 06:48:07 +08:00
|
|
|
})
|
|
|
|
}
|
2020-03-30 06:20:51 +08:00
|
|
|
}
|