(t *testing.T)
| 602 | } |
| 603 | |
| 604 | func 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 | |
| 640 | func TestParse(t *testing.T) { |
| 641 | ResetForTesting(func() { t.Error("bad parse") }) |
nothing calls this directly
no test coverage detected