Skip to content

Commit

Permalink
[wasm] Disable some existing System.Console library tests throwing PN…
Browse files Browse the repository at this point in the history
…SE (dotnet#37975)

* [wasm] Disable existing System.Console library tests which fail on WASM with PlatformNotSupportedException; add several tests to reflect WASM PNSE-behavior

* Address feedback
  • Loading branch information
MaximLipnin authored Jun 18, 2020
1 parent 7a8af8c commit 0de5003
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/libraries/System.Console/tests/CancelKeyPress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class CancelKeyPressTests
private const int WaitFailTestTimeoutSeconds = 30;

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void CanAddAndRemoveHandler()
{
ConsoleCancelEventHandler handler = (sender, e) =>
Expand Down
19 changes: 19 additions & 0 deletions src/libraries/System.Console/tests/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
public class Color
{
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void InvalidColors()
{
AssertExtensions.Throws<ArgumentException>(null, () => Console.BackgroundColor = (ConsoleColor)42);
AssertExtensions.Throws<ArgumentException>(null, () => Console.ForegroundColor = (ConsoleColor)42);
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void RoundtrippingColor()
{
Console.BackgroundColor = Console.BackgroundColor;
Expand All @@ -32,6 +34,23 @@ public static void RoundtrippingColor()
}

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public static void ForegroundColor_Throws_PlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.ForegroundColor);
Assert.Throws<PlatformNotSupportedException>(() => Console.ForegroundColor = ConsoleColor.Red);
}

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public static void BackgroundColor_Throws_PlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.BackgroundColor);
Assert.Throws<PlatformNotSupportedException>(() => Console.BackgroundColor = ConsoleColor.Red);
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void RedirectedOutputDoesNotUseAnsiSequences()
{
// Make sure that redirecting to a memory stream causes Console not to write out the ANSI sequences
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Console/tests/ConsoleEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static IEnumerable<object[]> InputData()

[Theory]
[MemberData(nameof(InputData))]
[PlatformSpecific(~TestPlatforms.Browser)]
public void TestEncoding(string inputString)
{
TextWriter outConsoleStream = Console.Out;
Expand Down Expand Up @@ -79,6 +80,7 @@ public void TestEncoding(string inputString)
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void TestValidEncodings()
{
Action<Encoding> check = encoding =>
Expand All @@ -98,7 +100,6 @@ public void TestValidEncodings()
{
check(Encoding.ASCII);
}

}

public class NonexistentCodePageEncoding : Encoding
Expand Down
18 changes: 16 additions & 2 deletions src/libraries/System.Console/tests/ReadAndWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,24 @@ public static unsafe void OutputEncoding()

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public static void OutputEncoding_Browser()
public static void OutputEncoding_Getter_Returns_Unicode()
{
Encoding curEncoding = Console.OutputEncoding;
Assert.Equal(Encoding.Unicode, curEncoding);
Assert.Throws<PlatformNotSupportedException>(() => Console.OutputEncoding = curEncoding );
}

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public static void OutputEncoding_Setter_Throws_PlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.OutputEncoding = Encoding.Unicode);
}

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public static void InputEncoding_Getter_Throws_PlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.InputEncoding);
}

static readonly string[] s_testLines = new string[] {
Expand Down Expand Up @@ -344,6 +357,7 @@ public static void OutputEncoding_Browser()
};

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void ReadAndReadLine()
{
TextWriter savedStandardOutput = Console.Out;
Expand Down
18 changes: 16 additions & 2 deletions src/libraries/System.Console/tests/ReadKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,33 @@ public static void ConsoleKeyValueCheck()
}

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)]
public void NumberLock_GetUnix_ThrowsPlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.NumberLock);
}

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[PlatformSpecific(TestPlatforms.Browser)]
public void NumberLock_Getter_Returns_False()
{
Assert.False(Console.NumberLock);
}

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)]
public void CapsLock_GetUnix_ThrowsPlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.CapsLock);
}

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public void CapsLock_Getter_Returns_False()
{
Assert.False(Console.CapsLock);
}

private static void RunRemote(Func<int> func, ProcessStartInfo psi = null)
{
var options = new RemoteInvokeOptions();
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Console/tests/SetIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class SetIn
{
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void SetInThrowsOnNull()
{
TextReader savedIn = Console.In;
Expand All @@ -26,6 +27,7 @@ public static void SetInThrowsOnNull()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void SetInReadLine()
{
const string TextStringFormat = "Test {0}";
Expand Down
8 changes: 8 additions & 0 deletions src/libraries/System.Console/tests/SyncTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private static void Test(string content, Action action)
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void ReadToEnd()
{
var expected = string.Join(Environment.NewLine, s_testLines);
Expand All @@ -93,6 +94,7 @@ public void ReadToEnd()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void ReadBlock()
{
var expected = new[] { 'H', 'e', 'l', 'l', 'o' };
Expand All @@ -111,6 +113,7 @@ public void ReadBlock()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void Read()
{
var expected = new[] { 'H', 'e', 'l', 'l', 'o' };
Expand All @@ -129,6 +132,7 @@ public void Read()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void Peek()
{
const string expected = "ABC";
Expand All @@ -142,6 +146,7 @@ public void Peek()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void ReadToEndAsync()
{
var expected = string.Join(Environment.NewLine, s_testLines);
Expand All @@ -156,6 +161,7 @@ public void ReadToEndAsync()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void ReadBlockAsync()
{
var expected = new[] { 'H', 'e', 'l', 'l', 'o' };
Expand All @@ -180,6 +186,7 @@ public void ReadBlockAsync()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void ReadAsync()
{
var expected = new[] { 'H', 'e', 'l', 'l', 'o' };
Expand All @@ -204,6 +211,7 @@ public void ReadAsync()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public void ReadLineAsync()
{
var expected = string.Join(Environment.NewLine, s_testLines);
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Console/tests/ThreadSafety.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ThreadSafety
const int NumberOfIterations = 100;

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void OpenStandardXXXCanBeCalledConcurrently()
{
Parallel.For(0, NumberOfIterations, i =>
Expand Down Expand Up @@ -41,6 +42,7 @@ public static void OpenStandardXXXCanBeCalledConcurrently()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void SetStandardXXXCanBeCalledConcurrently()
{
TextReader savedStandardInput = Console.In;
Expand Down Expand Up @@ -83,6 +85,7 @@ public static void SetStandardXXXCanBeCalledConcurrently()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void ReadMayBeCalledConcurrently()
{
const char TestChar = '+';
Expand Down
10 changes: 10 additions & 0 deletions src/libraries/System.Console/tests/Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class TimeOut
{
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void OpenStandardXXX_WriteTimeOut()
{
using (Stream standardOut = Console.OpenStandardOutput(), standardIn = Console.OpenStandardInput(), standardError = Console.OpenStandardError())
Expand All @@ -27,6 +28,7 @@ public static void OpenStandardXXX_WriteTimeOut()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void OpenStandardXXX_ReadTimeOut()
{
using (Stream standardOut = Console.OpenStandardOutput(), standardIn = Console.OpenStandardInput(), standardError = Console.OpenStandardError())
Expand All @@ -42,6 +44,7 @@ public static void OpenStandardXXX_ReadTimeOut()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
public static void OpenStandardXXX_CanTimeOut()
{
using (Stream standardOut = Console.OpenStandardOutput(), standardIn = Console.OpenStandardInput(), standardError = Console.OpenStandardError())
Expand All @@ -51,4 +54,11 @@ public static void OpenStandardXXX_CanTimeOut()
Assert.False(standardError.CanTimeout);
}
}

[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public static void OpenStandardInput_Throws_PlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Console.OpenStandardInput());
}
}
Loading

0 comments on commit 0de5003

Please sign in to comment.