File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
"regexp"
28
28
"strings"
29
29
"sync"
30
+ "syscall"
30
31
"testing"
31
32
"text/template"
32
33
"time"
@@ -50,6 +51,8 @@ type TestCmd struct {
50
51
stdout * bufio.Reader
51
52
stdin io.WriteCloser
52
53
stderr * testlogger
54
+ // Err will contain the process exit error or interrupt signal error
55
+ Err error
53
56
}
54
57
55
58
// Run exec's the current binary using name as argv[0] which will trigger the
@@ -182,11 +185,25 @@ func (tt *TestCmd) ExpectExit() {
182
185
}
183
186
184
187
func (tt * TestCmd ) WaitExit () {
185
- tt .cmd .Wait ()
188
+ tt .Err = tt . cmd .Wait ()
186
189
}
187
190
188
191
func (tt * TestCmd ) Interrupt () {
189
- tt .cmd .Process .Signal (os .Interrupt )
192
+ tt .Err = tt .cmd .Process .Signal (os .Interrupt )
193
+ }
194
+
195
+ // ExitStatus exposes the process' OS exit code
196
+ // It will only return a valid value after the process has finished.
197
+ func (tt * TestCmd ) ExitStatus () int {
198
+ if tt .Err != nil {
199
+ exitErr := tt .Err .(* exec.ExitError )
200
+ if exitErr != nil {
201
+ if status , ok := exitErr .Sys ().(syscall.WaitStatus ); ok {
202
+ return status .ExitStatus ()
203
+ }
204
+ }
205
+ }
206
+ return 0
190
207
}
191
208
192
209
// StderrText returns any stderr output written so far.
You can’t perform that action at this time.
0 commit comments