Skip to content

Add support for exclude by attribute #232

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

Closed
nordinrahman opened this issue Nov 1, 2018 · 12 comments
Closed

Add support for exclude by attribute #232

nordinrahman opened this issue Nov 1, 2018 · 12 comments
Labels
enhancement General enhancement request

Comments

@nordinrahman
Copy link

As of now, coverlet could exclude any classes/methods/properties decorated with ExcludeFromCodeCoverage attribute. However, it does not applicable for code annotated by other attributes like GeneratedCodeAttribute nor CompilerGeneratedAttribute. In short, it does not allow user to exclude with arbitrary attribute. This is one of most common feature for other coverage tool (e.g. dotcover) that I usually use.

There are already demands to this feature, as listed below:

The feature will have the following criteria:

  1. Add additional argument parameter --exclude-by-attribute for CLI tool
  2. Add additional MSBUILD property ExcludeByAttribute
  3. Existing implementation to exclude code annotated by ExcludeByCodeCoverage remains as is
  4. Exclusion list could be arbitrary specified in multiple, delimited by ,, just like existing Exclude list.
  5. Any code, i.e.: classes, properties, and methods annotated with listed attributes, will be ignored from coverage.
  6. The behavior of criteria 5 above, will be similar to how existing ExcludeByCodeCoverage works.

TQ.

@tonerdo tonerdo added the enhancement General enhancement request label Nov 4, 2018
@tonerdo
Copy link
Collaborator

tonerdo commented Nov 4, 2018

Hi @nordinrahman, I'm inclined to agree with you on this. Will add it to my personal backlog but I'm open to PRs on this

@amweiss
Copy link
Contributor

amweiss commented Nov 4, 2018

I can start taking a stab at this if no one else is since it also can cover my desire to see ObsoleteAttribute excluded.

@amweiss
Copy link
Contributor

amweiss commented Nov 5, 2018

@nordinrahman if you can, please try to clone my PR (#233) and see if it meets your needs, it passed the basic tests but I'm struggling a bit to see good ways to test it while in development.

@nordinrahman
Copy link
Author

@amweiss , yes I reviewed the code, and it looks good to me.

Initially, I intend to add more unit test to cover the business logic introduced, but it's kinda of a challenge (eg changes on console app).

I'm yet to run the build against sample project, for manual testing - I will update here once I'm done.

Thanks, @amweiss . I wonder what @tonerdo 's opinion on this?

@amweiss
Copy link
Contributor

amweiss commented Nov 6, 2018

@nordinrahman I agree, I did the minimum unit test to make sure the attribute excluded the code from coverage. I do have a few stylistic and coverage changes I'll send over on a subsequent PR if this one is getting merged.

@amweiss
Copy link
Contributor

amweiss commented Nov 8, 2018

Perhaps apparent to other people, but not me, I think it's only going to work as part of a build the way I did it, not in the CLI afterward since it runs at the instrumenter level. So technically it won't meet the needs of this.

@amweiss
Copy link
Contributor

amweiss commented Nov 20, 2018

I believe this is working as part of the build tasks now, @nordinrahman and @tonerdo is there anything left needed to merge #233 ?

@nordinrahman
Copy link
Author

Thanks @amweiss , awesome. Looking forward for new release by @tonerdo

tonerdo added a commit that referenced this issue Nov 28, 2018
@tonerdo
Copy link
Collaborator

tonerdo commented Nov 28, 2018

@nordinrahman @amweiss fix is available in latest NuGet releases

@tonerdo tonerdo closed this as completed Nov 28, 2018
@sbansal-mdsol
Copy link

Can we exclude Startup.cs or Program.cs using ExcludeFromCodeCoverage attribute?

@MarcoRossignoli
Copy link
Collaborator

@amweiss
Copy link
Contributor

amweiss commented Apr 19, 2019

ExcludeFromCodeCoverage is also separate from this, that part worked fine already. This pull request allows for defining arbitrary attributes to ignore as well as ExcludeFromCodeCoverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement General enhancement request
Projects
None yet
Development

No branches or pull requests

5 participants