(t *testing.T)
| 1019 | } |
| 1020 | |
| 1021 | func TestSetHelpTemplate(t *testing.T) { |
| 1022 | rootCmd := &Command{Use: "root", Run: emptyRun} |
| 1023 | childCmd := &Command{Use: "child", Run: emptyRun} |
| 1024 | rootCmd.AddCommand(childCmd) |
| 1025 | |
| 1026 | rootCmd.SetHelpTemplate("WORKS {{.UseLine}}") |
| 1027 | |
| 1028 | // Call the help on the root command and check the new template is used |
| 1029 | got, err := executeCommand(rootCmd, "--help") |
| 1030 | if err != nil { |
| 1031 | t.Errorf("Unexpected error: %v", err) |
| 1032 | } |
| 1033 | |
| 1034 | expected := "WORKS " + rootCmd.UseLine() |
| 1035 | if got != expected { |
| 1036 | t.Errorf("Expected %q, got %q", expected, got) |
| 1037 | } |
| 1038 | |
| 1039 | // Call the help on the child command and check |
| 1040 | // the new template is inherited from the parent |
| 1041 | got, err = executeCommand(rootCmd, "child", "--help") |
| 1042 | if err != nil { |
| 1043 | t.Errorf("Unexpected error: %v", err) |
| 1044 | } |
| 1045 | |
| 1046 | expected = "WORKS " + childCmd.UseLine() |
| 1047 | if got != expected { |
| 1048 | t.Errorf("Expected %q, got %q", expected, got) |
| 1049 | } |
| 1050 | |
| 1051 | // Reset the root command help template and make sure |
| 1052 | // it falls back to the default |
| 1053 | rootCmd.SetHelpTemplate("") |
| 1054 | got, err = executeCommand(rootCmd, "--help") |
| 1055 | if err != nil { |
| 1056 | t.Errorf("Unexpected error: %v", err) |
| 1057 | } |
| 1058 | |
| 1059 | if !strings.Contains(got, "Usage:") { |
| 1060 | t.Errorf("Expected to contain %q, got %q", "Usage:", got) |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | func TestHelpFlagExecuted(t *testing.T) { |
| 1065 | rootCmd := &Command{Use: "root", Long: "Long description", Run: emptyRun} |
nothing calls this directly
no test coverage detected