-
Notifications
You must be signed in to change notification settings - Fork 257
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
Exclude functions from code coverage #476
Comments
You can add |
Hello, Thank you for your response. Like in coverage.py for python, where we can add the list of functions in the configuration files that excludes functions from code coverage. "exclude_lines = Please share your ideas. |
At the moment you can use |
Thank you and sorry for the late response. Do you think it is possible to have a feature like "Pragma: no cover" available in coverage.py that excludes functions from coverage. Please suggest. |
The essential difference is that coverage.py works on the level of Python syntax blocks. When you ignore the line introducing a block ( In contrast, gcovr works on the level of source code lines. Gcovr is completely language-agnostic, and does not attempt to parse source code (aside from some very minor heuristics). The underlying data source usually does include function coverage information (which we want to make use of, e.g. see #325, #362). At some point far into the future it might be possible to ignore any line contained by a particular function or block. However, there will be further problems that Python doesn't have, e.g. name mangling and template specialization. I understand the desire for this feature, but there's no plausible path to actually implement it within a reasonable horizon (I'd estimate it at about 80 person-hours of work, assuming the necessary function coverage information can be extracted easily). But as explained, coverage exclusion markers can be added to achieve the desired effect. We just can't add the convenience feature to ignore a function in one go. |
There is a similar issue regarding lcov at linux-test-project/lcov#116. One suggested alternative to only get “interesting” coverage statistics was to use differential coverage tools. The discussion also pointed out difficulties with handling nested functions, which can even occur in C (with GCC extensions). |
Hi @latk, I wanted to check back in on this request. I stumbled upon this thread when planning to raise a similar question. However, the difference now is that lcov supports the above with Do you believe this work still falls in the camp of 80 person-hours of work, |
Hi @kschwab! Gcovr has started collecting per-function coverage statistics that might also facilitate exclusion processing. There would still be challenges (nested functions, template specialization, name mangling) but it might be good enough for C-style code. Gcovr now has an architecture where exclusions are processed in multiple passes. It would be possible to implement another pass that essentially treats functions as start/stop exclusion markers. I don't have the energy for active contributions to gcovr, so I won't do this myself. But I'll support anyone who does. |
Thank you @latk. If I get the time I will try and lend a hand if possible. Would you like me to create a new issue for tracking this, or can we transition this current one back into opened state? |
I've reopened this issue. A good starting point to work on this would be to look at the existing exclusion processing passes and at the FunctionCoverage data model. Note that lcov knows the |
Hello,
It is good that we can exclude files from code coverage using config files and regex patterns.
Is there any way that we can exclude functions in a file using filters and exclusion markers from config files.
For example, I am looking for a way to exclude functions from code coverage when we add the function names in the config file.
In coverage.py for python, we can add "pragma: no cover" and list of function names in the config file to ignore those functions. In a similar way, can we do it in gcovr?
Please suggest.
The text was updated successfully, but these errors were encountered: