-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analyzers/AnalyzerScope loops endlessly when analysing public inner c…
…lass
- Loading branch information
1 parent
84c5e63
commit 808cef9
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using ICSharpCode.Decompiler; | ||
using ICSharpCode.Decompiler.CSharp.Resolver; | ||
using ICSharpCode.Decompiler.Metadata; | ||
using ICSharpCode.Decompiler.TypeSystem; | ||
using ICSharpCode.ILSpy.Analyzers; | ||
|
||
using Mono.Cecil; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace ICSharpCode.ILSpy.Tests.Analyzers | ||
{ | ||
|
||
[TestFixture] | ||
public class AnalyzerScopeTests | ||
{ | ||
public class TestClass | ||
{ | ||
|
||
} | ||
|
||
|
||
[Test] | ||
public void WhenPublicNestedClass_ThenNotInfiniteLoop() | ||
{ | ||
// Given | ||
ILSpyX.AssemblyList assemblyList = new ILSpyX.AssemblyList(); | ||
var file = new PEFile(this.GetType().Assembly.Location); | ||
var td = file.Metadata.TypeDefinitions.First(td => td.GetFullTypeName(file.Metadata).Name == nameof(TestClass)); | ||
|
||
Decompiler.Metadata.IAssemblyResolver assemblyResolver = new UniversalAssemblyResolver(null, false, null); | ||
ICompilation compilation = new DecompilerTypeSystem(file, assemblyResolver); | ||
ITypeResolveContext context = new CSharpResolver(compilation); | ||
var module = ((IModuleReference)file).Resolve(context) as MetadataModule; | ||
IEntity entity = module.GetDefinition(td); | ||
|
||
// When | ||
var task = Task.Run(() => { | ||
var target = new AnalyzerScope(assemblyList, entity); | ||
}); | ||
|
||
var result = Task.WaitAny(new[] { task, Task.Delay(500) }); // 0.5 seconds | ||
|
||
// Then | ||
Assert.That(result == 0, "The constructor should completes in no longer than 10 seconds"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters