Browse Source

Fix VBPretty Async test

pull/2853/head
ElektroKill 3 years ago
parent
commit
684be5c13a
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 4
      ICSharpCode.Decompiler.Tests/TestCases/VBPretty/.gitignore
  2. 62
      ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Async.cs
  3. 3
      ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Async.vb
  4. 2
      ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs

4
ICSharpCode.Decompiler.Tests/TestCases/VBPretty/.gitignore vendored

@ -1 +1,3 @@
*.dll /*.dll
/*.exe
/*.pdb

62
ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Async.cs

@ -2,44 +2,50 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace EquivalentCSharpConsoleApp using Microsoft.VisualBasic.CompilerServices;
[StandardModule]
internal sealed class AsyncProgram
{ {
static class Program [STAThread]
public static void Main(string[] args)
{ {
public static void Main(string[] args) Task task = new Task(ProcessDataAsync);
{ task.Start();
var task = new Task(ProcessDataAsync); task.Wait();
task.Start(); Console.ReadLine();
task.Wait(); }
Console.ReadLine();
}
public async static void ProcessDataAsync() public static async void ProcessDataAsync()
{ {
Task<int> task = HandleFileAsync("C:\\enable1.txt"); Task<int> task = HandleFileAsync("C:\\enable1.txt");
Console.WriteLine("Please wait, processing"); Console.WriteLine("Please wait, processing");
int result = await task; Console.WriteLine("Count: " + await task);
Console.WriteLine("Count: " + result.ToString()); }
}
public async static Task<int> HandleFileAsync(string file) public static async Task<int> HandleFileAsync(string file)
{
Console.WriteLine("HandleFile enter");
int num = 0;
checked
{ {
Console.WriteLine("HandleFile enter"); using (StreamReader streamReader = new StreamReader(file))
int count = 0;
using (StreamReader reader = new StreamReader(file))
{ {
string value = await reader.ReadToEndAsync(); string text = await streamReader.ReadToEndAsync();
count += value.Length; num += text.Length;
for (var i = 0; i <= 10000; i += 1) int num2 = 0;
do
{ {
var x = value.GetHashCode(); if (text.GetHashCode() == 0)
if (x == 0) {
count -= 1; num--;
} }
num2++;
} while (num2 <= 10000);
} }
Console.WriteLine("HandleFile exit"); Console.WriteLine("HandleFile exit");
return count; return num;
} }
} }
} }

3
ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Async.vb

@ -1,7 +1,8 @@
Imports System Imports System
Imports System.IO Imports System.IO
Imports System.Threading.Tasks
Module Program Module AsyncProgram
' Sample taken verbatim from https://www.dotnetperls.com/async-vbnet ' Sample taken verbatim from https://www.dotnetperls.com/async-vbnet
Sub Main(args As String()) Sub Main(args As String())
Dim task = New Task(AddressOf ProcessDataAsync) Dim task = New Task(AddressOf ProcessDataAsync)

2
ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs

@ -89,7 +89,7 @@ namespace ICSharpCode.Decompiler.Tests
CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest, CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest,
}; };
[Test, Ignore("Implement VB async/await")] [Test]
public async Task Async([ValueSource(nameof(defaultOptions))] CompilerOptions options) public async Task Async([ValueSource(nameof(defaultOptions))] CompilerOptions options)
{ {
await Run(options: options); await Run(options: options);

Loading…
Cancel
Save