1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/mkmf.rb (find_executable0): should exclude directories.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-03-11 09:42:46 +00:00
parent 23f2460e82
commit e77a9ad446
3 changed files with 44 additions and 8 deletions

View file

@ -1,3 +1,7 @@
Fri Mar 11 18:42:43 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (find_executable0): should exclude directories.
Fri Mar 11 01:40:35 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* process.c (proc_getmaxgroups, proc_setmaxgroups): Process#maxgroups

View file

@ -1327,11 +1327,20 @@ end
# Internal use only.
#
def find_executable0(bin, path = nil)
executable_file = proc do |name|
begin
stat = File.stat(name)
rescue SystemCallError
else
next name if stat.file? and stat.executable?
end
end
exts = config_string('EXECUTABLE_EXTS') {|s| s.split} || config_string('EXEEXT') {|s| [s]}
if File.expand_path(bin) == bin
return bin if File.executable?(bin)
return bin if executable_file.call(bin)
if exts
exts.each {|ext| File.executable?(file = bin + ext) and return file}
exts.each {|ext| executable_file.call(file = bin + ext) and return file}
end
return nil
end
@ -1342,9 +1351,9 @@ def find_executable0(bin, path = nil)
end
file = nil
path.each do |dir|
return file if File.executable?(file = File.join(dir, bin))
return file if executable_file.call(file = File.join(dir, bin))
if exts
exts.each {|ext| File.executable?(ext = file + ext) and return ext}
exts.each {|ext| executable_file.call(ext = file + ext) and return ext}
end
end
nil

View file

@ -2,10 +2,18 @@ require_relative 'base'
class TestMkmf
class TestFindExecutable < TestMkmf
def setup
super
@path, ENV["PATH"] = ENV["PATH"], @tmpdir
end
def teardown
ENV["PATH"] = @path
super
end
def test_find_executable
bug2669 = '[ruby-core:27912]'
path, ENV["PATH"] = ENV["PATH"], path
ENV["PATH"] = @tmpdir
name = "foobar#{$$}#{rand(1000)}"
exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
stdout.filter {|s| s.sub(name, "<executable>")}
@ -20,8 +28,23 @@ class TestMkmf
end
assert_equal("#{@tmpdir}/#{name}#{ext}", result, bug2669)
end
end
def test_find_executable_dir
name = "foobar#{$$}#{rand(1000)}"
exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
stdout.filter {|s| s.sub(name, "<executable>")}
exts[0] ||= ""
exts.each do |ext|
full = name+ext
begin
Dir.mkdir(full)
result = mkmf {find_executable(name)}
ensure
ENV["PATH"] = path
Dir.rmdir(full)
end
assert_nil(result)
end
end
end
end