Ensure Console.Out is not disposed and is restored if it was replaced during the test run #4317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm on the AWS .NET team. We got a report from a user that used
NUnitLite
and got an object disposed exception when using this library in their AWS Lambda functions. Lambda is AWS's serverless compute offering.In Lambda we redirect
Console.Out
to our ownStreamWriter
for logging.NUnitLite
is wrappingConsole.Out
with its ownColorConsoleWriter
and when it is done it disposesColorConsoleWriter
and disposes its innerTextWriter
which would normally be the console stdout that ignores the dispose call but instead calls ourTextWriter
to dispose. With ourTextWriter
disposed any calls toConsole.Out
now fail.We have fixed Lambda to ignore the dispose call but I though this PR would be helpful for others to ensure
NUnitLite
doesn't accidently dispose of somebody else's customConsole.Out
.I also made sure if
Console.SetOut
orConsole.SetError
are used to be sure to restore to the originalTextWriter
s after the run is complete.Fixes #4319