Browse Source

Filter out a bunch of non-determinism from the generated pretty test IL files.

pull/1108/head
Daniel Grunwald 8 years ago
parent
commit
f386d0b9d1
  1. 5
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  2. 4
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 6
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

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

@ -119,7 +119,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
if (module.Assembly != null) if (module.Assembly != null)
rd.WriteAssemblyHeader(module.Assembly); rd.WriteAssemblyHeader(module.Assembly);
output.WriteLine(); output.WriteLine();
rd.WriteModuleHeader(module); rd.WriteModuleHeader(module, skipMVID: true);
output.WriteLine(); output.WriteLine();
rd.WriteModuleContents(module); rd.WriteModuleContents(module);
} }
@ -155,6 +155,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
il = Regex.Replace(il, @"^// +Microsoft .* Disassembler\. +Version.*\r?\n", "", RegexOptions.Multiline); il = Regex.Replace(il, @"^// +Microsoft .* Disassembler\. +Version.*\r?\n", "", RegexOptions.Multiline);
// copyright header "All rights reserved" is dependent on system language // copyright header "All rights reserved" is dependent on system language
il = Regex.Replace(il, @"^// +Copyright .* Microsoft.*\r?\n", "", RegexOptions.Multiline); il = Regex.Replace(il, @"^// +Copyright .* Microsoft.*\r?\n", "", RegexOptions.Multiline);
// filename may contain full path
il = Regex.Replace(il, @"^// WARNING: Created Win32 resource file.*\r?\n", "", RegexOptions.Multiline);
File.WriteAllText(outputFile, il); File.WriteAllText(outputFile, il);
return outputFile; return outputFile;
@ -285,7 +287,6 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
options.CompilerOptions = "/unsafe /o" + (flags.HasFlag(CSharpCompilerOptions.Optimize) ? "+" : "-"); options.CompilerOptions = "/unsafe /o" + (flags.HasFlag(CSharpCompilerOptions.Optimize) ? "+" : "-");
options.CompilerOptions += (flags.HasFlag(CSharpCompilerOptions.UseDebug) ? " /debug" : ""); options.CompilerOptions += (flags.HasFlag(CSharpCompilerOptions.UseDebug) ? " /debug" : "");
options.CompilerOptions += (flags.HasFlag(CSharpCompilerOptions.Force32Bit) ? " /platform:anycpu32bitpreferred" : ""); options.CompilerOptions += (flags.HasFlag(CSharpCompilerOptions.Force32Bit) ? " /platform:anycpu32bitpreferred" : "");
options.CompilerOptions += " /baseaddress:0x40000";
if (preprocessorSymbols.Count > 0) { if (preprocessorSymbols.Count > 0) {
options.CompilerOptions += " /d:" + string.Join(";", preprocessorSymbols); options.CompilerOptions += " /d:" + string.Join(";", preprocessorSymbols);
} }

4
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -299,7 +299,9 @@ namespace ICSharpCode.Decompiler.Tests
// re-create .il file if necessary // re-create .il file if necessary
CompilerResults output = null; CompilerResults output = null;
try { try {
output = Tester.CompileCSharp(csFile, cscOptions); string outputFile = Path.ChangeExtension(ilFile,
cscOptions.HasFlag(CSharpCompilerOptions.Library) ? ".dll" : ".exe");
output = Tester.CompileCSharp(csFile, cscOptions, outputFile);
Tester.Disassemble(output.PathToAssembly, ilFile, asmOptions); Tester.Disassemble(output.PathToAssembly, ilFile, asmOptions);
} finally { } finally {
if (output != null) if (output != null)

6
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -1145,7 +1145,7 @@ namespace ICSharpCode.Decompiler.Disassembler
} }
} }
public void WriteModuleHeader(ModuleDefinition module) public void WriteModuleHeader(ModuleDefinition module, bool skipMVID = false)
{ {
if (module.HasExportedTypes) { if (module.HasExportedTypes) {
foreach (ExportedType exportedType in module.ExportedTypes) { foreach (ExportedType exportedType in module.ExportedTypes) {
@ -1163,7 +1163,9 @@ namespace ICSharpCode.Decompiler.Disassembler
} }
output.WriteLine(".module {0}", module.Name); output.WriteLine(".module {0}", module.Name);
output.WriteLine("// MVID: {0}", module.Mvid.ToString("B").ToUpperInvariant()); if (!skipMVID) {
output.WriteLine("// MVID: {0}", module.Mvid.ToString("B").ToUpperInvariant());
}
// TODO: imagebase, file alignment, stackreserve, subsystem // TODO: imagebase, file alignment, stackreserve, subsystem
output.WriteLine(".corflags 0x{0:x} // {1}", module.Attributes, module.Attributes.ToString()); output.WriteLine(".corflags 0x{0:x} // {1}", module.Attributes, module.Attributes.ToString());

Loading…
Cancel
Save