]> Cypherpunks repositories - gostls13.git/commitdiff
flag: use strings.Builder
authorcuiweixie <cuiweixie@gmail.com>
Sun, 4 Sep 2022 09:47:17 +0000 (17:47 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 6 Sep 2022 15:47:09 +0000 (15:47 +0000)
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>

src/flag/flag_test.go

index ca6ba5d149c69ae8f10d37c9d19f739842c8421a..791a8826bedde53064b0a4c5d6f05985785ca9c0 100644 (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