Browse Source

Delete created temp files if test execution was successful.

pull/2768/head
Siegfried Pammer 3 years ago
parent
commit
6139d9d58e
  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
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false); 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); 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(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} }
finally finally
{ {
@ -473,9 +471,7 @@ namespace ICSharpCode.Decompiler.Tests
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false); 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); 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(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} }
finally finally
{ {
@ -499,9 +495,7 @@ namespace ICSharpCode.Decompiler.Tests
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false); 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); 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(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} }
finally finally
{ {

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

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

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

@ -18,6 +18,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
@ -296,6 +297,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
static string GetTargetFrameworkAttributeSnippetFile() 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(); var tempFile = Path.GetTempFileName();
File.WriteAllText(tempFile, targetFrameworkAttributeSnippet); File.WriteAllText(tempFile, targetFrameworkAttributeSnippet);
return tempFile; return tempFile;
@ -395,7 +397,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
if ((flags & CompilerOptions.UseMcsMask) == 0) if ((flags & CompilerOptions.UseMcsMask) == 0)
{ {
CompilerResults results = new CompilerResults(); CompilerResults results = new CompilerResults();
results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); results.PathToAssembly = outputFileName;
var (roslynVersion, languageVersion) = (flags & CompilerOptions.UseRoslynMask) switch { var (roslynVersion, languageVersion) = (flags & CompilerOptions.UseRoslynMask) switch {
0 => ("legacy", "5"), 0 => ("legacy", "5"),
@ -488,7 +490,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
else else
{ {
CompilerResults results = new CompilerResults(); CompilerResults results = new CompilerResults();
results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); results.PathToAssembly = outputFileName;
string testBasePath = RoundtripAssembly.TestDir; string testBasePath = RoundtripAssembly.TestDir;
if (!Directory.Exists(testBasePath)) if (!Directory.Exists(testBasePath))
{ {
@ -828,11 +830,42 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public class CompilerResults 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() 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
var decompiled = await Tester.DecompileCSharp(executable, settings).ConfigureAwait(false); var decompiled = await Tester.DecompileCSharp(executable, settings).ConfigureAwait(false);
CodeAssert.FilesAreEqual(csFile, decompiled); CodeAssert.FilesAreEqual(csFile, decompiled);
Tester.RepeatOnIOError(() => File.Delete(decompiled));
} }
static readonly object copyLock = new object(); static readonly object copyLock = new object();

1
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -745,6 +745,7 @@ namespace ICSharpCode.Decompiler.Tests
// 3. Compile // 3. Compile
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray()); 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
var decompiled = await Tester.DecompileCSharp(executable, decompilerSettings).ConfigureAwait(false); var decompiled = await Tester.DecompileCSharp(executable, decompilerSettings).ConfigureAwait(false);
CodeAssert.FilesAreEqual(expectedFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray()); 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
var decompiled = await Tester.DecompileCSharp(executable.PathToAssembly, settings).ConfigureAwait(false); var decompiled = await Tester.DecompileCSharp(executable.PathToAssembly, settings).ConfigureAwait(false);
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(options).ToArray()); CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(options).ToArray());
Tester.RepeatOnIOError(() => File.Delete(decompiled));
} }
} }
} }

Loading…
Cancel
Save