Skip to content

Commit b7f8e32

Browse files
kolyshkinpcmoore
authored andcommitted
test: simplify execInSubprocess
Use CombinedOutput to simplify the code. Signed-off-by: Kir Kolyshkin <[email protected]> [PM: subject line tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent 398b733 commit b7f8e32

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

seccomp_test.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,11 @@ func execInSubprocess(t *testing.T, f func(t *testing.T)) {
3333
cmd.Env = []string{subprocessEnvKey + "=1"}
3434
cmd.Stdin = os.Stdin
3535

36-
var b strings.Builder
37-
cmd.Stdout = &b
38-
cmd.Stderr = &b
39-
40-
err := cmd.Start()
36+
out, err := cmd.CombinedOutput()
37+
t.Logf("%s", out)
4138
if err != nil {
42-
t.Logf("\n%s", b.String())
43-
t.Error("failed to spawn test in sub-process", err)
44-
t.FailNow()
45-
}
46-
47-
err = cmd.Wait()
48-
if err != nil {
49-
t.Logf("\n%s", b.String())
50-
if err, ok := err.(*exec.ExitError); ok {
51-
// err.ExitCode() not available in go1.11
52-
// https://github.com/golang/go/issues/26539
53-
t.Errorf("Test failed: %v", err.String())
54-
}
55-
t.Error(`test failed`)
56-
t.FailNow()
39+
t.Fatal(err)
5740
}
58-
t.Logf("\n%s", b.String())
5941
}
6042

6143
// Type Function Tests

0 commit comments

Comments
 (0)