mirror of
https://github.com/golang/go
synced 2024-11-05 20:06:10 -07:00
os: use strings.Builder
Change-Id: I610509aa35c345ff7fbb1fc94bf177ffbe934731 Reviewed-on: https://go-review.googlesource.com/c/go/+/428274 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Benny Siegert <bsiegert@gmail.com>
This commit is contained in:
parent
e2d8ed2fd7
commit
6375f508a8
@ -5,7 +5,6 @@
|
|||||||
package exec_test
|
package exec_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -28,7 +27,7 @@ func ExampleLookPath() {
|
|||||||
func ExampleCommand() {
|
func ExampleCommand() {
|
||||||
cmd := exec.Command("tr", "a-z", "A-Z")
|
cmd := exec.Command("tr", "a-z", "A-Z")
|
||||||
cmd.Stdin = strings.NewReader("some input")
|
cmd.Stdin = strings.NewReader("some input")
|
||||||
var out bytes.Buffer
|
var out strings.Builder
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -804,7 +804,7 @@ func TestExtraFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c = exec.CommandContext(ctx, exe)
|
c = exec.CommandContext(ctx, exe)
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr strings.Builder
|
||||||
c.Stdout = &stdout
|
c.Stdout = &stdout
|
||||||
c.Stderr = &stderr
|
c.Stderr = &stderr
|
||||||
c.ExtraFiles = []*os.File{tf}
|
c.ExtraFiles = []*os.File{tf}
|
||||||
@ -822,7 +822,7 @@ func TestExtraFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = c.Run()
|
err = c.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Run: %v\n--- stdout:\n%s--- stderr:\n%s", err, stdout.Bytes(), stderr.Bytes())
|
t.Fatalf("Run: %v\n--- stdout:\n%s--- stderr:\n%s", err, stdout.String(), stderr.String())
|
||||||
}
|
}
|
||||||
if stdout.String() != text {
|
if stdout.String() != text {
|
||||||
t.Errorf("got stdout %q, stderr %q; want %q on stdout", stdout.String(), stderr.String(), text)
|
t.Errorf("got stdout %q, stderr %q; want %q on stdout", stdout.String(), stderr.String(), text)
|
||||||
@ -904,7 +904,7 @@ func TestIgnorePipeErrorOnSuccess(t *testing.T) {
|
|||||||
testWith := func(r io.Reader) func(*testing.T) {
|
testWith := func(r io.Reader) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
cmd := helperCommand(t, "echo", "foo")
|
cmd := helperCommand(t, "echo", "foo")
|
||||||
var out bytes.Buffer
|
var out strings.Builder
|
||||||
cmd.Stdin = r
|
cmd.Stdin = r
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package os_test
|
package os_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -1167,7 +1166,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) {
|
|||||||
}
|
}
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b strings.Builder
|
||||||
io.Copy(&b, r)
|
io.Copy(&b, r)
|
||||||
output := b.String()
|
output := b.String()
|
||||||
|
|
||||||
@ -1718,7 +1717,7 @@ func runBinHostname(t *testing.T) string {
|
|||||||
}
|
}
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b strings.Builder
|
||||||
io.Copy(&b, r)
|
io.Copy(&b, r)
|
||||||
_, err = p.Wait()
|
_, err = p.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user