Skip to content

Commit

Permalink
Mark ValueTask unit tests with ActiveIssue attribute and make asserti…
Browse files Browse the repository at this point in the history
…ons as if the feature is implemented.
  • Loading branch information
maraf committed Nov 10, 2021
1 parent e00e249 commit 5f30ce3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,32 @@ public static async ValueTask AsynchronousValueTask()
await Task.Yield();
}

public static ValueTask SynchronousValueTask()
{
return ValueTask.CompletedTask;
}

public static ValueTask<int> SynchronousValueTaskInt(int i)
{
return ValueTask.FromResult(i);
}

public static async ValueTask<int> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,16 @@ private static async Task<bool> 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()
{
Expand All @@ -938,57 +948,75 @@ 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.");
}

[Fact]
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<JSException>(() => 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<JSException>(() => 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.");
}
}
}

0 comments on commit 5f30ce3

Please sign in to comment.