File tree 1 file changed +22
-4
lines changed
1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 8
8
"path/filepath"
9
9
"runtime"
10
10
"strings"
11
+ "sync"
11
12
"syscall"
12
13
"time"
13
14
@@ -49,15 +50,32 @@ func ProcessExitCode(err error) (exitCode int) {
49
50
return
50
51
}
51
52
53
+ type lockedBuffer struct {
54
+ m sync.RWMutex
55
+ buf bytes.Buffer
56
+ }
57
+
58
+ func (buf * lockedBuffer ) Write (b []byte ) (int , error ) {
59
+ buf .m .Lock ()
60
+ defer buf .m .Unlock ()
61
+ return buf .buf .Write (b )
62
+ }
63
+
64
+ func (buf * lockedBuffer ) String () string {
65
+ buf .m .RLock ()
66
+ defer buf .m .RUnlock ()
67
+ return buf .buf .String ()
68
+ }
69
+
52
70
// Result stores the result of running a command
53
71
type Result struct {
54
72
Cmd * exec.Cmd
55
73
ExitCode int
56
74
Error error
57
75
// Timeout is true if the command was killed because it ran for too long
58
76
Timeout bool
59
- outBuffer * bytes. Buffer
60
- errBuffer * bytes. Buffer
77
+ outBuffer * lockedBuffer
78
+ errBuffer * lockedBuffer
61
79
}
62
80
63
81
// Assert compares the Result against the Expected struct, and fails the test if
@@ -255,8 +273,8 @@ func buildCmd(cmd Cmd) *Result {
255
273
default :
256
274
execCmd = exec .Command (cmd .Command [0 ], cmd .Command [1 :]... )
257
275
}
258
- outBuffer := new (bytes. Buffer )
259
- errBuffer := new (bytes. Buffer )
276
+ outBuffer := new (lockedBuffer )
277
+ errBuffer := new (lockedBuffer )
260
278
261
279
execCmd .Stdin = cmd .Stdin
262
280
execCmd .Dir = cmd .Dir
You can’t perform that action at this time.
0 commit comments