mirror of
https://github.com/spf13/cobra
synced 2025-04-27 00:57:23 +00:00
[update] Test for SetErrPrefix()
If it doesn't output any errors, fails the test.
This commit is contained in:
parent
a76559e04a
commit
da3c9eeebd
1 changed files with 12 additions and 0 deletions
|
@ -1099,6 +1099,18 @@ func TestShorthandVersionTemplate(t *testing.T) {
|
|||
checkStringContains(t, output, "customized version: 1.0.0")
|
||||
}
|
||||
|
||||
func TestErrPrefix(t *testing.T) {
|
||||
rootCmd := &Command{Use: "root", SilenceUsage: true, Run: emptyRun}
|
||||
rootCmd.SetErrPrefix("customized error prefix:")
|
||||
|
||||
output, err := executeCommand(rootCmd, "--unknown", "flag")
|
||||
if err == nil {
|
||||
t.Errorf("Expected error")
|
||||
}
|
||||
|
||||
checkStringContains(t, output, "customized error prefix: unknown flag: --unknown")
|
||||
}
|
||||
|
||||
func TestVersionFlagExecutedOnSubcommand(t *testing.T) {
|
||||
rootCmd := &Command{Use: "root", Version: "1.0.0"}
|
||||
rootCmd.AddCommand(&Command{Use: "sub", Run: emptyRun})
|
||||
|
|
Loading…
Add table
Reference in a new issue