-
Notifications
You must be signed in to change notification settings - Fork 553
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 regex filters #589
Add regex filters #589
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, thank you very much 👍
This is a great PR, thanks a lot! :) 🎉
I've been looking, but I couldn't find anything to complain about :D Nice feature, good bug fix, solid testing.
I'm slightly afraid that it might involuntarily break something but I don't think so :D
If you wanted to be super awesome you could dust up the README section on filters a bit, adding the regex filter and Array filter but no worries I can also go around to doing this.
Let's see what the CI says.
I also asked my bunnies to find potential problems, they came up empty so far though.
lib/simplecov/configuration.rb
Outdated
elsif filter_argument.is_a?(Array) | ||
SimpleCov::ArrayFilter.new(filter_argument) | ||
elsif filter_argument | ||
SimpleCov::Filter.class_for_argument(filter_argument).new(filter_argument) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff! 👍
No problem. I'll give the README some TLC today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the updates! Also thanks for fixing the ArrayFilter if I saw correctly :)
Had a couple of comments on that implementations, let's see where we get there :)
end | ||
``` | ||
|
||
You can pass in an array containing any of the other filter types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 👍
lib/simplecov/filter.rb
Outdated
# Returns true if any of the file paths passed in the given array matches the string | ||
# configured when initializing this Filter with StringFilter.new(['some/path', 'other/path']) | ||
def initialize(filter_argument) | ||
filter_argument.map! do |arg| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rather not use map!
as I don't wanna mutate whatever was passed in, so rather without !
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
lib/simplecov/filter.rb
Outdated
if arg.is_a?(SimpleCov::Filter) | ||
arg | ||
else | ||
Filter.class_for_argument(arg).new(arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just thinking out loud, couldn't we also put that check into Filter.class_for_argument
e.g. if it is already a filter? Would make that code easier and centralize the knowledge :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait we can't because this one already instantiates which we wouldn't need there... maybe another helper method? Not quite sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah sounds good. I'll make a factory function that instantiates based the appropriate class type, or does nothing if it's given a filter.
lib/simplecov/filter.rb
Outdated
end | ||
|
||
super(filter_argument) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling, the additions here were necessary because THINGS weren't working. Sounds like we might miss some specs here. If you wanna add those, great! 👍
If not let me know and I'll try to get to it when I got some time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is definitely a hole in the specs. I had to do manual tests to make sure this worked. I'll see if I can whip up some specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff! Some question about two usages but otherwise should be ready to roll. Thanks so much! 🚀
lib/simplecov/filter.rb
Outdated
def self.build_filter(filter_argument) | ||
return filter_argument if filter_argument.is_a?(SimpleCov::Filter) | ||
class_for_argument(filter_argument).new(filter_argument) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍
#### [Sublime Editor: SimpleCov](https://packagecontrol.io/packages/SimpleCov) | ||
*by sentience* | ||
|
||
Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 drive by fixes
lib/simplecov/filter.rb
Outdated
def self.class_for_argument(filter_argument) | ||
return filter_argument if filter_argument.is_a?(SimpleCov::Filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this? I thought if needed this should be handled by .build_filter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely not. Not sure how I put that in there.
lib/simplecov/filter.rb
Outdated
@@ -66,15 +73,15 @@ def matches?(source_file) | |||
|
|||
class ArrayFilter < SimpleCov::Filter | |||
def initialize(filter_argument) | |||
filter_argument.map! do |arg| | |||
filter_objects = filter_argument.map do |arg| | |||
if arg.is_a?(SimpleCov::Filter) | |||
arg | |||
else | |||
Filter.class_for_argument(arg).new(arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't we wanna use .build_filter
here? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right thanks. I knew there was a reason I abstracted that out.
This is a more correct way to get the projects directory, agreed? |
The changes in here will also fix #419 I believe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good and should be good to go in when I have a silent minute :)
lib/simplecov/source_file.rb
Outdated
@@ -82,8 +82,7 @@ def initialize(filename, coverage) | |||
|
|||
# The path to this source file relative to the projects directory | |||
def project_filename | |||
project_dir = File.dirname(File.expand_path(File.basename(__FILE__))) | |||
@filename.sub(/^#{project_dir}/, "") | |||
@filename.sub(/^#{SimpleCov.root}/, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm not too sure but I think it looks good 👍
In the future though, would be preferred to have unrelated changes for other issues etc. in their own PR so they don't get too big and stay more focussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but this change was kind of required for the regex. Without it the regex would be matching the full path, which probably nobody would understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, didn't make that connection in my head. Thanks!
Previously, filter strings passed to `add_filter` have been handled as regexps. It means, for example, `add_filter '.pl'` matches against 'sample.rb' because `.` is handled as _any character_ in regexp. As now we have [regexp filter](simplecov-ruby#589), there's no reason to handle filter strings as regexps. However we need to think about semver with this change. If this behavior was intentional, we cannot introduce this change until next major version bump. Or we can do if this was a _bug_.
Previously, filter strings passed to `add_filter` have been handled as regexps. It means, for example, `add_filter '.pl'` matches against 'sample.rb' because `.` is handled as _any character_ in regexp. As now we have [regexp filter](simplecov-ruby#589), there's no reason to handle filter strings as regexps. However we need to think about semver with this change. If this behavior was intentional, we cannot introduce this change until next major version bump. Or we can do if this was a _bug_.
0.15.0 (2017-08-14) ([changes](simplecov-ruby/simplecov@v0.14.1...v0.15.0)) ======= ## Enhancements * Ability to use regex filters for removing files from the output. See [#589](simplecov-ruby/simplecov#589) (thanks @jsteel) ## Bugfixes * Fix merging race condition when running tests in parallel and merging them. See [#570](simplecov-ruby/simplecov#570) (thanks @jenseng) * Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classigied as irrelevant. See [#605](simplecov-ruby/simplecov#605) (thanks @odlp) * Allow using simplecov with frozen-string-literals enabled. See [#590](simplecov-ruby/simplecov#590) (thanks @pat) * Make sure Array Filter can use all other filter types. See [#589](simplecov-ruby/simplecov#589) (thanks @jsteel) * Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](simplecov-ruby/simplecov#589) (thanks @jsteel)
Add the ability to use regex filters. The regexes should match against the files path relative to the current project, not the full path to root. For example, the file /Users/jon/project/app/foo/test.rb would match on a filter of "jon". I made the String and Array matchers follow that new rule as well.
Fixes #514