1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:26:11 -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:
cuiweixie 2022-09-04 18:45:00 +08:00 committed by Benny Siegert
parent e2d8ed2fd7
commit 6375f508a8
3 changed files with 6 additions and 8 deletions

View File

@ -5,7 +5,6 @@
package exec_test
import (
"bytes"
"context"
"encoding/json"
"fmt"
@ -28,7 +27,7 @@ func ExampleLookPath() {
func ExampleCommand() {
cmd := exec.Command("tr", "a-z", "A-Z")
cmd.Stdin = strings.NewReader("some input")
var out bytes.Buffer
var out strings.Builder
cmd.Stdout = &out
err := cmd.Run()
if err != nil {

View File

@ -804,7 +804,7 @@ func TestExtraFiles(t *testing.T) {
}
c = exec.CommandContext(ctx, exe)
var stdout, stderr bytes.Buffer
var stdout, stderr strings.Builder
c.Stdout = &stdout
c.Stderr = &stderr
c.ExtraFiles = []*os.File{tf}
@ -822,7 +822,7 @@ func TestExtraFiles(t *testing.T) {
}
err = c.Run()
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 {
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) {
return func(t *testing.T) {
cmd := helperCommand(t, "echo", "foo")
var out bytes.Buffer
var out strings.Builder
cmd.Stdin = r
cmd.Stdout = &out
if err := cmd.Run(); err != nil {

View File

@ -5,7 +5,6 @@
package os_test
import (
"bytes"
"errors"
"flag"
"fmt"
@ -1167,7 +1166,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) {
}
w.Close()
var b bytes.Buffer
var b strings.Builder
io.Copy(&b, r)
output := b.String()
@ -1718,7 +1717,7 @@ func runBinHostname(t *testing.T) string {
}
w.Close()
var b bytes.Buffer
var b strings.Builder
io.Copy(&b, r)
_, err = p.Wait()
if err != nil {