Browse Source

Use ExecuteBufferedAsync from CliWrap

pull/2642/head
Christoph Wille 3 years ago committed by Siegfried Pammer
parent
commit
266ce4c779
  1. 8
      ICSharpCode.Decompiler.Tests/Helpers/RoslynToolset.cs
  2. 12
      ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs
  3. 91
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  4. 2
      ICSharpCode.Decompiler.Tests/TestTraceListener.cs

8
ICSharpCode.Decompiler.Tests/Helpers/RoslynToolset.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -60,7 +60,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
packageStream,
cache,
logger,
cancellationToken);
cancellationToken).ConfigureAwait(false);
using PackageArchiveReader packageReader = new PackageArchiveReader(packageStream);
NuspecReader nuspecReader = await packageReader.GetNuspecReaderAsync(cancellationToken).ConfigureAwait(false);
@ -72,7 +72,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -72,7 +72,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
fileStream.CopyToFile(targetPath);
return targetPath;
},
logger, cancellationToken);
logger, cancellationToken).ConfigureAwait(false);
}
}
@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
string path = Path.Combine(baseDir, version, "tools");
if (!Directory.Exists(path))
{
await FetchPackage("Microsoft.Net.Compilers", version, Path.Combine(baseDir, version));
await FetchPackage("Microsoft.Net.Compilers", version, Path.Combine(baseDir, version)).ConfigureAwait(false);
}
installedCompilers.Add(version, path);
@ -130,7 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -130,7 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
string path = Path.Combine(baseDir, "tools");
if (!Directory.Exists(path))
{
await FetchPackage("vswhere", "2.8.4", baseDir);
await FetchPackage("vswhere", "2.8.4", baseDir).ConfigureAwait(false);
}
vswherePath = Path.Combine(path, "vswhere.exe");
}

12
ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs

@ -26,6 +26,7 @@ using System.Text.RegularExpressions; @@ -26,6 +26,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CliWrap;
using CliWrap.Buffered;
using NUnit.Framework;
@ -114,20 +115,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -114,20 +115,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
otherOptions += " \"-d:" + string.Join(",", preprocessorSymbols.Select(kv => kv.Key + "=" + kv.Value)) + "\" ";
}
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(vbcPath)
.WithArguments($"{otherOptions}{string.Join(" ", references)} -out:\"{Path.GetFullPath(results.PathToAssembly)}\" {string.Join(" ", sourceFileNames.Select(fn => '"' + Path.GetFullPath(fn) + '"'))}")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Console.WriteLine("output: " + stdout);
Console.WriteLine("errors: " + stderr);
Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
Assert.AreEqual(0, result.ExitCode, "vbc failed");
return results;

91
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -30,6 +30,7 @@ using System.Xml.Linq; @@ -30,6 +30,7 @@ using System.Xml.Linq;
using System.Xml.XPath;
using CliWrap;
using CliWrap.Buffered;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
@ -106,12 +107,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -106,12 +107,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
internal static async Task Initialize()
{
await roslynToolset.Fetch("1.3.2");
await roslynToolset.Fetch("2.10.0");
await roslynToolset.Fetch("3.11.0");
await roslynToolset.Fetch(roslynLatestVersion);
await roslynToolset.Fetch("1.3.2").ConfigureAwait(false);
await roslynToolset.Fetch("2.10.0").ConfigureAwait(false);
await roslynToolset.Fetch("3.11.0").ConfigureAwait(false);
await roslynToolset.Fetch(roslynLatestVersion).ConfigureAwait(false);
await vswhereToolset.Fetch();
await vswhereToolset.Fetch().ConfigureAwait(false);
}
public static async Task<string> AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug)
@ -151,19 +152,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -151,19 +152,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
otherOptions += "/debug ";
}
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(ilasmPath)
.WithArguments($"/nologo {otherOptions}/output=\"{outputFile}\" \"{sourceFileName}\"")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Console.WriteLine("output: " + stdout);
Console.WriteLine("errors: " + stderr);
Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
Assert.AreEqual(0, result.ExitCode, "ilasm failed");
return outputFile;
@ -197,19 +193,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -197,19 +193,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
string ildasmPath = SdkUtility.GetSdkPath("ildasm.exe");
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(ildasmPath)
.WithArguments($"/nobar /utf8 /out=\"{outputFile}\" \"{sourceFileName}\"")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Console.WriteLine("output: " + stdout);
Console.WriteLine("errors: " + stderr);
Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
Assert.AreEqual(0, result.ExitCode, "ildasm failed");
// Unlike the .imagebase directive (which is a fixed value when compiling with /deterministic),
@ -448,20 +439,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -448,20 +439,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
otherOptions += " \"-d:" + string.Join(";", preprocessorSymbols) + "\" ";
}
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(cscPath)
.WithArguments($"{otherOptions} -lib:{libPath} {string.Join(" ", references)} -out:\"{Path.GetFullPath(results.PathToAssembly)}\" {string.Join(" ", sourceFileNames.Select(fn => '"' + Path.GetFullPath(fn) + '"'))}")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Console.WriteLine("output: " + stdout);
Console.WriteLine("errors: " + stderr);
Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
Assert.AreEqual(0, result.ExitCode, "csc failed");
return results;
@ -509,20 +495,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -509,20 +495,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
otherOptions += " \"-d:" + string.Join(";", preprocessorSymbols) + "\" ";
}
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(mcsPath)
.WithArguments($"{otherOptions}-out:\"{Path.GetFullPath(results.PathToAssembly)}\" {string.Join(" ", sourceFileNames.Select(fn => '"' + Path.GetFullPath(fn) + '"'))}")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Console.WriteLine("output: " + stdout);
Console.WriteLine("errors: " + stderr);
Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
Assert.AreEqual(0, result.ExitCode, "mcs failed");
return results;
@ -626,36 +607,26 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -626,36 +607,26 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static async Task<(int ExitCode, string Output, string Error)> Run(string assemblyFileName)
{
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(assemblyFileName)
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
return (result.ExitCode, stdout.ToString(), stderr.ToString());
return (result.ExitCode, result.StandardOutput, result.StandardError);
}
public static async Task<(int ExitCode, string Output, string Error)> RunWithTestRunner(string assemblyFileName, bool force32Bit)
{
StringBuilder stderr = new();
StringBuilder stdout = new();
string pathToRunner = force32Bit
? Path.Combine(TesterPath, "ICSharpCode.Decompiler.TestRunner32.exe")
: Path.Combine(TesterPath, "ICSharpCode.Decompiler.TestRunner.exe");
var command = Cli.Wrap(pathToRunner)
.WithArguments(assemblyFileName)
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
return (result.ExitCode, stdout.ToString(), stderr.ToString());
return (result.ExitCode, result.StandardOutput, result.StandardError);
}
/*
public static int RunInContainer(string assemblyFileName, out string output, out string error)
@ -851,34 +822,28 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -851,34 +822,28 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
string snPath = SdkUtility.GetSdkPath("sn.exe");
StringBuilder stderr = new();
StringBuilder stdout = new();
var command = Cli.Wrap(snPath)
.WithArguments($"-R \"{assemblyPath}\" \"{keyFilePath}\"")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None);
var result = await command.ExecuteAsync().ConfigureAwait(false);
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Assert.AreEqual(0, result.ExitCode, "sn failed");
Console.WriteLine("output: " + stdout);
Console.WriteLine("errors: " + stderr);
Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
}
public static async Task<string> FindMSBuild()
{
string path = vswhereToolset.GetVsWhere();
StringBuilder stdout = new();
var result = await Cli.Wrap(path)
.WithArguments(@"-latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe")
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
.WithValidation(CommandResultValidation.None)
.ExecuteAsync().ConfigureAwait(false);
.ExecuteBufferedAsync().ConfigureAwait(false);
if (result.ExitCode != 0)
throw new InvalidOperationException("Could not find MSBuild");
return stdout.ToString().TrimEnd();
return result.StandardOutput.TrimEnd();
}
}

2
ICSharpCode.Decompiler.Tests/TestTraceListener.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.Tests
[OneTimeSetUp]
public async Task RunBeforeAnyTests()
{
await Tester.Initialize();
await Tester.Initialize().ConfigureAwait(false);
}
}
}

Loading…
Cancel
Save