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

Function TestShorthandLookup

flag_test.go:604–638  ·  flag_test.go::TestShorthandLookup
(t *testing.T)

Source from the content-addressed store, hash-verified

602}
603
604func TestShorthandLookup(t *testing.T) {
605 f := NewFlagSet("shorthand", ContinueOnError)
606 if f.Parsed() {
607 t.Error("f.Parse() = true before Parse")
608 }
609 f.BoolP("boola", "a", false, "bool value")
610 f.BoolP("boolb", "b", false, "bool2 value")
611 args := []string{
612 "-ab",
613 }
614 f.SetOutput(ioutil.Discard)
615 if err := f.Parse(args); err != nil {
616 t.Error("expected no error, got ", err)
617 }
618 if !f.Parsed() {
619 t.Error("f.Parse() = false after Parse")
620 }
621 flag := f.ShorthandLookup("a")
622 if flag == nil {
623 t.Errorf("f.ShorthandLookup(\"a\") returned nil")
624 }
625 if flag.Name != "boola" {
626 t.Errorf("f.ShorthandLookup(\"a\") found %q instead of \"boola\"", flag.Name)
627 }
628 flag = f.ShorthandLookup("")
629 if flag != nil {
630 t.Errorf("f.ShorthandLookup(\"\") did not return nil")
631 }
632 defer func() {
633 recover()
634 }()
635 flag = f.ShorthandLookup("ab")
636 // should NEVER get here. lookup should panic. defer'd func should recover it.
637 t.Errorf("f.ShorthandLookup(\"ab\") did not panic")
638}
639
640func TestParse(t *testing.T) {
641 ResetForTesting(func() { t.Error("bad parse") })

Callers

nothing calls this directly

Calls 7

ParsedMethod · 0.95
BoolPMethod · 0.95
SetOutputMethod · 0.95
ParseMethod · 0.95
ShorthandLookupMethod · 0.95
NewFlagSetFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected