Skip to content

Commit

Permalink
complement '.rb' on test-all TESTS=test_xxx
Browse files Browse the repository at this point in the history
for test-all rule, we can specify a file with TESTS option like
`TESTS=test_xxx.rb`. However, we can eliminate last '.rb' suffix
so this patch try with '.rb' suffix if the given path is not available.
  • Loading branch information
ko1 committed Jul 14, 2019
1 parent b67b07b commit 47e571c
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions tool/lib/test/unit.rb
Expand Up @@ -871,31 +871,41 @@ def non_options(files, options)
end
files.map! {|f|
f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
((paths if /\A\.\.?(?:\z|\/)/ !~ f) || [nil]).any? do |prefix|
if prefix
path = f.empty? ? prefix : "#{prefix}/#{f}"
else
next if f.empty?
path = f
end
if f.end_with?(File::SEPARATOR) or !f.include?(File::SEPARATOR) or File.directory?(path)
match = (Dir["#{path}/**/#{@@testfile_prefix}_*.rb"] + Dir["#{path}/**/*_#{@@testfile_suffix}.rb"]).uniq
else
match = Dir[path]
while true
ret = ((paths if /\A\.\.?(?:\z|\/)/ !~ f) || [nil]).any? do |prefix|
if prefix
path = f.empty? ? prefix : "#{prefix}/#{f}"
else
next if f.empty?
path = f
end
if f.end_with?(File::SEPARATOR) or !f.include?(File::SEPARATOR) or File.directory?(path)
match = (Dir["#{path}/**/#{@@testfile_prefix}_*.rb"] + Dir["#{path}/**/*_#{@@testfile_suffix}.rb"]).uniq
else
match = Dir[path]
end
if !match.empty?
if reject
match.reject! {|n|
n = n[(prefix.length+1)..-1] if prefix
reject_pat =~ n
}
end
break match
elsif !reject or reject_pat !~ f and File.exist? path
break path
end
end
if !match.empty?
if reject
match.reject! {|n|
n = n[(prefix.length+1)..-1] if prefix
reject_pat =~ n
}
if !ret
if /\.rb\z/ =~ f
raise ArgumentError, "file not found: #{f}"
else
f = "#{f}.rb"
end
break match
elsif !reject or reject_pat !~ f and File.exist? path
break path
else
break ret
end
end or
raise ArgumentError, "file not found: #{f}"
end
}
files.flatten!
super(files, options)
Expand Down

0 comments on commit 47e571c

Please sign in to comment.