Skip to content
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

Merged
merged 7 commits into from
Jun 24, 2017
Merged

Add regex filters #589

merged 7 commits into from
Jun 24, 2017

Conversation

jsteel
Copy link

@jsteel jsteel commented Jun 16, 2017

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

Copy link
Collaborator

@PragTob PragTob left a 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.

img_20170616_204511_01

elsif filter_argument.is_a?(Array)
SimpleCov::ArrayFilter.new(filter_argument)
elsif filter_argument
SimpleCov::Filter.class_for_argument(filter_argument).new(filter_argument)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff! 👍

@jsteel
Copy link
Author

jsteel commented Jun 19, 2017

No problem. I'll give the README some TLC today.

Copy link
Collaborator

@PragTob PragTob left a 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

# 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|
Copy link
Collaborator

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 ! :)

Copy link
Author

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator

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 :)

Copy link
Collaborator

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.

Copy link
Author

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.

end

super(filter_argument)
end
Copy link
Collaborator

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 :)

Copy link
Author

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.

Copy link
Collaborator

@PragTob PragTob left a 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! 🚀

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

#### [Sublime Editor: Simple​Cov](https://packagecontrol.io/packages/SimpleCov)
*by sentience*

Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 drive by fixes

def self.class_for_argument(filter_argument)
return filter_argument if filter_argument.is_a?(SimpleCov::Filter)
Copy link
Collaborator

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 ?

Copy link
Author

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.

@@ -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)
Copy link
Collaborator

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? :)

Copy link
Author

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.

@jsteel
Copy link
Author

jsteel commented Jun 22, 2017

This is a more correct way to get the projects directory, agreed?

@jsteel
Copy link
Author

jsteel commented Jun 22, 2017

The changes in here will also fix #419 I believe

Copy link
Collaborator

@PragTob PragTob left a 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 :)

@@ -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}/, "")
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Collaborator

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!

@PragTob PragTob merged commit 44064c3 into simplecov-ruby:master Jun 24, 2017
PragTob added a commit that referenced this pull request Jun 24, 2017
yujinakayama added a commit to yujinakayama/simplecov that referenced this pull request Aug 27, 2017
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_.
yujinakayama added a commit to yujinakayama/simplecov that referenced this pull request Aug 27, 2017
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_.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 31, 2017
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants