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

Function TestDeprecatedFlagUsage

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

Source from the content-addressed store, hash-verified

1176}
1177
1178func TestDeprecatedFlagUsage(t *testing.T) {
1179 f := NewFlagSet("bob", ContinueOnError)
1180 f.Bool("badflag", true, "always true")
1181 usageMsg := "use --good-flag instead"
1182 f.MarkDeprecated("badflag", usageMsg)
1183
1184 args := []string{"--badflag"}
1185 out, err := parseReturnStderr(t, f, args)
1186 if err != nil {
1187 t.Fatal("expected no error; got ", err)
1188 }
1189
1190 if !strings.Contains(out, usageMsg) {
1191 t.Errorf("usageMsg not printed when using a deprecated flag!")
1192 }
1193}
1194
1195func TestDeprecatedFlagShorthandUsage(t *testing.T) {
1196 f := NewFlagSet("bob", ContinueOnError)

Callers

nothing calls this directly

Calls 4

BoolMethod · 0.95
MarkDeprecatedMethod · 0.95
NewFlagSetFunction · 0.85
parseReturnStderrFunction · 0.85

Tested by

no test coverage detected