Skip to content

Commit

Permalink
[update] Test for SetErrPrefix()
Browse files Browse the repository at this point in the history
If it doesn't output any errors, fails the test.
  • Loading branch information
5ouma committed Sep 1, 2023
1 parent a76559e commit da3c9ee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit da3c9ee

Please sign in to comment.