2009-04-16 10:17:14 -04:00
|
|
|
require 'test/unit'
|
2013-06-18 00:43:21 -04:00
|
|
|
require 'timeout'
|
2009-04-16 10:17:14 -04:00
|
|
|
require 'tmpdir'
|
|
|
|
|
|
|
|
class TestNotImplement < Test::Unit::TestCase
|
|
|
|
def test_respond_to_fork
|
2011-02-12 09:17:54 -05:00
|
|
|
assert_include(Process.methods, :fork)
|
2009-04-16 10:17:14 -04:00
|
|
|
if /linux/ =~ RUBY_PLATFORM
|
|
|
|
assert_equal(true, Process.respond_to?(:fork))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_respond_to_lchmod
|
2011-02-12 09:17:54 -05:00
|
|
|
assert_include(File.methods, :lchmod)
|
2009-04-16 10:17:14 -04:00
|
|
|
if /linux/ =~ RUBY_PLATFORM
|
|
|
|
assert_equal(false, File.respond_to?(:lchmod))
|
|
|
|
end
|
|
|
|
if /freebsd/ =~ RUBY_PLATFORM
|
|
|
|
assert_equal(true, File.respond_to?(:lchmod))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_call_fork
|
2013-07-10 21:31:23 -04:00
|
|
|
GC.start
|
2013-06-18 00:43:21 -04:00
|
|
|
pid = nil
|
2013-10-12 23:16:50 -04:00
|
|
|
ps =
|
2013-08-14 06:16:33 -04:00
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /linux/ # assume Linux Distribution uses procps
|
2013-10-12 23:16:50 -04:00
|
|
|
proc {`ps -eLf #{pid}`}
|
2013-08-14 06:16:33 -04:00
|
|
|
when /freebsd/
|
2013-10-12 23:16:50 -04:00
|
|
|
proc {`ps -lH #{pid}`}
|
2013-08-14 06:16:33 -04:00
|
|
|
when /darwin/
|
2013-10-12 23:16:50 -04:00
|
|
|
proc {`ps -lM #{pid}`}
|
2013-08-14 06:16:33 -04:00
|
|
|
else
|
2013-10-12 23:16:50 -04:00
|
|
|
proc {`ps -l #{pid}`}
|
2013-08-14 06:16:33 -04:00
|
|
|
end
|
2013-10-12 23:16:50 -04:00
|
|
|
assert_nothing_raised(Timeout::Error, ps) do
|
|
|
|
Timeout.timeout(5) {
|
|
|
|
pid = fork {}
|
|
|
|
Process.wait pid
|
|
|
|
pid = nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
if pid
|
2013-06-27 06:16:17 -04:00
|
|
|
Process.kill(:KILL, pid)
|
2013-06-19 14:04:16 -04:00
|
|
|
Process.wait pid
|
|
|
|
end
|
2013-06-18 00:43:21 -04:00
|
|
|
end if Process.respond_to?(:fork)
|
2009-04-16 10:17:14 -04:00
|
|
|
|
|
|
|
def test_call_lchmod
|
|
|
|
if File.respond_to?(:lchmod)
|
|
|
|
Dir.mktmpdir {|d|
|
|
|
|
f = "#{d}/f"
|
|
|
|
g = "#{d}/g"
|
|
|
|
File.open(f, "w") {}
|
|
|
|
File.symlink f, g
|
|
|
|
newmode = 0444
|
|
|
|
File.lchmod newmode, "#{d}/g"
|
|
|
|
snew = File.lstat(g)
|
|
|
|
assert_equal(newmode, snew.mode & 0777)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_method_inspect_fork
|
|
|
|
m = Process.method(:fork)
|
|
|
|
if Process.respond_to?(:fork)
|
|
|
|
assert_not_match(/not-implemented/, m.inspect)
|
|
|
|
else
|
|
|
|
assert_match(/not-implemented/, m.inspect)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_method_inspect_lchmod
|
|
|
|
m = File.method(:lchmod)
|
|
|
|
if File.respond_to?(:lchmod)
|
|
|
|
assert_not_match(/not-implemented/, m.inspect)
|
|
|
|
else
|
|
|
|
assert_match(/not-implemented/, m.inspect)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|