From 5f30ce333b28586cbfc3e92e1a11c97c32103fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 10 Nov 2021 08:01:39 +0100 Subject: [PATCH] Mark ValueTask unit tests with ActiveIssue attribute and make assertions as if the feature is implemented. --- .../JavaScript/HelperMarshal.cs | 21 ++++++ .../JavaScript/MarshalTests.cs | 74 +++++++++++++------ 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs index 477f29ec0923d..f612dcb76be52 100644 --- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs +++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs @@ -679,11 +679,32 @@ public static async ValueTask AsynchronousValueTask() await Task.Yield(); } + public static ValueTask SynchronousValueTask() + { + return ValueTask.CompletedTask; + } + + public static ValueTask SynchronousValueTaskInt(int i) + { + return ValueTask.FromResult(i); + } + public static async ValueTask AsynchronousValueTaskInt(int i) { await Task.Yield(); return i; } + + public static ValueTask FailedSynchronousValueTask() + { + return ValueTask.FromException(new Exception()); + } + + public static async ValueTask FailedAsynchronousValueTask() + { + await Task.Yield(); + throw new Exception(); + } } public enum TestEnum : uint { diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs index 8830b322be1ed..b4b20b30c8049 100644 --- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs +++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs @@ -923,6 +923,16 @@ private static async Task MarshalTask(string helperMethodName, string help return resolved; } + private static async Task MarshalTaskReturningInt(string helperMethodName) + { + HelperMarshal._intValue = 0; + + bool success = await MarshalTask(helperMethodName, "7", "App.call_test_method ('InvokeInt', [ result ], 'i');"); + + Assert.True(success, $"{helperMethodName} didn't succeeded."); + Assert.Equal(7, HelperMarshal._intValue); + } + [Fact] public static async Task MarshalSynchronousTask() { @@ -938,32 +948,21 @@ public static async Task MarshalAsynchronousTask() } [Fact] - public static async Task MarshalSynchronousTaskInt() + public static Task MarshalSynchronousTaskInt() { - HelperMarshal._intValue = 0; - - bool success = await MarshalTask("SynchronousTaskInt", "7", "App.call_test_method ('InvokeInt', [ result ], 'i');"); - - Assert.True(success, "SynchronousTask didn't succeeded."); - Assert.Equal(7, HelperMarshal._intValue); + return MarshalTaskReturningInt("SynchronousTaskInt"); } [Fact] - public static async Task MarshalAsynchronousTaskInt() + public static Task MarshalAsynchronousTaskInt() { - HelperMarshal._intValue = 0; - - bool success = await MarshalTask("AsynchronousTaskInt", "7", "App.call_test_method ('InvokeInt', [ result ], 'i');"); - - Assert.True(success, "AsynchronousTask didn't succeeded."); - Assert.Equal(7, HelperMarshal._intValue); + return MarshalTaskReturningInt("AsynchronousTaskInt"); } [Fact] public static async Task MarshalFailedSynchronousTask() { bool success = await MarshalTask("FailedSynchronousTask"); - Assert.False(success, "FailedSynchronousTask didn't failed."); } @@ -971,24 +970,53 @@ public static async Task MarshalFailedSynchronousTask() public static async Task MarshalFailedAsynchronousTask() { bool success = await MarshalTask("FailedAsynchronousTask"); - Assert.False(success, "FailedAsynchronousTask didn't failed."); } [Fact] - [Trait("Category","Marek")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/61368")] + public static async Task MarshalSynchronousValueTaskDoesNotWorkYet() + { + bool success = await MarshalTask("SynchronousValueTask"); + Assert.True(success, "SynchronousValueTask didn't succeeded."); + } + + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/61368")] public static async Task MarshalAsynchronousValueTaskDoesNotWorkYet() { - var exception = await Assert.ThrowsAsync(() => MarshalTask("AsynchronousValueTask")); - Assert.StartsWith("Error: no idea on how to unbox value types", exception.Message); + bool success = await MarshalTask("AsynchronousValueTask"); + Assert.True(success, "AsynchronousValueTask didn't succeeded."); + } + + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/61368")] + public static Task MarshalSynchronousValueTaskIntDoesNotWorkYet() + { + return MarshalTaskReturningInt("SynchronousValueTaskInt"); + } + + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/61368")] + public static Task MarshalAsynchronousValueTaskIntDoesNotWorkYet() + { + return MarshalTaskReturningInt("AsynchronousValueTaskInt"); + } + + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/61368")] + public static async Task MarshalFailedSynchronousValueTaskDoesNotWorkYet() + { + bool success = await MarshalTask("FailedSynchronousValueTask"); + Assert.False(success, "FailedSynchronousValueTask didn't failed."); } [Fact] - [Trait("Category","Marek")] - public static async Task MarshalAsynchronousValueTaskIntDoesNotWorkYet() + [ActiveIssue("https://github.com/dotnet/runtime/issues/61368")] + public static async Task MarshalFailedAsynchronousValueTaskDoesNotWorkYet() { - var exception = await Assert.ThrowsAsync(() => MarshalTask("AsynchronousValueTaskInt", "7")); - Assert.StartsWith("Error: no idea on how to unbox value types", exception.Message); + bool success = await MarshalTask("FailedAsynchronousValueTask"); + Assert.False(success, "FailedAsynchronousValueTask didn't failed."); } } }