Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of ExcludeFromCodeCoverage attribute #112

Merged
merged 3 commits into from Jun 5, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/coverlet.core/Instrumentation/Instrumenter.cs
Expand Up @@ -24,6 +24,14 @@ internal class Instrumenter
private readonly static Lazy<MethodInfo> _markExecutedMethodLoader = new Lazy<MethodInfo>(GetMarkExecutedMethod);
private InstrumenterResult _result;

private static readonly string[] _excludeAttributeNames = new[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't think we need this as a field. A local variable is just fine

{
nameof(ExcludeFromCoverageAttribute),
"ExcludeFromCoverage",
nameof(ExcludeFromCodeCoverageAttribute),
"ExcludeFromCodeCoverage"
};

public Instrumenter(string module, string identifier, string[] filters, string[] excludedFiles)
{
_module = module;
Expand Down Expand Up @@ -271,9 +279,7 @@ private static void ReplaceExceptionHandlerBoundary(ExceptionHandler handler, In
private static bool IsExcludeAttribute(CustomAttribute customAttribute)
{
var attributeName = customAttribute.AttributeType.Name;

return attributeName == nameof(ExcludeFromCoverageAttribute) || attributeName == "ExcludeFromCoverage"
|| attributeName == nameof(ExcludeFromCodeCoverageAttribute) || attributeName == "ExcludeFromCodeCoverage";
return _excludeAttributeNames.Any(a => a.Equals(attributeName));
}

private static Mono.Cecil.Cil.MethodBody GetMethodBody(MethodDefinition method)
Expand Down