Skip to content

Commit

Permalink
Add TestsAssemblyTempPath to enable the ability to redirect to a cent…
Browse files Browse the repository at this point in the history
…ral location
  • Loading branch information
christophwille committed Jul 11, 2024
1 parent c940cbc commit 17a6197
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ ILSpy.Installer/wix/
/VERSION
/ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs
*/.vscode/
DecompilerTests.config.json
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
38 changes: 35 additions & 3 deletions ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

0 comments on commit 17a6197

Please sign in to comment.