flag: allow a FlagSet to not write to os.Stderr
Fixes #2747
R=golang-dev, gri, r, rogpeppe, r
CC=golang-dev
https://golang.org/cl/5564065
diff --git a/src/pkg/flag/flag_test.go b/src/pkg/flag/flag_test.go
index 698c15f..a9561f2 100644
--- a/src/pkg/flag/flag_test.go
+++ b/src/pkg/flag/flag_test.go
@@ -5,10 +5,12 @@
package flag_test
import (
+ "bytes"
. "flag"
"fmt"
"os"
"sort"
+ "strings"
"testing"
"time"
)
@@ -206,6 +208,17 @@
}
}
+func TestSetOutput(t *testing.T) {
+ var flags FlagSet
+ var buf bytes.Buffer
+ flags.SetOutput(&buf)
+ flags.Init("test", ContinueOnError)
+ flags.Parse([]string{"-unknown"})
+ if out := buf.String(); !strings.Contains(out, "-unknown") {
+ t.Logf("expected output mentioning unknown; got %q", out)
+ }
+}
+
// This tests that one can reset the flags. This still works but not well, and is
// superseded by FlagSet.
func TestChangingArgs(t *testing.T) {