From da3c9eeebd0302584ccc2031a8ab917779d04ce9 Mon Sep 17 00:00:00 2001 From: 5ouma <101255979+5ouma@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:31:11 +0900 Subject: [PATCH] [update] Test for `SetErrPrefix()` If it doesn't output any errors, fails the test. --- command_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/command_test.go b/command_test.go index b0f5e860..d234b355 100644 --- a/command_test.go +++ b/command_test.go @@ -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})