(t *testing.T)
| 894 | } |
| 895 | |
| 896 | func TestPersistentRequiredFlagsWithDisableFlagParsing(t *testing.T) { |
| 897 | // Make sure a required persistent flag does not break |
| 898 | // commands that disable flag parsing |
| 899 | |
| 900 | parent := &Command{Use: "parent", Run: emptyRun} |
| 901 | parent.PersistentFlags().Bool("foo", false, "") |
| 902 | flag := parent.PersistentFlags().Lookup("foo") |
| 903 | assertNoErr(t, parent.MarkPersistentFlagRequired("foo")) |
| 904 | |
| 905 | child := &Command{Use: "child", Run: emptyRun} |
| 906 | child.DisableFlagParsing = true |
| 907 | |
| 908 | parent.AddCommand(child) |
| 909 | |
| 910 | if _, err := executeCommand(parent, "--foo", "child"); err != nil { |
| 911 | t.Errorf("Unexpected error: %v", err) |
| 912 | } |
| 913 | |
| 914 | // Reset the flag or else it will remember the state from the previous command |
| 915 | flag.Changed = false |
| 916 | if _, err := executeCommand(parent, "child", "--foo"); err != nil { |
| 917 | t.Errorf("Unexpected error: %v", err) |
| 918 | } |
| 919 | |
| 920 | // Reset the flag or else it will remember the state from the previous command |
| 921 | flag.Changed = false |
| 922 | if _, err := executeCommand(parent, "child"); err != nil { |
| 923 | t.Errorf("Unexpected error: %v", err) |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | func TestInitHelpFlagMergesFlags(t *testing.T) { |
| 928 | usage := "custom flag" |
nothing calls this directly
no test coverage detected