Skip to content

Commit

Permalink
Merge pull request #682 from nc-annenk/add-exclude-pattern-option
Browse files Browse the repository at this point in the history
add exclude pattern option
  • Loading branch information
grosser committed Feb 7, 2019
2 parents 194a1fa + 4826f07 commit 4f0b5ee
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
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

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

0 comments on commit 4f0b5ee

Please sign in to comment.