Skip to content

Commit fb44929

Browse files
committed
bugfix use pointer mutex
1 parent ad970da commit fb44929

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

goproc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ func Run1(cmd *Cmd) (string, string, error, int) {
464464
onStdout := cmd.OnStdout
465465
onStderr := cmd.OnStderr
466466
stdoutBuff := bytes.Buffer{}
467-
stdoutLock := sync.Mutex{}
467+
stdoutLock := &sync.Mutex{}
468468
stderrBuff := bytes.Buffer{}
469-
stderrMutex := sync.Mutex{}
469+
stderrMutex := &sync.Mutex{}
470470
cmd.OnStdout = func(cmd *Cmd, s string) error {
471471
stdoutLock.Lock()
472472
stdoutBuff.WriteString(s)

pullpush.sh

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ go mod tidy
2020
ag gokil **/*.go && ( echo 'echo should not import previous gokil library..' ; kill 0 )
2121
echo "imports checked.."
2222

23+
# test with race
24+
go test -race .
25+
2326
# add and commit all files
2427
git add .
2528
git status

single_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ func TestRun1missing(t *testing.T) {
3838
assert.Error(t, err)
3939
assert.Equal(t, 0, exitCode)
4040
}
41+
42+
func TestRun1long(t *testing.T) {
43+
_, stderr, err, exitCode := Run1(&Cmd{
44+
Program: `ls`,
45+
Parameters: []string{`-alr`},
46+
})
47+
assert.Equal(t, "", stderr)
48+
assert.NoError(t, err)
49+
assert.Equal(t, 0, exitCode)
50+
}

0 commit comments

Comments
 (0)