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

cleanup pattern matching #683

Merged
merged 1 commit into from Feb 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions lib/parallel_tests/test/runner.rb
Expand Up @@ -209,23 +209,20 @@ def sort_by_filesize(tests)
end

def find_tests(tests, options = {})
files_list = (tests || []).map do |file_or_folder|
suffix_pattern = options[:suffix] || test_suffix
include_pattern = options[:pattern] || //
exclude_pattern = options[:exclude_pattern]

(tests || []).flat_map do |file_or_folder|
if File.directory?(file_or_folder)
files = files_in_folder(file_or_folder, options)
files.grep(options[:suffix] || test_suffix)
.grep(options[:pattern] || //)
files = files.grep(suffix_pattern).grep(include_pattern)
files -= files.grep(exclude_pattern) if exclude_pattern
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving the filtering of the exclusion into this block means folders are not filtered out. If the goal is to mirror the functionality of rspec --pattern and `--exclude-pattern, wouldn't the folder need to have the regexes applied as well?

Copy link
Owner Author

Choose a reason for hiding this comment

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

it means files that are explicitly added are not affected by filters
folders are still effected since they are covered to files and then matched against

files
else
file_or_folder
end
end

flat_files_list = files_list.uniq.flat_map { |i| i }

if regex = options[:exclude_pattern]
flat_files_list.reject! { |file| file =~ regex }
end

flat_files_list
end.uniq
end

def files_in_folder(folder, options={})
Expand Down