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 @@ + +