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

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

Closed
koiuo opened this issue Oct 14, 2018 · 2 comments
Closed

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

koiuo opened this issue Oct 14, 2018 · 2 comments

Comments

@koiuo
Copy link

koiuo commented Oct 14, 2018

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.

@koiuo koiuo changed the title Command.SetErrOutput for more finegrained testing Command.SetErrOutput(io.Writer) for more finegrained testing Oct 14, 2018
@jleni
Copy link
Contributor

jleni commented Feb 9, 2019

This is definitely necessary.
I would even go as far as adding a third method to redirec sdtin too.
Sometimes, CLIs need some input and we definitely need all these three to properly test things.
btw, this other open issue proposes the same. #658

@github-actions
Copy link

github-actions bot commented Apr 8, 2020

This issue is being marked as stale due to a long period of inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants