-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ProcessStandardConsoleTests.cs
59 lines (50 loc) · 2.05 KB
/
ProcessStandardConsoleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.Win32;
using Xunit;
namespace System.Diagnostics.Tests
{
public class ProcessStandardConsoleTests : ProcessTestBase
{
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void TestChangesInConsoleEncoding()
{
const int ConsoleEncoding = 437;
void RunWithExpectedCodePage(int expectedCodePage)
{
Process p = CreateProcessLong();
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
Assert.Equal(expectedCodePage, p.StandardInput.Encoding.CodePage);
Assert.Equal(expectedCodePage, p.StandardOutput.CurrentEncoding.CodePage);
Assert.Equal(expectedCodePage, p.StandardError.CurrentEncoding.CodePage);
p.Kill();
Assert.True(p.WaitForExit(WaitInMS));
};
// Don't test this on Windows containers, as there is a known issue.
// See https://github.com/dotnet/runtime/issues/42000 for more details.
if (!OperatingSystem.IsWindows() || PlatformDetection.IsInContainer)
{
RunWithExpectedCodePage(Encoding.UTF8.CodePage);
return;
}
int inputEncoding = Interop.GetConsoleCP();
int outputEncoding = Interop.GetConsoleOutputCP();
try
{
Interop.SetConsoleCP(ConsoleEncoding);
Interop.SetConsoleOutputCP(ConsoleEncoding);
RunWithExpectedCodePage(ConsoleEncoding);
}
finally
{
Interop.SetConsoleCP(inputEncoding);
Interop.SetConsoleOutputCP(outputEncoding);
}
}
}
}