aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r--src/os/exec/exec_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index 6888d29cd8..28be21ce63 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -786,3 +786,33 @@ func TestIgnorePipeErrorOnSuccess(t *testing.T) {
t.Errorf("output = %q; want %q", got, want)
}
}
+
+type badWriter struct{}
+
+func (w *badWriter) Write(data []byte) (int, error) {
+ return 0, io.ErrUnexpectedEOF
+}
+
+func TestClosePipeOnCopyError(t *testing.T) {
+ testenv.MustHaveExec(t)
+
+ if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
+ t.Skipf("skipping test on %s - no yes command", runtime.GOOS)
+ }
+ cmd := exec.Command("yes")
+ cmd.Stdout = new(badWriter)
+ c := make(chan int, 1)
+ go func() {
+ err := cmd.Run()
+ if err == nil {
+ t.Errorf("yes completed successfully")
+ }
+ c <- 1
+ }()
+ select {
+ case <-c:
+ // ok
+ case <-time.After(5 * time.Second):
+ t.Fatalf("yes got stuck writing to bad writer")
+ }
+}