exception_unix_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //go:build !windows && !plan9 && !js
  2. package eval_test
  3. import (
  4. "fmt"
  5. "runtime"
  6. "syscall"
  7. "testing"
  8. . "src.elv.sh/pkg/eval"
  9. "src.elv.sh/pkg/tt"
  10. )
  11. func TestExternalCmdExit_Error(t *testing.T) {
  12. tt.Test(t, tt.Fn("Error", error.Error), tt.Table{
  13. tt.Args(ExternalCmdExit{0x0, "ls", 1}).Rets("ls exited with 0"),
  14. tt.Args(ExternalCmdExit{0x100, "ls", 1}).Rets("ls exited with 1"),
  15. // Note: all Unix'es have SIGINT = 2, but syscall package has different
  16. // string in gccgo("Interrupt") and gc("interrupt").
  17. tt.Args(ExternalCmdExit{0x2, "ls", 1}).Rets("ls killed by signal " + syscall.SIGINT.String()),
  18. // 0x80 + signal for core dumped
  19. tt.Args(ExternalCmdExit{0x82, "ls", 1}).Rets("ls killed by signal " + syscall.SIGINT.String() + " (core dumped)"),
  20. // 0x7f + signal<<8 for stopped
  21. tt.Args(ExternalCmdExit{0x27f, "ls", 1}).Rets("ls stopped by signal " + syscall.SIGINT.String() + " (pid=1)"),
  22. })
  23. if runtime.GOOS == "linux" {
  24. tt.Test(t, tt.Fn("Error", error.Error), tt.Table{
  25. // 0x057f + cause<<16 for trapped. SIGTRAP is 5 on all Unix'es but have
  26. // different string representations on different OSes.
  27. tt.Args(ExternalCmdExit{0x1057f, "ls", 1}).Rets(fmt.Sprintf(
  28. "ls stopped by signal %s (pid=1) (trapped 1)", syscall.SIGTRAP)),
  29. // 0xff is the only exit code that is not exited, signaled or stopped.
  30. tt.Args(ExternalCmdExit{0xff, "ls", 1}).Rets("ls has unknown WaitStatus 255"),
  31. })
  32. }
  33. }