From 906e350edc2932c0252e677db14b636e07f88555 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Feb 2019 16:17:51 +0100 Subject: [PATCH] Add PDB test case "LambdaCapturing". --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PdbGenerationTestRunner.cs | 26 ++++++-- .../TestCases/PdbGen/LambdaCapturing.xml | 63 +++++++++++++++++++ 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/PdbGen/LambdaCapturing.xml diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 679c27753..e492a0799 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -204,6 +204,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs b/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs index 965044f17..0d5ad1884 100644 --- a/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs @@ -29,6 +29,13 @@ namespace ICSharpCode.Decompiler.Tests TestGeneratePdb(); } + [Test] + [Ignore("differences in il ranges")] + public void LambdaCapturing() + { + TestGeneratePdb(); + } + private void TestGeneratePdb([CallerMemberName] string testName = null) { const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans; @@ -59,20 +66,27 @@ namespace ICSharpCode.Decompiler.Tests } } } - ProcessXmlFile(Path.ChangeExtension(pdbFileName, ".xml")); - ProcessXmlFile(Path.ChangeExtension(xmlFile, ".generated.xml")); - Assert.AreEqual(File.ReadAllText(xmlFile), File.ReadAllText(Path.ChangeExtension(xmlFile, ".generated.xml"))); + string expectedFileName = Path.ChangeExtension(xmlFile, ".expected.xml"); + ProcessXmlFile(expectedFileName); + string generatedFileName = Path.ChangeExtension(xmlFile, ".generated.xml"); + ProcessXmlFile(generatedFileName); + Assert.AreEqual(Normalize(expectedFileName), Normalize(generatedFileName)); } - private void ProcessXmlFile(string v) + private void ProcessXmlFile(string fileName) { - var document = XDocument.Load(v); + var document = XDocument.Load(fileName); foreach (var file in document.Descendants("file")) { file.Attribute("checksum").Remove(); file.Attribute("embeddedSourceLength").Remove(); file.ReplaceNodes(new XCData(file.Value.Replace("\uFEFF", ""))); } - document.Save(v, SaveOptions.None); + document.Save(fileName, SaveOptions.None); + } + + private string Normalize(string inputFileName) + { + return File.ReadAllText(inputFileName).Replace("\r\n", "\n").Replace("\r", "\n"); } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/PdbGen/LambdaCapturing.xml b/ICSharpCode.Decompiler.Tests/TestCases/PdbGen/LambdaCapturing.xml new file mode 100644 index 000000000..62e069886 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/PdbGen/LambdaCapturing.xml @@ -0,0 +1,63 @@ + + + + a + b + captured); + } + + private static void Test(Func p) + { + p(1, 2); + } + } +} +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file