Browse Source

Build self-contained test runners before running tests.

pull/2642/head
Siegfried Pammer 3 years ago
parent
commit
e24b901cd1
  1. 3
      ICSharpCode.Decompiler.TestRunner/ICSharpCode.Decompiler.TestRunner.csproj
  2. 20
      ICSharpCode.Decompiler.TestRunner/Program.cs
  3. 77
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

3
ICSharpCode.Decompiler.TestRunner/ICSharpCode.Decompiler.TestRunner.csproj

@ -4,9 +4,6 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PlatformTarget>x64</PlatformTarget>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\ICSharpCode.Decompiler.Tests\bin\$(Configuration)\$(TargetFramework)\win-x64\</OutputPath>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

20
ICSharpCode.Decompiler.TestRunner/Program.cs

@ -1,4 +1,22 @@
using System; // Copyright (c) 2022 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Reflection; using System.Reflection;
using System.Runtime.Loader; using System.Runtime.Loader;

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

@ -90,6 +90,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static readonly string TesterPath; public static readonly string TesterPath;
public static readonly string TestCasePath; public static readonly string TestCasePath;
static readonly string testRunnerBasePath;
static readonly string packagesPropsFile; static readonly string packagesPropsFile;
static readonly string roslynLatestVersion; static readonly string roslynLatestVersion;
static readonly RoslynToolset roslynToolset; static readonly RoslynToolset roslynToolset;
@ -99,6 +100,11 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{ {
TesterPath = Path.GetDirectoryName(typeof(Tester).Assembly.Location); TesterPath = Path.GetDirectoryName(typeof(Tester).Assembly.Location);
TestCasePath = Path.Combine(TesterPath, "../../../../TestCases"); TestCasePath = Path.Combine(TesterPath, "../../../../TestCases");
#if DEBUG
testRunnerBasePath = Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/bin/Debug/net6.0-windows");
#else
testRunnerBasePath = Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/bin/Release/net6.0-windows");
#endif
packagesPropsFile = Path.Combine(TesterPath, "../../../../../packages.props"); packagesPropsFile = Path.Combine(TesterPath, "../../../../../packages.props");
roslynLatestVersion = XDocument.Load(packagesPropsFile).XPathSelectElement("//RoslynVersion").Value; roslynLatestVersion = XDocument.Load(packagesPropsFile).XPathSelectElement("//RoslynVersion").Value;
roslynToolset = new RoslynToolset(); roslynToolset = new RoslynToolset();
@ -113,6 +119,21 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
await roslynToolset.Fetch(roslynLatestVersion).ConfigureAwait(false); await roslynToolset.Fetch(roslynLatestVersion).ConfigureAwait(false);
await vswhereToolset.Fetch().ConfigureAwait(false); await vswhereToolset.Fetch().ConfigureAwait(false);
#if DEBUG
await BuildTestRunner("win-x86", "Debug").ConfigureAwait(false);
await BuildTestRunner("win-x64", "Debug").ConfigureAwait(false);
#else
await BuildTestRunner("win-x86", "Release").ConfigureAwait(false);
await BuildTestRunner("win-x64", "Release").ConfigureAwait(false);
#endif
}
static async Task BuildTestRunner(string runtime, string config)
{
await Cli.Wrap("dotnet.exe")
.WithArguments(new[] { "build", Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/ICSharpCode.Decompiler.TestRunner.csproj"), "-r", runtime, "-c", config, "--self-contained" })
.ExecuteAsync();
} }
public static async Task<string> AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug) public static async Task<string> AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug)
@ -617,10 +638,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
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)
{ {
string pathToRunner = force32Bit string testRunner = Path.Combine(testRunnerBasePath, force32Bit ? "win-x86" : "win-x64", "ICSharpCode.Decompiler.TestRunner.exe");
? Path.Combine(TesterPath, "ICSharpCode.Decompiler.TestRunner32.exe") var command = Cli.Wrap(testRunner)
: Path.Combine(TesterPath, "ICSharpCode.Decompiler.TestRunner.exe");
var command = Cli.Wrap(pathToRunner)
.WithArguments(assemblyFileName) .WithArguments(assemblyFileName)
.WithValidation(CommandResultValidation.None); .WithValidation(CommandResultValidation.None);
@ -628,57 +647,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
return (result.ExitCode, result.StandardOutput, result.StandardError); return (result.ExitCode, result.StandardOutput, result.StandardError);
} }
/*
public static int RunInContainer(string assemblyFileName, out string output, out string error)
{
AssemblyLoadContext context = new("RunInContainer", isCollectible: true);
context.Resolving += ContextResolving;
var (oldOut, newOut) = WrapOut();
var (oldError, newError) = WrapError();
int result;
try
{
var mainAssembly = context.LoadFromAssemblyPath(assemblyFileName);
var tmp = mainAssembly.EntryPoint!.Invoke(null, Array.Empty<object>());
result = tmp is int i ? i : 0;
}
finally
{
context.Unload();
context.Resolving -= ContextResolving;
Console.SetOut(oldOut);
Console.SetError(oldError);
}
output = newOut.ToString();
error = newError.ToString();
return result;
static Assembly ContextResolving(AssemblyLoadContext context, AssemblyName name)
{
return null;
}
static (TextWriter oldWriter, StringBuilder newOutput) WrapOut()
{
var oldWriter = Console.Out;
var newOutput = new StringBuilder();
Console.SetOut(new StringWriter(newOutput));
return (oldWriter, newOutput);
}
static (TextWriter oldWriter, StringBuilder newOutput) WrapError()
{
var oldWriter = Console.Error;
var newOutput = new StringBuilder();
Console.SetError(new StringWriter(newOutput));
return (oldWriter, newOutput);
}
}
*/
public static Task<string> DecompileCSharp(string assemblyFileName, DecompilerSettings settings = null) public static Task<string> DecompileCSharp(string assemblyFileName, DecompilerSettings settings = null)
{ {
if (settings == null) if (settings == null)

Loading…
Cancel
Save