Comment 3 for bug 797150

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Continuing above comment...

By experimenting, I ascertained that Console.Clear() always applies to the real console, even when Console.SetOut has been called.

For example, in a console program, this code

        public static void Main()
        {
            Console.WriteLine("Starting...");

            var savedOut = Console.Out;
            var sw = new StringWriter();
            Console.WriteLine("Setting Console to StringWriter");
            Console.SetOut(sw);

            Console.WriteLine("This should not appear");
            Console.Clear();
            Console.WriteLine("Neither should this");

            Console.SetOut(savedOut);
            Console.WriteLine("Exiting...");
        }

Results in a cleared screan with "Exiting..." displayed at the top.

Since Console.Clear() is being applied to the real console, the example test runs successfully under nunit-console, but causes an error under the nunit gui, which doesn't have a real console.

An interesting effect, but not an NUnit bug.

Charlie