Browse Source

Put generated test assemblies in same folder as test cases, instead of %TMP%

This makes it easier to open them in ILSpy for debugging.
pull/909/merge
Daniel Grunwald 8 years ago
parent
commit
4d755a7ccf
  1. 3
      .gitignore
  2. 5
      ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
  3. 23
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  4. 11
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  5. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/.gitignore

3
.gitignore vendored

@ -10,4 +10,5 @@ _ReSharper*/ @@ -10,4 +10,5 @@ _ReSharper*/
*.ReSharper
*.patch
.vs/
/ILSpy.AddIn/Packages/*
/ILSpy.AddIn/Packages/*
/ICSharpCode.Decompiler.Tests/TestCases/Correctness/*.exe

5
ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs

@ -213,17 +213,18 @@ namespace ICSharpCode.Decompiler.Tests @@ -213,17 +213,18 @@ namespace ICSharpCode.Decompiler.Tests
void RunCS([CallerMemberName] string testName = null, CompilerOptions options = CompilerOptions.UseDebug)
{
string testFileName = testName + ".cs";
string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe";
CompilerResults outputFile = null, decompiledOutputFile = null;
try {
outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options);
outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options,
outputFileName: Path.Combine(TestCasePath, testOutputFileName));
string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly);
decompiledOutputFile = Tester.CompileCSharp(decompiledCodeFile, options);
Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile);
File.Delete(decompiledCodeFile);
File.Delete(outputFile.PathToAssembly);
File.Delete(decompiledOutputFile.PathToAssembly);
} finally {
if (outputFile != null)

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

@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static string AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug)
{
string ilasmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Microsoft.NET\Framework\v4.0.30319\ilasm.exe");
string outputFile = Path.GetFileNameWithoutExtension(sourceFileName);
string outputFile = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(sourceFileName));
string otherOptions = " ";
if (options.HasFlag(AssemblerOptions.Library)) {
outputFile += ".dll";
@ -156,7 +156,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -156,7 +156,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
};
});
public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug)
public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug, string outputFileName = null)
{
List<string> sourceFileNames = new List<string> { sourceFileName };
foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)""")) {
@ -181,7 +181,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -181,7 +181,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
deterministic: true
));
CompilerResults results = new CompilerResults(new TempFileCollection());
results.PathToAssembly = Path.GetTempFileName();
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
var emitResult = compilation.Emit(results.PathToAssembly);
if (!emitResult.Success) {
StringBuilder b = new StringBuilder("Compiler error:");
@ -202,6 +202,9 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -202,6 +202,9 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
if (preprocessorSymbols.Count > 0) {
options.CompilerOptions += " /d:" + string.Join(";", preprocessorSymbols);
}
if (outputFileName != null) {
options.OutputAssembly = outputFileName;
}
options.ReferencedAssemblies.Add("System.Core.dll");
CompilerResults results = provider.CompileAssemblyFromFile(options, sourceFileNames.ToArray());
@ -216,6 +219,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -216,6 +219,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
}
}
internal static string GetSuffix(CompilerOptions cscOptions)
{
string suffix = "";
if ((cscOptions & CompilerOptions.Optimize) != 0)
suffix += ".opt";
if ((cscOptions & CompilerOptions.Force32Bit) != 0)
suffix += ".32";
if ((cscOptions & CompilerOptions.UseDebug) != 0)
suffix += ".dbg";
if ((cscOptions & CompilerOptions.UseRoslyn) != 0)
suffix += ".roslyn";
return suffix;
}
public static int Run(string assemblyFileName, out string output, out string error)
{
ProcessStartInfo info = new ProcessStartInfo(assemblyFileName);

11
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -196,16 +196,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -196,16 +196,7 @@ namespace ICSharpCode.Decompiler.Tests
void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None)
{
var ilFile = Path.Combine(TestCasePath, testName);
if ((cscOptions & CompilerOptions.Optimize) != 0)
ilFile += ".opt";
if ((cscOptions & CompilerOptions.Force32Bit) != 0)
ilFile += ".32";
if ((cscOptions & CompilerOptions.UseDebug) != 0)
ilFile += ".dbg";
if ((cscOptions & CompilerOptions.UseRoslyn) != 0)
ilFile += ".roslyn";
ilFile += ".il";
var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il";
var csFile = Path.Combine(TestCasePath, testName + ".cs");
if (!File.Exists(ilFile)) {

2
ICSharpCode.Decompiler.Tests/TestCases/Pretty/.gitignore vendored

@ -1 +1,3 @@ @@ -1 +1,3 @@
/*.res
/*.dll
/*.exe

Loading…
Cancel
Save