MCPcopy
hub / github.com/spf13/pflag / TestDeprecatedFlagShorthandUsage

Function TestDeprecatedFlagShorthandUsage

flag_test.go:1195–1211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1193}
1194
1195func TestDeprecatedFlagShorthandUsage(t *testing.T) {
1196 f := NewFlagSet("bob", ContinueOnError)
1197 name := "noshorthandflag"
1198 f.BoolP(name, "n", true, "always true")
1199 usageMsg := fmt.Sprintf("use --%s instead", name)
1200 f.MarkShorthandDeprecated(name, usageMsg)
1201
1202 args := []string{"-n"}
1203 out, err := parseReturnStderr(t, f, args)
1204 if err != nil {
1205 t.Fatal("expected no error; got ", err)
1206 }
1207
1208 if !strings.Contains(out, usageMsg) {
1209 t.Errorf("usageMsg not printed when using a deprecated flag!")
1210 }
1211}
1212
1213func TestDeprecatedFlagUsageNormalized(t *testing.T) {
1214 f := NewFlagSet("bob", ContinueOnError)

Callers

nothing calls this directly

Calls 4

BoolPMethod · 0.95
NewFlagSetFunction · 0.85
parseReturnStderrFunction · 0.85

Tested by

no test coverage detected