nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bitfield/script
Pull request #118 (2022-05-13 18:26:22)

Update README.md
typo for AppendFile short description


Patch:
diff --git a/README.md b/README.md
index f273c93..5322d38 100644
--- a/README.md
+++ b/README.md
@@ -239,7 +239,7 @@ Sinks are methods that return some data from a pipe, ending the pipeline and ext
 
 | Sink | Destination | Results |
 | ---- | ----------- | ------- |
-| [`AppendFile`](https://pkg.go.dev/github.com/bitfield/script#Pipe.AppendFile) | appended to file, creating if it exists | bytes written, error |
+| [`AppendFile`](https://pkg.go.dev/github.com/bitfield/script#Pipe.AppendFile) | appended to file, creating if it doesn't exist | bytes written, error |
 | [`Bytes`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Bytes) | | data as `[]byte`, error
 | [`CountLines`](https://pkg.go.dev/github.com/bitfield/script#Pipe.CountLines) | |number of lines, error  |
 | [`Read`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Read) | given `[]byte` | bytes read, error  |
diff --git a/script.go b/script.go
index 8703873..d3a643d 100644
--- a/script.go
+++ b/script.go
@@ -140,9 +140,6 @@ func (p *Pipe) SetError(err error) {
 	}
 	p.mu.Lock()
 	defer p.mu.Unlock()
-	if err != nil {
-		p.Close()
-	}
 	p.err = err
 }
 


Test patch:
diff --git a/script_test.go b/script_test.go
index f87b610..7968365 100644
--- a/script_test.go
+++ b/script_test.go
@@ -931,12 +931,18 @@ func TestExecRunsGoWithNoArgsAndGetsUsageMessagePlusErrorExitStatus2(t *testing.
 	// We can't make many cross-platform assumptions about what external
 	// commands will be available, but it seems logical that 'go' would be
 	// (though it may not be in the user's path)
-	got, err := script.Exec("go").String()
+	p := script.Exec("go")
+	output, err := p.String()
 	if err == nil {
 		t.Error("want error when command returns a non-zero exit status")
 	}
-	if !strings.Contains(got, "Usage") {
-		t.Fatalf("want output containing the word 'usage', got %q", got)
+	if !strings.Contains(output, "Usage") {
+		t.Fatalf("want output containing the word 'usage', got %q", output)
+	}
+	want := 2
+	got := p.ExitStatus()
+	if want != got {
+		t.Errorf("want exit status %d, got %d", want, got)
 	}
 }
 
@@ -1497,13 +1503,22 @@ func ExampleEcho() {
 	// Hello, world!
 }
 
-func ExampleExec_exitstatus() {
+func ExampleExec_exit_status_zero() {
 	p := script.Exec("echo")
+	p.Wait()
 	fmt.Println(p.ExitStatus())
 	// Output:
 	// 0
 }
 
+func ExampleExec_exit_status_not_zero() {
+	p := script.Exec("false")
+	p.Wait()
+	fmt.Println(p.ExitStatus())
+	// Output:
+	// 1
+}
+
 func ExampleFile() {
 	script.File("testdata/hello.txt").Stdout()
 	// Output:
Repository: bitfield/script
Pull request #120 (2022-05-17 20:57:00)

Fix Exec exit status
This PR fixes issues when trying to get exit status from Exec commands.
Closes https://github.com/bitfield/script/issues/117


Patch:
diff --git a/script.go b/script.go
index 8703873..d3a643d 100644
--- a/script.go
+++ b/script.go
@@ -140,9 +140,6 @@ func (p *Pipe) SetError(err error) {
 	}
 	p.mu.Lock()
 	defer p.mu.Unlock()
-	if err != nil {
-		p.Close()
-	}
 	p.err = err
 }
 


Test patch:
diff --git a/script_test.go b/script_test.go
index f87b610..7968365 100644
--- a/script_test.go
+++ b/script_test.go
@@ -931,12 +931,18 @@ func TestExecRunsGoWithNoArgsAndGetsUsageMessagePlusErrorExitStatus2(t *testing.
 	// We can't make many cross-platform assumptions about what external
 	// commands will be available, but it seems logical that 'go' would be
 	// (though it may not be in the user's path)
-	got, err := script.Exec("go").String()
+	p := script.Exec("go")
+	output, err := p.String()
 	if err == nil {
 		t.Error("want error when command returns a non-zero exit status")
 	}
-	if !strings.Contains(got, "Usage") {
-		t.Fatalf("want output containing the word 'usage', got %q", got)
+	if !strings.Contains(output, "Usage") {
+		t.Fatalf("want output containing the word 'usage', got %q", output)
+	}
+	want := 2
+	got := p.ExitStatus()
+	if want != got {
+		t.Errorf("want exit status %d, got %d", want, got)
 	}
 }
 
@@ -1497,13 +1503,22 @@ func ExampleEcho() {
 	// Hello, world!
 }
 
-func ExampleExec_exitstatus() {
+func ExampleExec_exit_status_zero() {
 	p := script.Exec("echo")
+	p.Wait()
 	fmt.Println(p.ExitStatus())
 	// Output:
 	// 0
 }
 
+func ExampleExec_exit_status_not_zero() {
+	p := script.Exec("false")
+	p.Wait()
+	fmt.Println(p.ExitStatus())
+	// Output:
+	// 1
+}
+
 func ExampleFile() {
 	script.File("testdata/hello.txt").Stdout()
 	// Output: