Skip to content

TextRunner accidentally disposes System.Out #4319

@jeroenvervaeke

Description

@jeroenvervaeke

It is possible to replace System.Out with your own implementation of TextWriter.
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 to System.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 using System.Out.
See: source code

I modified ConsoleColorWriter so Dispose is a NOP. (The base class disposes the writer provided by ConsoleColorWriter = 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions