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 exclude pattern option #682

Merged
merged 1 commit into from Feb 7, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -195,6 +195,7 @@ Options are:

-n [PROCESSES] How many processes to use, default: available CPUs
-p, --pattern [PATTERN] run tests matching this regex pattern
--exclude-pattern [PATTERN] exclude tests matching this regex pattern
--group-by [TYPE] group tests by:
found - order of finding files
steps - number of cucumber/spinach steps
Expand Down
1 change: 1 addition & 0 deletions lib/parallel_tests/cli.rb
Expand Up @@ -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]", "exclude tests matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ }
opts.on("--group-by [TYPE]", <<-TEXT.gsub(/^ /, '')
group tests by:
found - order of finding files
Expand Down
15 changes: 12 additions & 3 deletions lib/parallel_tests/test/runner.rb
Expand Up @@ -209,14 +209,23 @@ def sort_by_filesize(tests)
end

def find_tests(tests, options = {})
(tests || []).map do |file_or_folder|
files_list = (tests || []).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.grep(options[:suffix] || test_suffix)
.grep(options[:pattern] || //)
else
file_or_folder
end
end.flatten.uniq
end

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

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

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!

Copy link
Contributor Author

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.


flat_files_list
end

def files_in_folder(folder, options={})
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/rails51/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ../../..
specs:
parallel_tests (2.26.0)
parallel_tests (2.27.1)
parallel

GEM
Expand Down Expand Up @@ -65,7 +65,7 @@ GEM
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.12.1)
parallel (1.13.0)
rack (2.0.5)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/rails52/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ../../..
specs:
parallel_tests (2.26.0)
parallel_tests (2.27.1)
parallel

GEM
Expand Down Expand Up @@ -72,7 +72,7 @@ GEM
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.12.1)
parallel (1.13.0)
rack (2.0.5)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down
10 changes: 10 additions & 0 deletions spec/integration_spec.rb
Expand Up @@ -287,6 +287,16 @@ def test_unicode
expect(result).to include('ZZZ')
end

it "excludes test by given pattern and relative paths" do
write "spec/x_spec.rb", "puts 'XXX'"
write "spec/acceptance/y_spec.rb", "puts 'YYY'"
write "spec/integration/z_spec.rb", "puts 'ZZZ'"
result = run_tests "spec", :add => "--exclude-pattern 'spec/(integration|acceptance)'", :type => "rspec"
expect(result).to include('XXX')
expect(result).not_to include('YYY')
expect(result).not_to include('ZZZ')
end

it "can wait_for_other_processes_to_finish" do
skip if RUBY_PLATFORM == "java" # just too slow ...
write "test/a_test.rb", "require 'parallel_tests'; sleep 0.5 ; ParallelTests.wait_for_other_processes_to_finish; puts 'OutputA'"
Expand Down
4 changes: 4 additions & 0 deletions spec/parallel_tests/cli_spec.rb
Expand Up @@ -21,6 +21,10 @@ def call(*args)
expect(call(["--exec", "echo"])).to eq(execute: "echo")
end

it "parses excludes pattern" do
expect(call(["test", "--exclude-pattern", "spec/"])).to eq(defaults.merge(:exclude_pattern => /spec\//))
end

it "parses regular count" do
expect(call(["test", "-n3"])).to eq(defaults.merge(:count => 3))
end
Expand Down