-
Notifications
You must be signed in to change notification settings - Fork 748
TextRunner accidentally disposes System.Out #4319
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
Comments
Created a PR for this issue: #4318 |
How does PR #4317 and your pull request relate? I've not looked in detail as I don't understand the implications of each. They appear on the surface to do similar things. Can you provide some comments about how they work together, if they are the same or completely different? |
Apparently my colleague and I both created a PR in our spare time for the same issue without telling each other about it. We can close my PR in favor of the PR that @normj created |
Whoops sorry about the miscommunication @jeroenvervaeke and @mr-russ and duplicate PRs |
Not a problem! It's always welcome to have bugs filed, and having two PRs submitted to fix it is never a bad thing either. PS: I enjoyed your recent Lambda GC article @normj , great read. |
Oops, I just noticed that this was the only open issue for this. I'm going to reopen it to track the PR fix |
I update the PR with a test and I can create a PR for 3.13 once I know I did this PR correctly. @stevenaw Great to hear you like the blog post! |
It is possible to replace
System.Out
with your own implementation ofTextWriter
.One reason why you would want to do that is if you want to both capture all output to a stream and write it to console.
I was using this approach and I stumbled upon an issue when using
TextRunner
.When using
TextRunner
, and not providing a file,TextRunner
defaults toSystem.Out
.When
TextRunner
is done running it disposes the underlying stream that it was writing to. This is correct behaviour when using files, but not desired behaviour when usingSystem.Out
.See: source code
I modified
ConsoleColorWriter
soDispose
is a NOP. (The base class disposes the writer provided byConsoleColorWriter
=System.Out
).I've also added a unit test to verify that the fix works. If you want a code example of what crashes, check the unit test.
The text was updated successfully, but these errors were encountered: