Browse Source

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

pull/3231/head
Christoph Wille 12 months ago
parent
commit
17a6197a6a
  1. 1
      .gitignore
  2. 2
      Directory.Packages.props
  3. 34
      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/
/VERSION /VERSION
/ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs /ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs
*/.vscode/ */.vscode/
DecompilerTests.config.json

2
Directory.Packages.props

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

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

@ -17,24 +17,56 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System;
using System.IO; using System.IO;
using Microsoft.Extensions.Configuration;
namespace ICSharpCode.Decompiler.Tests.Helpers namespace ICSharpCode.Decompiler.Tests.Helpers
{ {
/// <summary> /// <summary>
/// Centralizes all file-path generation for compilation output (assemblies) /// 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> /// </summary>
internal static class TestsAssemblyOutput 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) public static string GetFilePath(string testCasePath, string testName, string computedExtension)
{ {
if (!UseCustomPath)
return Path.Combine(testCasePath, testName) + computedExtension; 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() public static string GetTempFileName()
{ {
if (!UseCustomPath)
return Path.GetTempFileName(); return Path.GetTempFileName();
return Path.Combine(TestsAssemblyTempPath, Path.GetRandomFileName());
} }
} }
} }

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

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

Loading…
Cancel
Save