-
Notifications
You must be signed in to change notification settings - Fork 501
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 exclude pattern option #682
Conversation
lib/parallel_tests/cli.rb
Outdated
@@ -164,6 +164,7 @@ def parse_options!(argv) | |||
BANNER | |||
opts.on("-n [PROCESSES]", Integer, "How many processes to use, default: available CPUs") { |n| options[:count] = n } | |||
opts.on("-p", "--pattern [PATTERN]", "run tests matching this regex pattern") { |pattern| options[:pattern] = /#{pattern}/ } | |||
opts.on("--exclude-pattern", "--exclude-pattern [PATTERN]", "run tests matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ } |
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.
opts.on("--exclude-pattern", "--exclude-pattern [PATTERN]", "run tests matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ } | |
opts.on("--exclude-pattern", "--exclude-pattern [PATTERN]", "run tests not matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ } |
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.
Reworded.
lib/parallel_tests/test/runner.rb
Outdated
@@ -209,16 +209,26 @@ def sort_by_filesize(tests) | |||
end | |||
|
|||
def find_tests(tests, options = {}) | |||
tests_list = all_tests(tests, options) | |||
exclude_tests(tests_list, options) |
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.
this seems asymmetric ... do it at the same place the pattern matching is done ?
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.
Addressed.
lib/parallel_tests/test/runner.rb
Outdated
else | ||
file_or_folder | ||
end | ||
end.flatten.uniq | ||
end | ||
|
||
def exclude_tests(tests_list, options = {}) | ||
tests_list.reject { |file| file =~ (options[:exclude_pattern] || //) } |
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.
//
matches everything- use either reject! or grep since they are more efficient
- do as little work as possible in the inner loop (use local variable and not option lookup)
tests_list.reject { |file| file =~ (options[:exclude_pattern] || //) } | |
if regex = options[:exclude_pattern] | |
tests_list -= tests_list.grep(regex) | |
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.
Addressed. Thanks for the quick feedback!
2ef59df
to
f57719e
Compare
Rakefile
Outdated
@@ -3,5 +3,5 @@ require 'bump/tasks' | |||
require 'bundler/gem_tasks' | |||
|
|||
task :default do | |||
sh "rspec spec/" | |||
system "rspec spec/" |
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.
This need to fail when the command fails, so use sh
lib/parallel_tests/test/runner.rb
Outdated
@@ -208,15 +208,22 @@ def sort_by_filesize(tests) | |||
tests.map! { |test| [test, File.stat(test).size] } | |||
end | |||
|
|||
def find_tests(tests, options = {}) | |||
(tests || []).map do |file_or_folder| | |||
def find_tests(tests = [], options = {}) |
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.
tests
should not have a default value
|
||
if regex = options[:exclude_pattern] | ||
files_list.reject! { |file| file =~ regex } | ||
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.
this is not consistent with how pattern works, it should be done inside so it does not apply to folders
... or both should apply to folders 🤷♂️
... and while your in here: it should use .flat_map
+ [file_or_folder]
and not .flatten
and .uniq!
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.
My assumption would be that anything matching the regex for the include pattern would be included, and the exclude_pattern
will filter out anything matching the exclude pattern. It should apply to folders or files, as the exclude pattern behavior should mirror the behavior of native rspec --exclude-pattern
option.
4e5b3e3
to
0dd7821
Compare
0dd7821
to
4826f07
Compare
@grosser Thanks for merging! Is there anything I need to do to get a new gem version out? |
no, I'm just waiting for my cleanup PR to go green and will then release |
v2.28.0 |
Awesome. Thanks a ton! Hopefully this will help others as well.
…On Thu, Feb 7, 2019 at 12:46 PM Michael Grosser ***@***.***> wrote:
v2.28.0
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#682 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AsNR3ix4I-RvcYBrJXW0FHDHXi5pm56qks5vLHRogaJpZM4aesUT>
.
--
This email and its attachments are confidential and may be privileged. Any
unauthorized use or disclosure is prohibited. If you receive this email in
error, please notify the sender and permanently delete the original without
forwarding, making any copies or disclosing its contents. NextCapital is a
brand name representing NextCapital Group, Inc. and its subsidiaries,
NextCapital Software, Inc. and NextCapital Advisers, Inc.
|
Add the ability to pass
--exclude-pattern
fixes #647
fixes #573