mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
add TestPersistentPreRunHooksForHelpCommand
This commit is contained in:
parent
ef1328f8cf
commit
ba4e21df7a
1 changed files with 19 additions and 0 deletions
|
@ -1611,6 +1611,25 @@ func TestPersistentHooks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPersistentPreRunHooksForHelpCommand(t *testing.T) {
|
||||
executed := false
|
||||
|
||||
rootCmd := &Command{
|
||||
Use: "root",
|
||||
PersistentPreRun: func(*Command, []string) { executed = true },
|
||||
Run: emptyRun,
|
||||
}
|
||||
childCmd := &Command{Use: "child", Run: emptyRun}
|
||||
rootCmd.AddCommand(childCmd)
|
||||
|
||||
if _, err := executeCommand(rootCmd, "help"); err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if !executed {
|
||||
t.Error("Root PersistentPreRun should have been executed")
|
||||
}
|
||||
}
|
||||
|
||||
// Related to https://github.com/spf13/cobra/issues/521.
|
||||
func TestGlobalNormFuncPropagation(t *testing.T) {
|
||||
normFunc := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
|
||||
|
|
Loading…
Reference in a new issue