Skip to content

Commit ee03bd6

Browse files
authored
Don't close pipe in SetError (#120)
Fixes #117. * The pipe shouldn't be closed on SetError function * Fix TestExecRunsGoWithNoArgsAndGetsUsageMessagePlusErrorExitStatus2 test. It was not checking that exit status is two * Update test name to match what is really doing * Fix example for getting exit status from exec * Add new example for exit status not zero on Exec
1 parent 3e48ccf commit ee03bd6

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

script.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ func (p *Pipe) SetError(err error) {
140140
}
141141
p.mu.Lock()
142142
defer p.mu.Unlock()
143-
if err != nil {
144-
p.Close()
145-
}
146143
p.err = err
147144
}
148145

script_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,18 @@ func TestExecRunsGoWithNoArgsAndGetsUsageMessagePlusErrorExitStatus2(t *testing.
931931
// We can't make many cross-platform assumptions about what external
932932
// commands will be available, but it seems logical that 'go' would be
933933
// (though it may not be in the user's path)
934-
got, err := script.Exec("go").String()
934+
p := script.Exec("go")
935+
output, err := p.String()
935936
if err == nil {
936937
t.Error("want error when command returns a non-zero exit status")
937938
}
938-
if !strings.Contains(got, "Usage") {
939-
t.Fatalf("want output containing the word 'usage', got %q", got)
939+
if !strings.Contains(output, "Usage") {
940+
t.Fatalf("want output containing the word 'usage', got %q", output)
941+
}
942+
want := 2
943+
got := p.ExitStatus()
944+
if want != got {
945+
t.Errorf("want exit status %d, got %d", want, got)
940946
}
941947
}
942948

@@ -1497,13 +1503,22 @@ func ExampleEcho() {
14971503
// Hello, world!
14981504
}
14991505

1500-
func ExampleExec_exitstatus() {
1506+
func ExampleExec_exit_status_zero() {
15011507
p := script.Exec("echo")
1508+
p.Wait()
15021509
fmt.Println(p.ExitStatus())
15031510
// Output:
15041511
// 0
15051512
}
15061513

1514+
func ExampleExec_exit_status_not_zero() {
1515+
p := script.Exec("false")
1516+
p.Wait()
1517+
fmt.Println(p.ExitStatus())
1518+
// Output:
1519+
// 1
1520+
}
1521+
15071522
func ExampleFile() {
15081523
script.File("testdata/hello.txt").Stdout()
15091524
// Output:

0 commit comments

Comments
 (0)