Skip to content

Command.SetErrOutput(io.Writer) for more finegrained testing #763

@koiuo

Description

@koiuo

Initially I commented on #607 , but I then found out, that I can't reopen it, hence I decided to create a dedicated issue. I apologize if that's an unwanted noise.

Right now Command offers SetOutput method to set alternative io.Writer implementation for testing stdout/stderr interaction.

I think it would be great to be able to distinct standard output and error output here.

It is not uncommong for commands to report warnings to stderr. For example, take GNU's ls

$ ls -l /does/not/exist /tmp
ls: cannot access '/does/not/exist': No such file or directory
/tmp:
total 27776
...

If I were to reimplement this in go, I'd want to be sure, that ls: cannot access ... won't get to stdout, as it may be piped further. So I'd like to have test for that. With current cobra code it is not possible to test this behavior.

It looks like a very straightforward and simple change and we can even make it backward compatible with current API.

If there's interest and/or maintainers are open for this change, I'd be willing to work on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions