Browse Source

Merge pull request #2768 from icsharpcode/delete-temp-files

pull/2769/head
Siegfried Pammer 3 years ago committed by GitHub
parent
commit
5b8f6e7814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
  2. 2
      ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs
  3. 39
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  4. 1
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  5. 1
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  6. 1
      ICSharpCode.Decompiler.Tests/UglyTestRunner.cs
  7. 1
      ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs

6
ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs

@ -443,9 +443,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -443,9 +443,7 @@ namespace ICSharpCode.Decompiler.Tests
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false);
await Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile, (options & CompilerOptions.UseTestRunner) != 0, (options & CompilerOptions.Force32Bit) != 0);
Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
}
finally
{
@ -473,9 +471,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -473,9 +471,7 @@ namespace ICSharpCode.Decompiler.Tests
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false);
await Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile, (options & CompilerOptions.UseTestRunner) != 0, (options & CompilerOptions.Force32Bit) != 0);
Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
}
finally
{
@ -499,9 +495,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -499,9 +495,7 @@ namespace ICSharpCode.Decompiler.Tests
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false);
await Tester.RunAndCompareOutput(testFileName, outputFile, decompiledOutputFile.PathToAssembly, decompiledCodeFile, (options & CompilerOptions.UseTestRunner) != 0, (options & CompilerOptions.Force32Bit) != 0).ConfigureAwait(false);
Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
}
finally
{

2
ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
if ((flags & CompilerOptions.UseMcsMask) == 0)
{
CompilerResults results = new CompilerResults();
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
results.PathToAssembly = outputFileName;
var (roslynVersion, languageVersion) = (flags & CompilerOptions.UseRoslynMask) switch {
0 => ("legacy", "11"),

39
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
@ -296,6 +297,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -296,6 +297,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
static string GetTargetFrameworkAttributeSnippetFile()
{
// Note: this leaks a temporary file, we're not attempting to delete it, because it is only one.
var tempFile = Path.GetTempFileName();
File.WriteAllText(tempFile, targetFrameworkAttributeSnippet);
return tempFile;
@ -395,7 +397,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -395,7 +397,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
if ((flags & CompilerOptions.UseMcsMask) == 0)
{
CompilerResults results = new CompilerResults();
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
results.PathToAssembly = outputFileName;
var (roslynVersion, languageVersion) = (flags & CompilerOptions.UseRoslynMask) switch {
0 => ("legacy", "5"),
@ -488,7 +490,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -488,7 +490,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
else
{
CompilerResults results = new CompilerResults();
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
results.PathToAssembly = outputFileName;
string testBasePath = RoundtripAssembly.TestDir;
if (!Directory.Exists(testBasePath))
{
@ -828,11 +830,42 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -828,11 +830,42 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public class CompilerResults
{
public string PathToAssembly { get; set; }
readonly HashSet<string> tempFiles = new(Decompiler.Util.Platform.FileNameComparer);
string pathToAssembly;
public string PathToAssembly {
get {
if (pathToAssembly == null)
{
pathToAssembly = Path.GetTempFileName();
tempFiles.Add(pathToAssembly);
}
return pathToAssembly;
}
set {
if (pathToAssembly != null)
{
throw new InvalidOperationException("PathToAssembly can only be set once");
}
pathToAssembly = value;
}
}
public void DeleteTempFiles()
{
foreach (var file in tempFiles)
{
Tester.RepeatOnIOError(() => File.Delete(file));
}
}
public void AddTempFile(string file)
{
if (!Path.IsPathFullyQualified(file))
{
throw new InvalidOperationException("file must be a fully qualified path");
}
tempFiles.Add(file);
}
}
}

1
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -278,6 +278,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -278,6 +278,7 @@ namespace ICSharpCode.Decompiler.Tests
var decompiled = await Tester.DecompileCSharp(executable, settings).ConfigureAwait(false);
CodeAssert.FilesAreEqual(csFile, decompiled);
Tester.RepeatOnIOError(() => File.Delete(decompiled));
}
static readonly object copyLock = new object();

1
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -745,6 +745,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -745,6 +745,7 @@ namespace ICSharpCode.Decompiler.Tests
// 3. Compile
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray());
Tester.RepeatOnIOError(() => File.Delete(decompiled));
}
}
}

1
ICSharpCode.Decompiler.Tests/UglyTestRunner.cs

@ -163,6 +163,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -163,6 +163,7 @@ namespace ICSharpCode.Decompiler.Tests
var decompiled = await Tester.DecompileCSharp(executable, decompilerSettings).ConfigureAwait(false);
CodeAssert.FilesAreEqual(expectedFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray());
Tester.RepeatOnIOError(() => File.Delete(decompiled));
}
}
}

1
ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs

@ -139,6 +139,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -139,6 +139,7 @@ namespace ICSharpCode.Decompiler.Tests
var decompiled = await Tester.DecompileCSharp(executable.PathToAssembly, settings).ConfigureAwait(false);
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(options).ToArray());
Tester.RepeatOnIOError(() => File.Delete(decompiled));
}
}
}

Loading…
Cancel
Save