Browse Source

Add TestsAssemblyTempPath to enable the ability to redirect to a central location

pull/3231/head
Christoph Wille 10 months ago
parent
commit
17a6197a6a
  1. 1
      .gitignore
  2. 2
      Directory.Packages.props
  3. 38
      ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs
  4. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

1
.gitignore vendored

@ -20,3 +20,4 @@ ILSpy.Installer/wix/ @@ -20,3 +20,4 @@ ILSpy.Installer/wix/
/VERSION
/ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs
*/.vscode/
DecompilerTests.config.json

2
Directory.Packages.props

@ -21,6 +21,8 @@ @@ -21,6 +21,8 @@
<PackageVersion Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta2-22171-02" />
<PackageVersion Include="Microsoft.DiaSymReader" Version="1.4.0" />
<PackageVersion Include="Microsoft.DiaSymReader.Native" Version="17.0.0-beta1.21524.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.NETCore.ILAsm" Version="8.0.0" />

38
ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs

@ -17,24 +17,56 @@ @@ -17,24 +17,56 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
namespace ICSharpCode.Decompiler.Tests.Helpers
{
/// <summary>
/// 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\\"
/// }
/// </summary>
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());
}
}
}

2
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -50,6 +50,8 @@ @@ -50,6 +50,8 @@
<ItemGroup>
<PackageReference Include="DiffLib" />
<PackageReference Include="CliWrap" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="NuGet.Protocol" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Reflection.Metadata" />

Loading…
Cancel
Save