(t *testing.T)
| 581 | } |
| 582 | |
| 583 | func TestChildFlagWithParentLocalFlag(t *testing.T) { |
| 584 | rootCmd := &Command{Use: "root", Run: emptyRun} |
| 585 | childCmd := &Command{Use: "child", Run: emptyRun} |
| 586 | rootCmd.AddCommand(childCmd) |
| 587 | |
| 588 | var intFlagValue int |
| 589 | rootCmd.Flags().StringP("sf", "s", "", "") |
| 590 | childCmd.Flags().IntVarP(&intFlagValue, "intf", "i", -1, "") |
| 591 | |
| 592 | _, err := executeCommand(rootCmd, "child", "-i7", "-sabc") |
| 593 | if err == nil { |
| 594 | t.Errorf("Invalid flag should generate error") |
| 595 | } |
| 596 | |
| 597 | checkStringContains(t, err.Error(), "unknown shorthand") |
| 598 | |
| 599 | if intFlagValue != 7 { |
| 600 | t.Errorf("Expected flag value: %v, got %v", 7, intFlagValue) |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | func TestFlagInvalidInput(t *testing.T) { |
| 605 | rootCmd := &Command{Use: "root", Run: emptyRun} |
nothing calls this directly
no test coverage detected