Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TestSetOutput #225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,8 @@ func VarP(value Value, name, shorthand, usage string) {
// returns the error.
func (f *FlagSet) failf(format string, a ...interface{}) error {
err := fmt.Errorf(format, a...)
fmt.Fprintln(f.Output(), err)
if f.errorHandling != ContinueOnError {
fmt.Fprintln(f.Output(), err)
f.usage()
}
return err
Expand Down
9 changes: 7 additions & 2 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,14 @@ func TestSetOutput(t *testing.T) {
flags.SetOutput(&buf)
flags.Init("test", ContinueOnError)
flags.Parse([]string{"--unknown"})
if out := buf.String(); !strings.Contains(out, "--unknown") {
t.Logf("expected output mentioning unknown; got %q", out)
out := buf.String()
if out == "" {
t.Error("expected output, got none")
}
if strings.Contains(out, "--unknown") {
return
}
t.Errorf("expected output mentioning unknown; got %q", out)
}

func TestOutput(t *testing.T) {
Expand Down