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

Function TestTermination

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

Source from the content-addressed store, hash-verified

1062}
1063
1064func TestTermination(t *testing.T) {
1065 f := NewFlagSet("termination", ContinueOnError)
1066 boolFlag := f.BoolP("bool", "l", false, "bool value")
1067 if f.Parsed() {
1068 t.Error("f.Parse() = true before Parse")
1069 }
1070 arg1 := "ls"
1071 arg2 := "-l"
1072 args := []string{
1073 "--",
1074 arg1,
1075 arg2,
1076 }
1077 f.SetOutput(ioutil.Discard)
1078 if err := f.Parse(args); err != nil {
1079 t.Fatal("expected no error; got ", err)
1080 }
1081 if !f.Parsed() {
1082 t.Error("f.Parse() = false after Parse")
1083 }
1084 if *boolFlag {
1085 t.Error("expected boolFlag=false, got true")
1086 }
1087 if len(f.Args()) != 2 {
1088 t.Errorf("expected 2 arguments, got %d: %v", len(f.Args()), f.Args())
1089 }
1090 if f.Args()[0] != arg1 {
1091 t.Errorf("expected argument %q got %q", arg1, f.Args()[0])
1092 }
1093 if f.Args()[1] != arg2 {
1094 t.Errorf("expected argument %q got %q", arg2, f.Args()[1])
1095 }
1096 if f.ArgsLenAtDash() != 0 {
1097 t.Errorf("expected argsLenAtDash %d got %d", 0, f.ArgsLenAtDash())
1098 }
1099}
1100
1101func getDeprecatedFlagSet() *FlagSet {
1102 f := NewFlagSet("bob", ContinueOnError)

Callers

nothing calls this directly

Calls 8

BoolPMethod · 0.95
ParsedMethod · 0.95
SetOutputMethod · 0.95
ParseMethod · 0.95
ArgsMethod · 0.95
ArgsLenAtDashMethod · 0.95
NewFlagSetFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected