mirror of
https://github.com/golang/go
synced 2024-11-23 15:00:03 -07:00
all: use strings.Builder where appropriate
Change-Id: I164d350ca480640996055dedf38d962921c474a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/435975 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
b78b84cd23
commit
972496ae6e
@ -192,7 +192,7 @@ var lineBreakerTests = []lineBreakerTest{
|
|||||||
|
|
||||||
func TestLineBreaker(t *testing.T) {
|
func TestLineBreaker(t *testing.T) {
|
||||||
for i, test := range lineBreakerTests {
|
for i, test := range lineBreakerTests {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(strings.Builder)
|
||||||
var breaker lineBreaker
|
var breaker lineBreaker
|
||||||
breaker.out = buf
|
breaker.out = buf
|
||||||
_, err := breaker.Write([]byte(test.in))
|
_, err := breaker.Write([]byte(test.in))
|
||||||
@ -206,13 +206,13 @@ func TestLineBreaker(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(buf.Bytes()) != test.out {
|
if got := buf.String(); got != test.out {
|
||||||
t.Errorf("#%d: got:%s want:%s", i, string(buf.Bytes()), test.out)
|
t.Errorf("#%d: got:%s want:%s", i, got, test.out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range lineBreakerTests {
|
for i, test := range lineBreakerTests {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(strings.Builder)
|
||||||
var breaker lineBreaker
|
var breaker lineBreaker
|
||||||
breaker.out = buf
|
breaker.out = buf
|
||||||
|
|
||||||
@ -229,8 +229,8 @@ func TestLineBreaker(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(buf.Bytes()) != test.out {
|
if got := buf.String(); got != test.out {
|
||||||
t.Errorf("#%d: (byte by byte) got:%s want:%s", i, string(buf.Bytes()), test.out)
|
t.Errorf("#%d: (byte by byte) got:%s want:%s", i, got, test.out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
package signal
|
package signal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -78,9 +78,9 @@ func main() {
|
|||||||
|
|
||||||
// run it
|
// run it
|
||||||
cmd := exec.Command(exe)
|
cmd := exec.Command(exe)
|
||||||
var b bytes.Buffer
|
var buf strings.Builder
|
||||||
cmd.Stdout = &b
|
cmd.Stdout = &buf
|
||||||
cmd.Stderr = &b
|
cmd.Stderr = &buf
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
|
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
|
||||||
}
|
}
|
||||||
@ -94,6 +94,6 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Program exited with error: %v\n%v", err, string(b.Bytes()))
|
t.Fatalf("Program exited with error: %v\n%v", err, buf.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package runtime_test
|
package runtime_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/abi"
|
"internal/abi"
|
||||||
"internal/syscall/windows/sysdll"
|
"internal/syscall/windows/sysdll"
|
||||||
@ -1044,7 +1043,7 @@ func TestNumCPU(t *testing.T) {
|
|||||||
|
|
||||||
cmd := exec.Command(os.Args[0], "-test.run=TestNumCPU")
|
cmd := exec.Command(os.Args[0], "-test.run=TestNumCPU")
|
||||||
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
|
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
|
||||||
var buf bytes.Buffer
|
var buf strings.Builder
|
||||||
cmd.Stdout = &buf
|
cmd.Stdout = &buf
|
||||||
cmd.Stderr = &buf
|
cmd.Stderr = &buf
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: _CREATE_SUSPENDED}
|
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: _CREATE_SUSPENDED}
|
||||||
@ -1054,7 +1053,7 @@ func TestNumCPU(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
childOutput := string(buf.Bytes())
|
childOutput := buf.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("child failed: %v: %v", err, childOutput)
|
t.Fatalf("child failed: %v: %v", err, childOutput)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user