aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'flag_test.go')
-rw-r--r--flag_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go
index 7d02dbc..58a5d25 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -159,6 +159,16 @@ func TestAnnotation(t *testing.T) {
}
}
+func TestName(t *testing.T) {
+ flagSetName := "bob"
+ f := NewFlagSet(flagSetName, ContinueOnError)
+
+ givenName := f.Name()
+ if givenName != flagSetName {
+ t.Errorf("Unexpected result when retrieving a FlagSet's name: expected %s, but found %s", flagSetName, givenName)
+ }
+}
+
func testParse(f *FlagSet, t *testing.T) {
if f.Parsed() {
t.Error("f.Parse() = true before Parse")
@@ -854,6 +864,17 @@ func TestSetOutput(t *testing.T) {
}
}
+func TestOutput(t *testing.T) {
+ var flags FlagSet
+ var buf bytes.Buffer
+ expect := "an example string"
+ flags.SetOutput(&buf)
+ fmt.Fprint(flags.Output(), expect)
+ if out := buf.String(); !strings.Contains(out, expect) {
+ t.Errorf("expected output %q; got %q", expect, 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) {