Browse Source

Add PDB test case "LambdaCapturing".

pull/1440/head
Siegfried Pammer 6 years ago
parent
commit
906e350edc
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 26
      ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs
  3. 63
      ICSharpCode.Decompiler.Tests/TestCases/PdbGen/LambdaCapturing.xml

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -204,6 +204,7 @@
<ItemGroup> <ItemGroup>
<Content Include="TestCases\PdbGen\HelloWorld.xml" /> <Content Include="TestCases\PdbGen\HelloWorld.xml" />
<Content Include="TestCases\PdbGen\LambdaCapturing.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

26
ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs

@ -29,6 +29,13 @@ namespace ICSharpCode.Decompiler.Tests
TestGeneratePdb(); TestGeneratePdb();
} }
[Test]
[Ignore("differences in il ranges")]
public void LambdaCapturing()
{
TestGeneratePdb();
}
private void TestGeneratePdb([CallerMemberName] string testName = null) private void TestGeneratePdb([CallerMemberName] string testName = null)
{ {
const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans; 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")); string expectedFileName = Path.ChangeExtension(xmlFile, ".expected.xml");
ProcessXmlFile(Path.ChangeExtension(xmlFile, ".generated.xml")); ProcessXmlFile(expectedFileName);
Assert.AreEqual(File.ReadAllText(xmlFile), File.ReadAllText(Path.ChangeExtension(xmlFile, ".generated.xml"))); 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")) { foreach (var file in document.Descendants("file")) {
file.Attribute("checksum").Remove(); file.Attribute("checksum").Remove();
file.Attribute("embeddedSourceLength").Remove(); file.Attribute("embeddedSourceLength").Remove();
file.ReplaceNodes(new XCData(file.Value.Replace("\uFEFF", ""))); 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");
} }
} }

63
ICSharpCode.Decompiler.Tests/TestCases/PdbGen/LambdaCapturing.xml

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<symbols>
<files>
<file id="1" name="ICSharpCode\Decompiler\Tests\TestCases\PdbGen\LambdaCapturing.cs" language="C#" checksumAlgorithm="SHA256"><![CDATA[using System;
namespace ICSharpCode.Decompiler.Tests.TestCases.PdbGen
{
public class LambdaCapturing
{
public static void Main(string[] args)
{
int num = 4;
int captured = Environment.TickCount + num;
Test((int a, int b) => a + b + captured);
}
private static void Test(Func<int, int, int> p)
{
p(1, 2);
}
}
}
]]></file>
</files>
<methods>
<method containingType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.LambdaCapturing" name="Main" parameterNames="args" token="0x6000001">
<sequencePoints>
<entry offset="0x0" hidden="true" document="1" />
<entry offset="0x5" startLine="9" startColumn="13" endLine="9" endColumn="27" document="1" />
<entry offset="0x7" startLine="10" startColumn="13" endLine="10" endColumn="58" document="1" />
<entry offset="0x14" startLine="11" startColumn="13" endLine="11" endColumn="46" document="1" />
<entry offset="0x24" startLine="12" startColumn="9" endLine="12" endColumn="10" document="1" />
</sequencePoints>
<scope startOffset="0x0" endOffset="0x25">
<local name="local" il_index="0" il_start="0x0" il_end="0x25" attributes="0" />
</scope>
</method>
<method containingType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.LambdaCapturing" name="Test" parameterNames="p" token="0x6000002">
<sequencePoints>
<entry offset="0x0" startLine="16" startColumn="13" endLine="16" endColumn="21" document="1" />
<entry offset="0x9" startLine="17" startColumn="9" endLine="17" endColumn="10" document="1" />
</sequencePoints>
<scope startOffset="0x0" endOffset="0xa" />
</method>
<method containingType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.LambdaCapturing+&lt;&gt;c__DisplayClass0_0" name="&lt;Main&gt;b__0" parameterNames="a, b" token="0x6000005">
<sequencePoints>
<entry offset="0x0" startLine="11" startColumn="28" endLine="11" endColumn="44" document="1" />
</sequencePoints>
<scope startOffset="0x0" endOffset="0xb" />
</method>
</methods>
<method-spans>
<method declaringType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.LambdaCapturing" methodName="Main" parameterNames="args" token="0x6000001">
<document startLine="9" endLine="12" />
</method>
<method declaringType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.LambdaCapturing" methodName="Test" parameterNames="p" token="0x6000002">
<document startLine="16" endLine="17" />
</method>
<method declaringType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.LambdaCapturing+&lt;&gt;c__DisplayClass0_0" methodName="&lt;Main&gt;b__0" parameterNames="a, b" token="0x6000005">
<document startLine="11" endLine="11" />
</method>
</method-spans>
</symbols>
Loading…
Cancel
Save