diff options
| author | Janet Kuo <[email protected]> | 2015-08-20 10:37:05 -0700 |
|---|---|---|
| committer | Janet Kuo <[email protected]> | 2015-08-20 15:51:15 -0700 |
| commit | e12c301bae1d77ba20ec0e3252011bdccb77b462 (patch) | |
| tree | dec35b117787a03841f45241429bf2cc8c378dfa /flag_test.go | |
| parent | 112aaa578dfdd0e913663b05153be974bd72497a (diff) | |
Add shorthand deprecator
Diffstat (limited to 'flag_test.go')
| -rw-r--r-- | flag_test.go | 33 |
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") |
