-
Notifications
You must be signed in to change notification settings - Fork 386
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
Is it possible to specify a directory to exclude from coverage? #56
Comments
We're also using gRPC code generation which makes the attribute-based exclusion feature unrealistic. A configuration or flag based solution would really help out here. |
@tonerdo the syntax suggested in #55 looks like it could be a winner - if that were a globbing pattern (and we'd have to support multiple globs). My suggestion would be a semicolon separated list of globs (probably have to quote it)
I think it would need to support both absolute and relative paths. Thoughts? |
I totally agree! My only thought is whether to limit this feature to just whole assemblies or to extend it to allow specifying namespaces/classes/methods and how that will work. |
In my scenario could be very useful also to have an "include" switch(a lot of auxiliary class i don't test). I like the idea of json config file(in addition) because we can address both. Another concern is the case with a lot of include/exclude, command line could become hard to use and i don't like the idea to organize code for coverage, again this isn't possible on existing code. My idea is to chose the code i want to test with minimum % of coverage or fail for new or existing code. |
@tonerdo I think the easiest would be path based. This will cover the majority of the scenarios, and devs can use the attribute method to exclude methods still. I don't see a scenario where I'd want to cover most code generated code, but not one particular method. At the very least, I'd expect such code to be generated in its own file. @MarcoRossignoli I think the ability to both include and exclude is valuable. I think if we help out with implementing an msbuild switch, it would be easy to include an msbuild xml file in your project (via project includes), which could define these in a file for you. |
@abe545 Path-based meaning everything inside the directory specified in the path, as well as all sub-directories? That idea would be flexible enough to encompass generated code perfectly. It also allows you to target large swaths of code or down to a single file at a time. @tonerdo I don't think assembly-only based exclusions would be flexible enough. It would potentially force the developer to create additional projects specifically to exclude portions of code from code coverage right? Even the config I would think would end up path-based too? What do you guys think? |
@ryanmvt yes... except I was thinking to support globbing patterns. If you don't specify any wildcards, it would indeed exclude the directory. That way, you could even do something like |
@tonerdo sounds good to me |
Awesome! Now who's gonna open that PR 😄? |
My coworker @ido-namely has volunteered, if nobody else wants it. |
Thank's a lot @abe545 @ido-namely ! |
I'm familiar with OpenCover and I've always liked the filter option it provides. Not saying Coverlet should use the same syntax and options though. Their filter option can include or exclude by assembly name and/or by type. I know that this topic is about excluding directories but I think the problem really boils down to have fine grained control over what to include and exclude. Personally I've never excluded something based on physical location but I've always specified what to include/exclude using assembly names and namespaces. Again, I'm not suggesting Coverlet should use the same syntax but it might be worth to take a look. The following is copied/based on OpenCovers wiki page Syntax : Examples
|
Would appreciate your comments on : #64 |
All this while my mind has been on ignoring assemblies (e.g. SomeAssembly.dll) from this PR it seems you guys were referring to actual source files. Is this about right? |
i think so(IMHO anyway after some thought on @coenm post...i think we could be more close to opencovers accepted standard, coverlet plus is cross plat support). @abe545 your generated class are in special namespaces?Or your issue is this(same namespace of "production classes"? |
So this issue is about excluding source files from coverage. As I see it, both options provide a different mechanism to have more control over what to cover and what to exclude. When working with filenames however, please take into account that Coverlet is a cross platform product.
|
very good point... |
Our use case is for code that gets generated by a tool (grpc). The tool does so based off some input files, which optionally define a namespace, and if not, will generate one based on the name of the input file. What this all means is that we would likely have to modify our coverage commands anytime an input changed (or we need to rely on a new generated file). I'm personally trying to build a set of scripts that can work throughout our organization, and we can decide where the files are generated, but not the contents of them. For our use case, physical file paths are the best way to do it. Yes, linux/windows paths are different (but the abstractions are good at using unixy paths, and rooted paths are also easy to detect in a xplat way ( Regarding partial classes - correct me if I'm wrong, but coverage is explicitly tied to a file. I don't think partials are too big a hurdle. If one of the class files is excluded from coverage, then the rest of the class can still have coverage generated. If people want the ability to exclude assembly and types, I'm all for it. But for us, the path based solution is still a better fit. I don't think it would be too difficult to support both. |
@tonerdo yes, we were more focused on file paths than assemblies (my team is also using gRPC code generation). Assembly exclusion is probably good to exclude entire projects from coverage, but namespace/type exclusion is probably much more useful (and granular). I would be happy personally with either one of these, or both solutions. Both could definitely work, and each one is probably more helpful for different circumstances. |
We can definitely have both assembly based filtering and source file based filtering, we don't necessarily have to choose. My only thought is how we want that functionality to look like from a usability standpoint. Right now I'm thinking of introducing 2 new properties: Excluding sources:
@ido-namely has already made some good progress on this. Much appreciated! Excluding assemblies:
The values for But at this point it feels a bit verbose and I'm currently leaning towards a single |
@tonerdo i agree with you on single prop. |
I think I addressed all your comments and submitted some changes (let me know if I missed something). |
One point I just thought of regarding the single property - what about the case where your source dir is the parent dir for your assemblies, I think in this case it wouldn't be so easy to just exclude some sources files without it excluding the assemblies, or is there an easy solution for that? |
#64 is all merged in. Will get to adding a |
@ido-namely thank's for PR! |
First of all, thanks for the pull request @ido-namely! I noticed that the latest nuget package does not contain this feature. Is there a release date for this feature? @tonerdo |
Thanks @ido-namely. @mathnogueira, @MarcoRossignoli, @ryanmvt, @abe545 new release here: https://www.nuget.org/packages/coverlet.msbuild/1.2.0. @MarcoRossignoli kindly help open a new issue to track adding a Thanks everyone for the productive comments |
New release available here: https://www.nuget.org/packages/coverlet.msbuild/2.0.0. Thanks for your help and patience guys |
greetings, over a year later here. :) I'm curious if any progress was made on excluding code covered by specifying namespaces in the our codebase is built in Azure DevOps, and tested with |
You could try with something like |
is that the exact syntax required this? I see no different results when running with that in the
thanks for the log suggestion - good to know. |
Mmm...I'll give it a try...I never tested for namespace, but I expect that is something close to that...and I think that we should support that filter feature if missing. |
@jeffrutland I did some test and syntax should work...I added some test to be sure, take a look to sample #579 |
Is this supported by coverlet.collector I've tried but it won't work. The build agent is linux |
@micheleissa yes, we use <?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>lcov</Format>
<Exclude>[xunit*]*</Exclude>
<ExcludeByFile>/app/gen/Namely.*.Grpc/*</ExcludeByFile>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings> |
@abe545
I'm trying to exclude anything in TinyIoC namespace. Does it have to be done via runsettings ? |
So those properties you're passing with I'm not a maintainer of this fantastic project, so I may not have the latest info. |
no most of them work fine, I'm following MS docs from here Now the comma separated list for namespaces is giving me errors regarding msbuild something like
@MarcoRossignoli , @tonerdo |
@micheleissa ah, according the msdn documentation, you're using the msbuild collector. This is how we used to use the msbuild collector (note that we escape the quotes because it was required in the dockerfile to force docker to pass the quotes to the actual command to run - you might be experiencing something similar):
|
@abe545 I will try it, thanks a lot. |
I tried the following:
getting
Any ideas? |
@micheleissa pls can you open a new issue and attach the console output you get when you say VSTest engine integration The coverage engine is the same undeneath but the "entry point"(we call these drivers) can be different with different way to setup things Thanks a lot @abe545 for the help. |
/p:Exclude don't works |
@jrichardsz Actually I'm using p:/Exclude in pipelines and it does work. |
Try with |
After a long amount of searching around and trial and error, what I had to do to solve this problem (alluded to in previous comments) is to add the following to my <PackageReference Include="coverlet.msbuild" Version="6.0.0"/> And then I had to switch from the following command:
To:
|
Hi, we would love to start using coverlet to generate code coverage, but we really don't want to include code that gets automatically generated in our coverage results. Since we generate it during CI, it wouldn't be feasible for us to apply attributes to every class that we want to exclude from coverage. We do, however, have a common folder in which the code gets generated.
Is there a flag we can pass to exclude the files in said folder from coverage?
The text was updated successfully, but these errors were encountered: