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