1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
require 'test/unit'
require 'test/test_helper'
require 'rbconfig'
class TestProcess < Test::Unit::TestCase
include TestHelper
def setup
@shell = Config::CONFIG['SHELL']
@shellcmd = "#@shell " + (Config::CONFIG['host_os'] =~ /Windows|mswin/ ? "/c" : "-c")
system(%{#@shellcmd "exit 1"})
@first_status = $?
system(%{#@shellcmd "exit 2"})
@second_status = $?
end
def test_process_status_returned_from_dollar_query
assert_kind_of Process::Status, @first_status
assert_kind_of Process::Status, @second_status
end
def test_process_status_to_i
assert_equal 256, @first_status.to_i
assert_equal 512, @second_status.to_i
end
def test_process_status_to_s
assert_equal "256", @first_status.to_s
assert_equal "512", @second_status.to_s
end
def test_process_status_exitstatus
assert_equal 1, @first_status.exitstatus
assert_equal 2, @second_status.exitstatus
end
def test_process_times
tms = nil
assert_nothing_raised {
tms = Process.times
}
assert tms.utime
assert tms.stime
assert tms.cutime
assert tms.cstime
assert tms.utime > 0
end
def test_host_process
unless Config::CONFIG['host_os'] =~ /Windows|mswin/ || !File.exist?("bin/jruby")
assert_equal "1", %x{sh -c 'bin/jruby -e "exit 1" ; echo $?'}.strip
end
end
if (WINDOWS)
def test_gid_windows
assert_equal 0, Process.gid
assert_equal 0, Process.egid
end
# JRUBY-2352
def test_not_implemented_methods_on_windows
# The goal here is to make sure that those "weird"
# POSIX methods don't break JRuby, since there were
# numerous regressions in this area.
assert_raise(NotImplementedError) { Process.uid = 5 }
assert_raise(NotImplementedError) { Process.gid = 5 }
# TODO: JRUBY-2705, doesn't work on x64 JVM
assert_equal 0, Process.euid unless WINDOWS_JVM_64
assert_raise(NotImplementedError) { Process.euid = 5 }
assert_raise(NotImplementedError) { Process.egid = 5 }
assert_raise(NotImplementedError) { Process.getpgid(100) }
assert_raise(NotImplementedError) { Process.setpgid(100, 555) }
assert_raise(NotImplementedError) { Process.setpriority(100, 100, 100) }
assert_raise(NotImplementedError) { Process.getpriority(100, 100) }
assert_raise(NotImplementedError) { Process.setrlimit(100, 100) }
assert_raise(NotImplementedError) { Process.getrlimit(100) }
assert_raise(NotImplementedError) { Process.groups }
assert_raise(NotImplementedError) { Process.groups = [] }
assert_raise(NotImplementedError) { Process.maxgroups }
assert_raise(NotImplementedError) { Process.maxgroups = 100 }
assert_raise(NotImplementedError) { Process.initgroups(100, 100) }
# TODO: JRUBY-2639, doesn't work on x64 JVM
assert_equal 0, Process.ppid unless WINDOWS_JVM_64
# TODO: temporal (JRUBY-2354)
assert_raise(NotImplementedError) { Process.wait }
assert_raise(NotImplementedError) { Process.wait2 }
assert_raise(NotImplementedError) { Process.waitpid }
assert_raise(NotImplementedError) { Process.waitpid2 }
assert_raise(NotImplementedError) { Process.waitall }
end
end
end
|