I was surprised recently, when I tried to filter out a particular file from coverage analysis that this usage [1]:
SimpleCov.start do
add_filter 'lib/some/file/to/ignore.rb'
track_files '{app,lib}/**/*'
results in a coverage report that says lib/some/file/to/ignore.rb has 0% coverage. I expected that add_filter would remove the file entirely from the report. I'm probably going to change my code to a slightly uglier track_files, but I wonder if there is or should be a cleaner way to do this.
[1] In reality, I'm using SimpleCov.start('rails') and was surprised that my filters weren't being applied.
yup that is somewhat obscure behaviour, sorry :|
@PragTob: Is it a feature or a bug, though? Would you consider a PR that applies filters to tracked files? Alternatively, would you prefer a PR that allows multiple track_files patterns so one could carefully exclude directories?
Honestly I'd have to review this, as in what's up right now/why was it introduced back in the time/how do they interact right now. I feel like filters should be applied to tracked files, i.e. if I wanna track files outside of the directory but then ignore some of them.
That you can't ignore files in the default rails track_files is really a problem.
Ah before I go hunting and eventually writing emails myself I'll try to @colszowka and @bf4 to see what's up / opinions / historic context
@PragTob Very sorry for the late reply and @cbeer Thanks for the bug report!
The filtering functionality has been part of simplecov since the beginning. Meanwhile, the explicit track_files feature came via #422 around two years ago. So I'm pretty sure this is a bug and should be fixed :)
I agree that track_files should not lead to filtered out files to appear again in your coverage report. Basically it's just an addon to the list of source files the coverage STDLIB cannot see due to the way how it operates, and therefore, I would expect filters to work the same way on those files as they do on the "regular" base file set reported by the coverage lib.
@cbeer PR would be very welcome! :heart:
Thanks for the input @colszowka ! :tada:
Hi, I am wondering if this issue has been rectified?
@vishthemenon not yet no, my time is sadly somewhat limited - PRs welcome :)
@PragTob Will take a look when I get some time soon. Will poke you when I hit a wall. :)