-
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
Changes from 1 commit
a0b14a1
ddc1008
5f88bb5
e31bce9
7250a70
b4ca146
cc8b81d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ def self.class_for_argument(filter_argument) | |
SimpleCov::RegexFilter | ||
elsif filter_argument.is_a?(Array) | ||
SimpleCov::ArrayFilter | ||
elsif filter_argument.is_a?(Proc) | ||
SimpleCov::BlockFilter | ||
else | ||
raise ArgumentError, "You have provided an unrecognized filter type" | ||
end | ||
|
@@ -63,11 +65,23 @@ def matches?(source_file) | |
end | ||
|
||
class ArrayFilter < SimpleCov::Filter | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. I think we should rather not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. just thinking out loud, couldn't we also put that check into There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't we wanna use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right thanks. I knew there was a reason I abstracted that out. |
||
end | ||
end | ||
|
||
super(filter_argument) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
|
||
# Returns true if any of the filters in the array match the given source file. | ||
# Configure this Filter like StringFilter.new(['some/path', /^some_regex/, Proc.new {|src_file| ... }]) | ||
def matches?(source_files_list) | ||
filter_argument.any? do |arg| | ||
source_files_list.project_filename =~ /#{arg}/ | ||
arg.matches?(source_files_list) | ||
end | ||
end | ||
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.
Thanks! 👍