aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
diff options
context:
space:
mode:
authorJanet Kuo <[email protected]>2015-08-20 10:37:05 -0700
committerJanet Kuo <[email protected]>2015-08-20 15:51:15 -0700
commite12c301bae1d77ba20ec0e3252011bdccb77b462 (patch)
treedec35b117787a03841f45241429bf2cc8c378dfa /flag_test.go
parent112aaa578dfdd0e913663b05153be974bd72497a (diff)
Add shorthand deprecator
Diffstat (limited to 'flag_test.go')
-rw-r--r--flag_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go
index 5114f28..165f689 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -729,6 +729,21 @@ func TestDeprecatedFlagInDocs(t *testing.T) {
}
}
+func TestDeprecatedFlagShorthandInDocs(t *testing.T) {
+ f := NewFlagSet("bob", ContinueOnError)
+ name := "noshorthandflag"
+ f.BoolP(name, "n", true, "always true")
+ f.MarkShorthandDeprecated("noshorthandflag", fmt.Sprintf("use --%s instead", name))
+
+ out := new(bytes.Buffer)
+ f.SetOutput(out)
+ f.PrintDefaults()
+
+ if strings.Contains(out.String(), "-n,") {
+ t.Errorf("found deprecated flag shorthand in usage!")
+ }
+}
+
func parseReturnStderr(t *testing.T, f *FlagSet, args []string) (string, error) {
oldStderr := os.Stderr
r, w, _ := os.Pipe()
@@ -768,6 +783,24 @@ func TestDeprecatedFlagUsage(t *testing.T) {
}
}
+func TestDeprecatedFlagShorthandUsage(t *testing.T) {
+ f := NewFlagSet("bob", ContinueOnError)
+ name := "noshorthandflag"
+ f.BoolP(name, "n", true, "always true")
+ usageMsg := fmt.Sprintf("use --%s instead", name)
+ f.MarkShorthandDeprecated(name, usageMsg)
+
+ args := []string{"-n"}
+ out, err := parseReturnStderr(t, f, args)
+ if err != nil {
+ t.Fatal("expected no error; got ", err)
+ }
+
+ if !strings.Contains(out, usageMsg) {
+ t.Errorf("usageMsg not printed when using a deprecated flag!")
+ }
+}
+
func TestDeprecatedFlagUsageNormalized(t *testing.T) {
f := NewFlagSet("bob", ContinueOnError)
f.Bool("bad-double_flag", true, "always true")