Browse Source

Use ExecuteBufferedAsync from CliWrap

pull/2642/head
Christoph Wille 4 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
packageStream, packageStream,
cache, cache,
logger, logger,
cancellationToken); cancellationToken).ConfigureAwait(false);
using PackageArchiveReader packageReader = new PackageArchiveReader(packageStream); using PackageArchiveReader packageReader = new PackageArchiveReader(packageStream);
NuspecReader nuspecReader = await packageReader.GetNuspecReaderAsync(cancellationToken).ConfigureAwait(false); NuspecReader nuspecReader = await packageReader.GetNuspecReaderAsync(cancellationToken).ConfigureAwait(false);
@ -72,7 +72,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
fileStream.CopyToFile(targetPath); fileStream.CopyToFile(targetPath);
return targetPath; return targetPath;
}, },
logger, cancellationToken); logger, cancellationToken).ConfigureAwait(false);
} }
} }
@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
string path = Path.Combine(baseDir, version, "tools"); string path = Path.Combine(baseDir, version, "tools");
if (!Directory.Exists(path)) 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); installedCompilers.Add(version, path);
@ -130,7 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
string path = Path.Combine(baseDir, "tools"); string path = Path.Combine(baseDir, "tools");
if (!Directory.Exists(path)) 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"); vswherePath = Path.Combine(path, "vswhere.exe");
} }

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

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

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

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

Loading…
Cancel
Save