pkg/eval: Test all branches of ExternalCmdExit.Error.

This addresses #944.
This commit is contained in:
Qi Xiao 2020-03-30 23:39:03 +01:00
parent 0d30e926c9
commit 4f26803226

View File

@ -3,6 +3,8 @@
package eval package eval
import ( import (
"fmt"
"syscall"
"testing" "testing"
"github.com/elves/elvish/pkg/tt" "github.com/elves/elvish/pkg/tt"
@ -10,6 +12,20 @@ import (
func TestExternalCmdExit_Error(t *testing.T) { func TestExternalCmdExit_Error(t *testing.T) {
tt.Test(t, tt.Fn("Error", error.Error), tt.Table{ tt.Test(t, tt.Fn("Error", error.Error), tt.Table{
tt.Args(ExternalCmdExit{0, "ls", 100}).Rets("ls exited with 0"), tt.Args(ExternalCmdExit{0x0, "ls", 1}).Rets("ls exited with 0"),
tt.Args(ExternalCmdExit{0x100, "ls", 1}).Rets("ls exited with 1"),
// Note: all Unix'es have SIGINT = 2 and the syscall package has same
// string for it ("interrupt").
tt.Args(ExternalCmdExit{0x2, "ls", 1}).Rets("ls killed by signal interrupt"),
// 0x80 + signal for core dumped
tt.Args(ExternalCmdExit{0x82, "ls", 1}).Rets("ls killed by signal interrupt (core dumped)"),
// 0x7f + signal<<8 for stopped
tt.Args(ExternalCmdExit{0x27f, "ls", 1}).Rets("ls stopped by signal interrupt (pid=1)"),
// 0x057f + cause<<16 for trapped. SIGTRAP is 5 on all Unix'es but have
// different string representations on different OSes.
tt.Args(ExternalCmdExit{0x1057f, "ls", 1}).Rets(fmt.Sprintf(
"ls stopped by signal %s (pid=1) (trapped 1)", syscall.SIGTRAP)),
// 0xff is the only exit code that is not exited, signaled or stopped.
tt.Args(ExternalCmdExit{0xff, "ls", 1}).Rets("ls has unknown WaitStatus 255"),
}) })
} }