Skip to content

Commit e7e407c

Browse files
committed
exclude local methods in excluded methods
1 parent d6ea467 commit e7e407c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/coverlet.core/Helpers/InstrumentationHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ public static bool IsTypeExcluded(string module, string type, string[] filters)
165165
return false;
166166
}
167167

168+
public static bool IsLocalMethod(string method)
169+
=> new Regex(WildcardToRegex("<*>*__*|*")).IsMatch(method);
170+
168171
public static string[] GetExcludedFiles(string[] rules)
169172
{
170173
const string RELATIVE_KEY = nameof(RELATIVE_KEY);

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ private void InstrumentModule()
6060
{
6161
resolver.AddSearchDirectory(Path.GetDirectoryName(_module));
6262
var parameters = new ReaderParameters { ReadSymbols = true, AssemblyResolver = resolver };
63+
6364
using (var module = ModuleDefinition.ReadModule(stream, parameters))
6465
{
65-
foreach (var type in module.GetTypes())
66+
var types = module.GetTypes();
67+
foreach (var type in types)
6668
{
67-
InstrumentType(type);
69+
TypeDefinition actualType = type;
70+
if (type.FullName.Contains("/"))
71+
actualType = types.FirstOrDefault(t => t.FullName == type.FullName.Split('/')[0]);
72+
73+
if (!actualType.CustomAttributes.Any(IsExcludeAttribute)
74+
&& !InstrumentationHelper.IsTypeExcluded(_module, actualType.FullName, _filters))
75+
InstrumentType(type);
6876
}
6977

7078
module.Write(stream);
@@ -74,17 +82,14 @@ private void InstrumentModule()
7482

7583
private void InstrumentType(TypeDefinition type)
7684
{
77-
TypeDefinition actualType = type;
78-
if (type.FullName.Contains("/"))
79-
actualType = type.Module.GetTypes().FirstOrDefault(t => t.FullName == type.FullName.Split('/')[0]);
80-
81-
if (actualType.CustomAttributes.Any(IsExcludeAttribute)
82-
|| InstrumentationHelper.IsTypeExcluded(_module, actualType.FullName, _filters))
83-
return;
84-
85-
foreach (var method in type.Methods)
85+
var methods = type.GetMethods();
86+
foreach (var method in methods)
8687
{
87-
if (!method.CustomAttributes.Any(IsExcludeAttribute))
88+
MethodDefinition actualMethod = method;
89+
if (InstrumentationHelper.IsLocalMethod(method.Name))
90+
actualMethod = methods.FirstOrDefault(m => m.Name == method.Name.Split('>')[0].Substring(1)) ?? method;
91+
92+
if (!actualMethod.CustomAttributes.Any(IsExcludeAttribute))
8893
InstrumentMethod(method);
8994
}
9095
}

0 commit comments

Comments
 (0)