diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs new file mode 100644 index 000000000..dd35bd413 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using ICSharpCode.Decompiler.Tests.Helpers; +using NUnit.Framework; + +namespace ICSharpCode.Decompiler.Tests +{ + public class ILPrettyTestRunner + { + const string TestCasePath = @"../../../../ICSharpCode.Decompiler.Tests/TestCases/ILPretty"; + + [Test] + public void AllFilesHaveTests() + { + var testNames = typeof(ILPrettyTestRunner).GetMethods() + .Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any()) + .Select(m => m.Name) + .ToArray(); + foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) { + if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) { + var testName = file.Name.Split('.')[0]; + Assert.Contains(testName, testNames); + Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs"))); + } + } + } + + [Test, Ignore("Need to decide how to represent virtual methods without 'newslot' flag")] + public void Issue379() + { + Run(); + } + + void Run([CallerMemberName] string testName = null) + { + var ilFile = Path.Combine(TestCasePath, testName + ".il"); + var csFile = Path.Combine(TestCasePath, testName + ".cs"); + + var executable = Tester.AssembleIL(ilFile, AssemblerOptions.Library); + var decompiled = Tester.DecompileCSharp(executable); + + CodeAssert.FilesAreEqual(csFile, decompiled); + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue379.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue379.cs new file mode 100644 index 000000000..f8e9d3ea1 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue379.cs @@ -0,0 +1,11 @@ +using System; + +namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty +{ + internal class Issue379 + { + public virtual void Test() where T : new() + { + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue379.il b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue379.il new file mode 100644 index 000000000..57c360372 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue379.il @@ -0,0 +1,31 @@ +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly ConsoleApp11 +{ + .ver 1:0:0:0 +} +.module ConsoleApp11.exe +// MVID: {B973FCD6-A9C4-48A9-8291-26DDC248E208} +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00020003 // ILONLY 32BITPREFERRED +// Image base: 0x000001C4B6C90000 + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue379 + extends [mscorlib]System.Object +{ +.method public hidebysig virtual + instance void Test<.ctor T>() cil managed +{ + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret +} // end of method Program::Test +} \ No newline at end of file