Skip to content

Commit 4aaf452

Browse files
authored
Merge branch 'icsharpcode:master' into GuessFakeMethodAccessor
2 parents e563294 + c0f0135 commit 4aaf452

35 files changed

+649
-137
lines changed

.github/workflows/build-ilspy.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: msbuild ILSpy.sln /p:Configuration=${{ matrix.configuration }} /p:Platform=$env:BuildPlatform /m
4848

4949
- name: Execute unit tests
50-
run: dotnet test --logger "trx;LogFileName=${{ matrix.configuration }}-test-results.trx" $env:Tests1 $env:Tests2 $env:Tests3
50+
run: dotnet test --logger "junit;LogFileName=${{ matrix.configuration }}.xml" --results-directory test-results $env:Tests1 $env:Tests2 $env:Tests3
5151
env:
5252
Tests1: ICSharpCode.Decompiler.Tests\bin\${{ matrix.configuration }}\net6.0-windows\win-x64\ICSharpCode.Decompiler.Tests.dll
5353
Tests2: ILSpy.Tests\bin\${{ matrix.configuration }}\net6.0-windows\ILSpy.Tests.dll
@@ -58,17 +58,13 @@ jobs:
5858
if: success() || failure()
5959
with:
6060
name: test-results-${{ matrix.configuration }}
61-
path: '**/*.trx'
61+
path: 'test-results/${{ matrix.configuration }}.xml'
6262

6363
- name: Create Test Report
64-
uses: phoenix-actions/test-reporting@v6
65-
if: github.event_name != 'pull_request' && (success() || failure())
64+
uses: test-summary/action@v1
65+
if: always()
6666
with:
67-
name: Unit Test Results (${{ matrix.configuration }})
68-
path: '**/*.trx'
69-
reporter: dotnet-trx
70-
list-suites: 'all'
71-
list-tests: 'failed'
67+
paths: "test-results/${{ matrix.configuration }}.xml"
7268

7369
- name: Format check
7470
run: python BuildTools\tidy.py

ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ public static List<string> GetPreprocessorSymbols(CompilerOptions flags)
318318
}
319319
if ((flags & CompilerOptions.UseRoslynMask) != 0)
320320
{
321-
preprocessorSymbols.Add("NETCORE");
321+
if (!flags.HasFlag(CompilerOptions.TargetNet40))
322+
{
323+
preprocessorSymbols.Add("NETCORE");
324+
}
322325
preprocessorSymbols.Add("ROSLYN");
323326
preprocessorSymbols.Add("CS60");
324327
preprocessorSymbols.Add("VB11");

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

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnitAdapterVersion)" />
5555
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)" />
5656
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
57+
<!-- used for xml test result files -->
58+
<PackageReference Include="JunitXml.TestLogger" Version="$(JUnitXmlTestLoggerVersion)" />
5759
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
5860
<PackageReference Include="System.Memory" Version="4.5.4" />
5961
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" />
@@ -108,6 +110,7 @@
108110
<Compile Include="Output\InsertParenthesesVisitorTests.cs" />
109111
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
110112
<Compile Include="TestAssemblyResolver.cs" />
113+
<None Include="TestCases\Pretty\MetadataAttributes.cs" />
111114
<None Include="TestCases\Correctness\ComInterop.cs" />
112115
<Compile Include="TestCases\Correctness\DeconstructionTests.cs" />
113116
<Compile Include="TestCases\Correctness\DynamicTests.cs" />
@@ -309,6 +312,7 @@
309312

310313
<ItemGroup>
311314
<Content Include="TestCases\PdbGen\ForLoopTests.xml" />
315+
<Content Include="TestCases\PdbGen\CustomPdbId.xml" />
312316
<Content Include="TestCases\PdbGen\HelloWorld.xml" />
313317
<Content Include="TestCases\PdbGen\LambdaCapturing.xml" />
314318
</ItemGroup>

ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs

+41-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Reflection.Metadata;
56
using System.Reflection.PortableExecutable;
67
using System.Runtime.CompilerServices;
78
using System.Text;
@@ -46,18 +47,38 @@ public void LambdaCapturing()
4647
TestGeneratePdb();
4748
}
4849

50+
[Test]
51+
public void CustomPdbId()
52+
{
53+
// Generate a PDB for an assembly using a randomly-generated ID, then validate that the PDB uses the specified ID
54+
(string peFileName, string pdbFileName) = CompileTestCase(nameof(CustomPdbId));
55+
56+
var moduleDefinition = new PEFile(peFileName);
57+
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Metadata.DetectTargetFrameworkId(), null, PEStreamOptions.PrefetchEntireImage);
58+
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings());
59+
var expectedPdbId = new BlobContentId(Guid.NewGuid(), (uint)Random.Shared.Next());
60+
61+
using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, nameof(CustomPdbId) + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
62+
{
63+
pdbStream.SetLength(0);
64+
PortablePdbWriter.WritePdb(moduleDefinition, decompiler, new DecompilerSettings(), pdbStream, noLogo: true, pdbId: expectedPdbId);
65+
66+
pdbStream.Position = 0;
67+
var metadataReader = MetadataReaderProvider.FromPortablePdbStream(pdbStream).GetMetadataReader();
68+
var generatedPdbId = new BlobContentId(metadataReader.DebugMetadataHeader.Id);
69+
70+
Assert.AreEqual(expectedPdbId.Guid, generatedPdbId.Guid);
71+
Assert.AreEqual(expectedPdbId.Stamp, generatedPdbId.Stamp);
72+
}
73+
}
74+
4975
private void TestGeneratePdb([CallerMemberName] string testName = null)
5076
{
5177
const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans;
5278

5379
string xmlFile = Path.Combine(TestCasePath, testName + ".xml");
54-
string xmlContent = File.ReadAllText(xmlFile);
55-
XDocument document = XDocument.Parse(xmlContent);
56-
var files = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value);
57-
Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files);
80+
(string peFileName, string pdbFileName) = CompileTestCase(testName);
5881

59-
string peFileName = Path.Combine(TestCasePath, testName + ".expected.dll");
60-
string pdbFileName = Path.Combine(TestCasePath, testName + ".expected.pdb");
6182
var moduleDefinition = new PEFile(peFileName);
6283
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Metadata.DetectTargetFrameworkId(), null, PEStreamOptions.PrefetchEntireImage);
6384
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings());
@@ -87,6 +108,20 @@ private void TestGeneratePdb([CallerMemberName] string testName = null)
87108
Assert.AreEqual(Normalize(expectedFileName), Normalize(generatedFileName));
88109
}
89110

111+
private (string peFileName, string pdbFileName) CompileTestCase(string testName)
112+
{
113+
string xmlFile = Path.Combine(TestCasePath, testName + ".xml");
114+
string xmlContent = File.ReadAllText(xmlFile);
115+
XDocument document = XDocument.Parse(xmlContent);
116+
var files = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value);
117+
Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files);
118+
119+
string peFileName = Path.Combine(TestCasePath, testName + ".expected.dll");
120+
string pdbFileName = Path.Combine(TestCasePath, testName + ".expected.pdb");
121+
122+
return (peFileName, pdbFileName);
123+
}
124+
90125
private void ProcessXmlFile(string fileName)
91126
{
92127
var document = XDocument.Load(fileName);

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

+6
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ public async Task StaticAbstractInterfaceMembers([ValueSource(nameof(roslynLates
714714
await RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview);
715715
}
716716

717+
[Test]
718+
public async Task MetadataAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
719+
{
720+
await RunForLibrary(cscOptions: cscOptions);
721+
}
722+
717723
async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
718724
{
719725
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings);

ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Debug.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public override void Close()
9292
pc = 2;
9393
}
9494

95-
public override bool get_CheckClose()
95+
public bool get_CheckClose()
9696
{
9797
switch (pc)
9898
{
@@ -106,7 +106,7 @@ public override bool get_CheckClose()
106106

107107
[DebuggerNonUserCode]
108108
[CompilerGenerated]
109-
public override int get_LastGenerated()
109+
public int get_LastGenerated()
110110
{
111111
return current;
112112
}

ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Release.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public override void Close()
9393
pc = 2;
9494
}
9595

96-
public override bool get_CheckClose()
96+
public bool get_CheckClose()
9797
{
9898
switch (pc)
9999
{
@@ -107,7 +107,7 @@ public override bool get_CheckClose()
107107

108108
[DebuggerNonUserCode]
109109
[CompilerGenerated]
110-
public override int get_LastGenerated()
110+
public int get_LastGenerated()
111111
{
112112
return current;
113113
}

ICSharpCode.Decompiler.Tests/TestCases/ILPretty/SequenceOfNestedIfs.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public class SequenceOfNestedIfs
1212
{
1313
public bool _clear;
1414
public Material _material;
15-
public override bool CheckShader()
15+
public virtual bool CheckShader()
1616
{
1717
return false;
1818
}
19-
public override void CreateMaterials()
19+
public virtual void CreateMaterials()
2020
{
2121
if (!_clear)
2222
{

ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ internal class UnknownTypes
22
{
33
private readonly IInterface memberField;
44

5-
public override bool CanExecute(CallbackQuery message)
5+
public virtual bool CanExecute(CallbackQuery message)
66
{
77
return ((IInterface<SomeClass, bool>)(object)memberField).Execute(new SomeClass {
88
ChatId = StaticClass.GetChatId(message),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<symbols>
3+
<files>
4+
<file id="1" name="ICSharpCode.Decompiler.Tests.TestCases.PdbGen\HelloWorld.cs" language="C#" checksumAlgorithm="SHA256"><![CDATA[using System;
5+
6+
namespace ICSharpCode.Decompiler.Tests.TestCases.PdbGen;
7+
8+
public class HelloWorld
9+
{
10+
public static void Main(string[] args)
11+
{
12+
Console.ReadKey();
13+
Console.WriteLine("Hello World!");
14+
Console.ReadKey();
15+
}
16+
}
17+
]]></file>
18+
</files>
19+
</symbols>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Runtime.InteropServices;
3+
4+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
5+
{
6+
internal class MetadataAttributes
7+
{
8+
private class MethodImplAttr
9+
{
10+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11+
public extern void A();
12+
#if NETCORE
13+
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
14+
public extern void B();
15+
#endif
16+
[MethodImpl(MethodImplOptions.ForwardRef)]
17+
public extern void D();
18+
[MethodImpl(MethodImplOptions.InternalCall)]
19+
public extern void E();
20+
[MethodImpl(MethodImplOptions.NoInlining)]
21+
public extern void F();
22+
[MethodImpl(MethodImplOptions.NoOptimization)]
23+
public extern void G();
24+
[PreserveSig]
25+
public extern void H();
26+
[MethodImpl(MethodImplOptions.Synchronized)]
27+
public extern void I();
28+
[MethodImpl(MethodImplOptions.Unmanaged)]
29+
public extern void J();
30+
[MethodImpl(MethodImplOptions.AggressiveInlining, MethodCodeType = MethodCodeType.Native)]
31+
public extern void A1();
32+
#if NETCORE
33+
[MethodImpl(MethodImplOptions.AggressiveOptimization, MethodCodeType = MethodCodeType.Native)]
34+
public extern void B1();
35+
#endif
36+
[MethodImpl(MethodImplOptions.ForwardRef, MethodCodeType = MethodCodeType.Native)]
37+
public extern void D1();
38+
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Native)]
39+
public extern void E1();
40+
[MethodImpl(MethodImplOptions.NoInlining, MethodCodeType = MethodCodeType.Native)]
41+
public extern void F1();
42+
[MethodImpl(MethodImplOptions.NoOptimization, MethodCodeType = MethodCodeType.Native)]
43+
public extern void G1();
44+
[MethodImpl(MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.Native)]
45+
public extern void H1();
46+
[MethodImpl(MethodImplOptions.Synchronized, MethodCodeType = MethodCodeType.Native)]
47+
public extern void I1();
48+
[MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType = MethodCodeType.Native)]
49+
public extern void J1();
50+
[MethodImpl(MethodImplOptions.AggressiveInlining, MethodCodeType = MethodCodeType.OPTIL)]
51+
public extern void A2();
52+
#if NETCORE
53+
[MethodImpl(MethodImplOptions.AggressiveOptimization, MethodCodeType = MethodCodeType.OPTIL)]
54+
public extern void B2();
55+
#endif
56+
[MethodImpl(MethodImplOptions.ForwardRef, MethodCodeType = MethodCodeType.OPTIL)]
57+
public extern void D2();
58+
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.OPTIL)]
59+
public extern void E2();
60+
[MethodImpl(MethodImplOptions.NoInlining, MethodCodeType = MethodCodeType.OPTIL)]
61+
public extern void F2();
62+
[MethodImpl(MethodImplOptions.NoOptimization, MethodCodeType = MethodCodeType.OPTIL)]
63+
public extern void G2();
64+
[MethodImpl(MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.OPTIL)]
65+
public extern void H2();
66+
[MethodImpl(MethodImplOptions.Synchronized, MethodCodeType = MethodCodeType.OPTIL)]
67+
public extern void I2();
68+
[MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType = MethodCodeType.OPTIL)]
69+
public extern void J2();
70+
[MethodImpl(MethodImplOptions.AggressiveInlining, MethodCodeType = MethodCodeType.OPTIL)]
71+
public extern void A3();
72+
#if NETCORE
73+
[MethodImpl(MethodImplOptions.AggressiveOptimization, MethodCodeType = MethodCodeType.Runtime)]
74+
public extern void B3();
75+
#endif
76+
[MethodImpl(MethodImplOptions.ForwardRef, MethodCodeType = MethodCodeType.Runtime)]
77+
public extern void D3();
78+
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
79+
public extern void E3();
80+
[MethodImpl(MethodImplOptions.NoInlining, MethodCodeType = MethodCodeType.Runtime)]
81+
public extern void F3();
82+
[MethodImpl(MethodImplOptions.NoOptimization, MethodCodeType = MethodCodeType.Runtime)]
83+
public extern void G3();
84+
[MethodImpl(MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.Runtime)]
85+
public extern void H3();
86+
[MethodImpl(MethodImplOptions.Synchronized, MethodCodeType = MethodCodeType.Runtime)]
87+
public extern void I3();
88+
[MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType = MethodCodeType.Runtime)]
89+
public extern void J3();
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)