Skip to content

Commit

Permalink
add exclude pattern option
Browse files Browse the repository at this point in the history
  • Loading branch information
nc-annenk committed Feb 1, 2019
1 parent 194a1fa commit 2ef59df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
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]", "run 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
12 changes: 11 additions & 1 deletion lib/parallel_tests/test/runner.rb
Expand Up @@ -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)
end

def all_tests(tests, options)
(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

def exclude_tests(tests_list, options = {})
tests_list.reject { |file| file =~ (options[:exclude_pattern] || //) }
end

def files_in_folder(folder, options={})
pattern = if options[:symlinks] == false # not nil or true
"**/*"
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(["--exclude-pattern", "spec/"])).to eq(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 2ef59df

Please sign in to comment.