aboutsummaryrefslogtreecommitdiff
path: root/func_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'func_test.go')
-rw-r--r--func_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/func_test.go b/func_test.go
index 9be74fa..d492b48 100644
--- a/func_test.go
+++ b/func_test.go
@@ -151,3 +151,33 @@ func TestFuncCompat(t *testing.T) {
}
})
}
+
+func TestFuncUsage(t *testing.T) {
+ t.Run("regular func flag", func(t *testing.T) {
+ // regular func flag:
+ // expect to see '--flag1 value' followed by the usageMessage, and no mention of a default value
+ fset := NewFlagSet("unittest", ContinueOnError)
+ fset.Func("flag1", "usage message", func(s string) error { return nil })
+ usage := fset.FlagUsagesWrapped(80)
+
+ usage = strings.TrimSpace(usage)
+ expected := "--flag1 value usage message"
+ if usage != expected {
+ t.Fatalf("unexpected generated usage message\n expected: %s\n got: %s", expected, usage)
+ }
+ })
+
+ t.Run("func flag with placeholder name", func(t *testing.T) {
+ // func flag, with a placeholder name:
+ // if usageMesage contains a placeholder, expect that name; still expect no mention of a default value
+ fset := NewFlagSet("unittest", ContinueOnError)
+ fset.Func("flag2", "usage message with `name` placeholder", func(s string) error { return nil })
+ usage := fset.FlagUsagesWrapped(80)
+
+ usage = strings.TrimSpace(usage)
+ expected := "--flag2 name usage message with name placeholder"
+ if usage != expected {
+ t.Fatalf("unexpected generated usage message\n expected: %s\n got: %s", expected, usage)
+ }
+ })
+}