-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
TestConsole
currently only captures stdOut, it should capture stdErr as well
#1732
Comments
Why did you close this @sudhz ? I'm reading Command Line Interface Guidelines and it says the following: I came across this issue wondering if/how the It seems that it doesn't, but probably should. Tell me if I'm mistaken. |
@FrankRay78 They closed it because TestConsole supports stderr (see |
@patriksvensson I don't see |
I've might be mistaken |
@patriksvensson I don't know this as well as you, but where my interested started was trying to unit test the provided exception handler outputs the message to |
Well, I closed it because I think if you want to check for StdErrConsole: StdOutConsole: Then pass these two instances to your class which needs to print to Since I figured out this pattern, I decided to close this. |
We're using the However, since var mockAnsiConsoleFactory = new Mock<IAnsiConsoleFactory>(MockBehavior.Strict);
var testStandardErrorConsole = new TestConsole();
var testStandardOutConsole = new TestConsole();
mockAnsiConsoleFactory.Setup(m => m.GetStandardErrorConsole()).Returns(testStandardErrorConsole);
mockAnsiConsoleFactory.Setup(m => m.GetStandardOutConsole()).Returns(testStandardOutConsole);
...
var commandResult = app.Run(new string[] {"catalog", "list", "--owner", "doesntexist"}, testStandardOutConsole);
// Assert against testStandardErrorConsole.Output
// Assert against commandResult.Output which should be equivalent to testStandardOutConsole.Output minus the extra formatting While I can see that this definitely works around the issue it feels like it breaks the |
Problem
The
TestConsole
class captures only the standard output (stdout) by default. It uses a StringWriter to capture the console output.How to fix
To capture both stdout and stderr, you would need to modify the
TestConsole
class to handle both streams.Proposed solution
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: