1
0
mirror of https://github.com/golang/go synced 2024-11-27 02:11:17 -07:00

flag: use strings.Builder

Change-Id: Iee846c4ac0f111ff97aa618dd42f6b2d14aa4342
Reviewed-on: https://go-review.googlesource.com/c/go/+/428259
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
cuiweixie 2022-09-04 17:47:17 +08:00 committed by Gopher Robot
parent ab87db8b46
commit 91a1b55489

View File

@ -5,7 +5,6 @@
package flag_test
import (
"bytes"
. "flag"
"fmt"
"internal/testenv"
@ -358,7 +357,7 @@ func TestUserDefinedBool(t *testing.T) {
func TestSetOutput(t *testing.T) {
var flags FlagSet
var buf bytes.Buffer
var buf strings.Builder
flags.SetOutput(&buf)
flags.Init("test", ContinueOnError)
flags.Parse([]string{"-unknown"})
@ -488,7 +487,7 @@ panic calling String method on zero flag_test.zeroPanicker for flag ZP1: panic!
func TestPrintDefaults(t *testing.T) {
fs := NewFlagSet("print defaults test", ContinueOnError)
var buf bytes.Buffer
var buf strings.Builder
fs.SetOutput(&buf)
fs.Bool("A", false, "for bootstrapping, allow 'any' type")
fs.Bool("Alongflagname", false, "disable bounds checking")
@ -531,7 +530,7 @@ func TestIntFlagOverflow(t *testing.T) {
// Issue 20998: Usage should respect CommandLine.output.
func TestUsageOutput(t *testing.T) {
ResetForTesting(DefaultUsage)
var buf bytes.Buffer
var buf strings.Builder
CommandLine.SetOutput(&buf)
defer func(old []string) { os.Args = old }(os.Args)
os.Args = []string{"app", "-i=1", "-unknown"}
@ -726,7 +725,7 @@ func TestInvalidFlags(t *testing.T) {
testName := fmt.Sprintf("FlagSet.Var(&v, %q, \"\")", test.flag)
fs := NewFlagSet("", ContinueOnError)
buf := bytes.NewBuffer(nil)
buf := &strings.Builder{}
fs.SetOutput(buf)
mustPanic(t, testName, test.errorMsg, func() {
@ -758,7 +757,7 @@ func TestRedefinedFlags(t *testing.T) {
testName := fmt.Sprintf("flag redefined in FlagSet(%q)", test.flagSetName)
fs := NewFlagSet(test.flagSetName, ContinueOnError)
buf := bytes.NewBuffer(nil)
buf := &strings.Builder{}
fs.SetOutput(buf)
var v flagVar