Repository: dotnet/runtime
File: src/libraries/System.Console/tests/ConsoleHandles.cs (C#)

Code before:
        [PlatformSpecific(TestPlatforms.AnyUnix | TestPlatforms.Windows)]
        public void OpenStandardHandles_DoNotOwnHandle()
        {
            RemoteExecutor.Invoke(() =>
            {
                SafeFileHandle inputHandle = Console.OpenStandardInputHandle();
                SafeFileHandle outputHandle = Console.OpenStandardOutputHandle();
                SafeFileHandle errorHandle = Console.OpenStandardErrorHandle();

                // Disposing should not close the underlying handle since ownsHandle is false
                inputHandle.Dispose();
                outputHandle.Dispose();
                errorHandle.Dispose();

                // Should still be able to get new handles
                using SafeFileHandle inputHandle2 = Console.OpenStandardInputHandle();
                using SafeFileHandle outputHandle2 = Console.OpenStandardOutputHandle();
                using SafeFileHandle errorHandle2 = Console.OpenStandardErrorHandle();

                Assert.NotNull(inputHandle2);
                Assert.NotNull(outputHandle2);
                Assert.NotNull(errorHandle2);
                Assert.False(inputHandle2.IsInvalid);
                Assert.False(outputHandle2.IsInvalid);
                Assert.False(errorHandle2.IsInvalid);
            }).Dispose();
        }

        [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
        [PlatformSpecific(TestPlatforms.AnyUnix | TestPlatforms.Windows)]
        public void OpenStandardHandles_CanBeUsedWithStream()
        {
            RemoteExecutor.Invoke(() =>
            {
                using SafeFileHandle outputHandle = Console.OpenStandardOutputHandle();
                using FileStream fs = new FileStream(outputHandle, FileAccess.Write);
                using StreamWriter writer = new StreamWriter(fs);
                writer.WriteLine("Test output");
            }).Dispose();
        }

        [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
        [PlatformSpecific(TestPlatforms.Android | TestPlatforms.iOS | TestPlatforms.tvOS)]
        public void OpenStandardInputHandle_ThrowsOnUnsupportedPlatforms()
        {
            RemoteExecutor.Invoke(() =>
            {
                Assert.Throws<PlatformNotSupportedException>(() => Console.OpenStandardInputHandle());
            }).Dispose();
        }


Review comment (suggestion):
this is the only test that should keep using `RemoteExecutor`, as long as we can capture its output and assert that the it was actually printed to STD OUT.

Code after:
            outputHandle.Dispose();
            errorHandle.Dispose();

            // Should still be able to get new handles
            using SafeFileHandle inputHandle2 = Console.OpenStandardInputHandle();
            using SafeFileHandle outputHandle2 = Console.OpenStandardOutputHandle();
            using SafeFileHandle errorHandle2 = Console.OpenStandardErrorHandle();

            Assert.NotNull(inputHandle2);
            Assert.NotNull(outputHandle2);
            Assert.NotNull(errorHandle2);
            Assert.False(inputHandle2.IsInvalid);
            Assert.False(outputHandle2.IsInvalid);
            Assert.False(errorHandle2.IsInvalid);
        }

        [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
        [PlatformSpecific(TestPlatforms.Any & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS & ~TestPlatforms.Android)]
        public void OpenStandardHandles_CanBeUsedWithStream()
        {
            using RemoteInvokeHandle child = RemoteExecutor.Invoke(() =>
            {
                using SafeFileHandle outputHandle = Console.OpenStandardOutputHandle();
                using FileStream fs = new FileStream(outputHandle, FileAccess.Write);
                using StreamWriter writer = new StreamWriter(fs);
                writer.WriteLine("Test output");
            }, new RemoteInvokeOptions { StartInfo = new ProcessStartInfo() { RedirectStandardOutput = true } });

            // Verify the output was written
            string output = child.Process.StandardOutput.ReadLine();
            Assert.Equal("Test output", output);
            
            child.Process.WaitForExit();
        }

        [Fact]
        [PlatformSpecific(TestPlatforms.Android | TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.Browser)]
        public void OpenStandardInputHandle_ThrowsOnUnsupportedPlatforms()
        {
            Assert.Throws<PlatformNotSupportedException>(() => Console.OpenStandardInputHandle());
        }

        [Fact]
        [PlatformSpecific(TestPlatforms.Android | TestPlatforms.iOS | TestPlatforms.tvOS)]
        public void OpenStandardOutputHandle_ThrowsOnUnsupportedPlatforms()
        {
            Assert.Throws<PlatformNotSupportedException>(() => Console.OpenStandardOutputHandle());
        }

        [Fact]
        [PlatformSpecific(TestPlatforms.Android | TestPlatforms.iOS | TestPlatforms.tvOS)]