pkg/signal.TestTrap: use a subtest
@@ -14,6 +14,7 @@ import (
)
func buildTestBinary(t *testing.T, tmpdir string, prefix string) (string, string) {
+ t.Helper()
tmpDir, err := ioutil.TempDir(tmpdir, prefix)
assert.NilError(t, err)
exePath := tmpDir + "/" + prefix
@@ -41,6 +42,7 @@ func TestTrap(t *testing.T) {
defer os.RemoveAll(tmpDir)
for _, v := range sigmap {
+ t.Run(v.name, func(t *testing.T) {
cmd := exec.Command(exePath)
cmd.Env = append(os.Environ(), "SIGNAL_TYPE="+v.name)
if v.multiple {
@@ -49,16 +51,16 @@ func TestTrap(t *testing.T) {
err := cmd.Start()
assert.NilError(t, err)
err = cmd.Wait()
- if e, ok := err.(*exec.ExitError); ok {
+ e, ok := err.(*exec.ExitError)
+ assert.Assert(t, ok, "expected exec.ExitError, got %T", e)
+
code := e.Sys().(syscall.WaitStatus).ExitStatus()
if v.multiple {
assert.Check(t, is.DeepEqual(128+int(v.signal.(syscall.Signal)), code))
} else {
assert.Check(t, is.Equal(99, code))
}
- continue
- }
- t.Fatal("process didn't end with any error")
+ })
}
}
