From 7e1523111a8d3071ea578a450430ceb9c2436e4d Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Thu, 11 Jul 2024 15:01:08 +0200 Subject: [PATCH 1/4] Set RuntimeIdentifier based on OS architecture --- .../ICSharpCode.Decompiler.Tests.csproj | 13 ++++++++++--- .../ILSpy.BamlDecompiler.Tests.csproj | 9 ++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index c35d60c3ee..ad3805bf5c 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -1,9 +1,16 @@ + + true + true + + net8.0-windows - win-x64 + win-x64 + win-arm64 + false AutoGeneratedProgram @@ -49,8 +56,8 @@ - - + + all diff --git a/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj b/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj index 0c00fb98c1..05807b302f 100644 --- a/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj +++ b/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj @@ -1,9 +1,16 @@  + + true + true + + net8.0-windows - win-x64 + win-x64 + win-arm64 + false AutoGeneratedProgram From c940cbc1d94ec976097df4015bd9df4f28e06cc4 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Thu, 11 Jul 2024 15:31:08 +0200 Subject: [PATCH 2/4] Add TestsAssemblyOutput, keep existing behavior of output assembly locations --- .../CorrectnessTestRunner.cs | 8 ++-- .../Helpers/Tester.cs | 2 +- .../Helpers/TestsAssemblyOutput.cs | 40 +++++++++++++++++++ .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 2 +- .../VBPrettyTestRunner.cs | 2 +- 6 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index 53cb566c07..2b877d1105 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -408,13 +408,13 @@ async Task RunCS([CallerMemberName] string testName = null, CompilerOptions opti if ((options & CompilerOptions.UseRoslynMask) != 0 && (options & CompilerOptions.TargetNet40) == 0) options |= CompilerOptions.UseTestRunner; string testFileName = testName + ".cs"; - string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe"; + string testOutputFileName = TestsAssemblyOutput.GetFilePath(TestCasePath, testName, Tester.GetSuffix(options) + ".exe"); CompilerResults outputFile = null, decompiledOutputFile = null; try { outputFile = await Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options, - outputFileName: Path.Combine(TestCasePath, testOutputFileName)).ConfigureAwait(false); + outputFileName: testOutputFileName).ConfigureAwait(false); string decompiledCodeFile = await Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options)).ConfigureAwait(false); if ((options & CompilerOptions.UseMcsMask) != 0) { @@ -452,13 +452,13 @@ async Task RunVB([CallerMemberName] string testName = null, CompilerOptions opti if ((options & CompilerOptions.UseRoslynMask) != 0) options |= CompilerOptions.UseTestRunner; string testFileName = testName + ".vb"; - string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe"; + string testOutputFileName = TestsAssemblyOutput.GetFilePath(TestCasePath, testName, Tester.GetSuffix(options) + ".exe"); CompilerResults outputFile = null, decompiledOutputFile = null; try { outputFile = await Tester.CompileVB(Path.Combine(TestCasePath, testFileName), options, - outputFileName: Path.Combine(TestCasePath, testOutputFileName)).ConfigureAwait(false); + outputFileName: testOutputFileName).ConfigureAwait(false); string decompiledCodeFile = await Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options)).ConfigureAwait(false); decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false); diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index ecbcf5c1b7..92eb339f6a 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -886,7 +886,7 @@ public string PathToAssembly { get { if (pathToAssembly == null) { - pathToAssembly = Path.GetTempFileName(); + pathToAssembly = TestsAssemblyOutput.GetTempFileName(); tempFiles.Add(pathToAssembly); } return pathToAssembly; diff --git a/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs b/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs new file mode 100644 index 0000000000..62e86e1484 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs @@ -0,0 +1,40 @@ +// Copyright (c) 2024 Christoph Wille +// +// 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.IO; + +namespace ICSharpCode.Decompiler.Tests.Helpers +{ + /// + /// Centralizes all file-path generation for compilation output (assemblies) + /// Here a redirect can be added to a different location for the output (ie a directory that is excluded from virus scanning) + /// + internal static class TestsAssemblyOutput + { + public static string GetFilePath(string testCasePath, string testName, string computedExtension) + { + return Path.Combine(testCasePath, testName) + computedExtension; + } + + public static string GetTempFileName() + { + return Path.GetTempFileName(); + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index ad3805bf5c..572356c2de 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -121,6 +121,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 4fe48369dd..e5c09c9c1a 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -714,7 +714,7 @@ async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOpt async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { var csFile = Path.Combine(TestCasePath, testName + ".cs"); - var exeFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".exe"; + var exeFile = TestsAssemblyOutput.GetFilePath(TestCasePath, testName, Tester.GetSuffix(cscOptions) + ".exe"); if (cscOptions.HasFlag(CompilerOptions.Library)) { exeFile = Path.ChangeExtension(exeFile, ".dll"); diff --git a/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs index c21dc07758..9fcc77b7d6 100644 --- a/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs @@ -147,7 +147,7 @@ async Task Run([CallerMemberName] string testName = null, CompilerOptions option { var vbFile = Path.Combine(TestCasePath, testName + ".vb"); var csFile = Path.Combine(TestCasePath, testName + ".cs"); - var exeFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(options) + ".exe"; + var exeFile = TestsAssemblyOutput.GetFilePath(TestCasePath, testName, Tester.GetSuffix(options) + ".exe"); if (options.HasFlag(CompilerOptions.Library)) { exeFile = Path.ChangeExtension(exeFile, ".dll"); From 17a6197a6aa494bc3ca8804acda83752ba73c124 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Thu, 11 Jul 2024 17:05:54 +0200 Subject: [PATCH 3/4] Add TestsAssemblyTempPath to enable the ability to redirect to a central location --- .gitignore | 1 + Directory.Packages.props | 2 + .../Helpers/TestsAssemblyOutput.cs | 38 +++++++++++++++++-- .../ICSharpCode.Decompiler.Tests.csproj | 2 + 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index be16796fde..e871f125d4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ ILSpy.Installer/wix/ /VERSION /ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs */.vscode/ +DecompilerTests.config.json \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 15f1659216..324ee40f21 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -21,6 +21,8 @@ + + diff --git a/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs b/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs index 62e86e1484..4e83cda9f0 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs @@ -17,24 +17,56 @@ // DEALINGS IN THE SOFTWARE. +using System; using System.IO; +using Microsoft.Extensions.Configuration; + namespace ICSharpCode.Decompiler.Tests.Helpers { /// /// Centralizes all file-path generation for compilation output (assemblies) - /// Here a redirect can be added to a different location for the output (ie a directory that is excluded from virus scanning) + /// + /// DecompilerTests.config.json file format: + /// { + /// "TestsAssemblyTempPath": "d:\\test\\" + /// } /// internal static class TestsAssemblyOutput { + static string? TestsAssemblyTempPath = null; + + private static bool UseCustomPath => !string.IsNullOrWhiteSpace(TestsAssemblyTempPath); + + static TestsAssemblyOutput() + { + var builder = new ConfigurationBuilder() + .AddJsonFile("DecompilerTests.config.json", optional: true, reloadOnChange: false); + + IConfigurationRoot configuration = builder.Build(); + var pathRedirectIfAny = configuration["TestsAssemblyTempPath"]; + + if (!string.IsNullOrWhiteSpace(pathRedirectIfAny)) + { + TestsAssemblyTempPath = pathRedirectIfAny; + } + } + public static string GetFilePath(string testCasePath, string testName, string computedExtension) { - return Path.Combine(testCasePath, testName) + computedExtension; + if (!UseCustomPath) + return Path.Combine(testCasePath, testName) + computedExtension; + + // As we are using the TestsAssemblyTempPath flat, we need to make sure that duplicated test names don't create file name clashes + return Path.Combine(TestsAssemblyTempPath, testName) + Guid.NewGuid().ToString() + computedExtension; } public static string GetTempFileName() { - return Path.GetTempFileName(); + if (!UseCustomPath) + return Path.GetTempFileName(); + + return Path.Combine(TestsAssemblyTempPath, Path.GetRandomFileName()); } } } diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 572356c2de..7970f62653 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -50,6 +50,8 @@ + + From ae338a001e606ed8695026311fbb63e14e63bcc2 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Thu, 11 Jul 2024 17:55:51 +0200 Subject: [PATCH 4/4] Early return if DecompilerTests.config.json doesn't exist (saves time with ConfigurationBuilder) --- ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs b/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs index 4e83cda9f0..492ccf7fb8 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs @@ -40,6 +40,9 @@ internal static class TestsAssemblyOutput static TestsAssemblyOutput() { + if (!File.Exists("DecompilerTests.config.json")) + return; + var builder = new ConfigurationBuilder() .AddJsonFile("DecompilerTests.config.json", optional: true, reloadOnChange: false);