diff options
Diffstat (limited to 'spec/ruby/core/process/status')
| -rw-r--r-- | spec/ruby/core/process/status/bit_and_spec.rb | 38 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/coredump_spec.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/equal_value_spec.rb | 15 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/exited_spec.rb | 32 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/exitstatus_spec.rb | 25 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/inspect_spec.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/pid_spec.rb | 15 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/right_shift_spec.rb | 37 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/signaled_spec.rb | 31 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/stopped_spec.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/stopsig_spec.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/success_spec.rb | 41 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/termsig_spec.rb | 43 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/to_i_spec.rb | 13 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/to_int_spec.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/to_s_spec.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/wait_spec.rb | 100 |
17 files changed, 420 insertions, 0 deletions
diff --git a/spec/ruby/core/process/status/bit_and_spec.rb b/spec/ruby/core/process/status/bit_and_spec.rb new file mode 100644 index 0000000000..a5b1123e90 --- /dev/null +++ b/spec/ruby/core/process/status/bit_and_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../../spec_helper' + +ruby_version_is ""..."4.0" do + + describe "Process::Status#&" do + it "returns a bitwise and of the integer status of an exited child" do + suppress_warning do + ruby_exe("exit(29)", exit_status: 29) + ($? & 0).should == 0 + ($? & $?.to_i).should == $?.to_i + + # Actual value is implementation specific + platform_is :linux do + # 29 == 0b11101 + ($? & 0b1011100000000).should == 0b1010100000000 + end + end + end + + ruby_version_is ""..."4.0" do + it "raises an ArgumentError if mask is negative" do + suppress_warning do + ruby_exe("exit(0)") + -> { + $? & -1 + }.should.raise(ArgumentError, 'negative mask value: -1') + end + end + + it "shows a deprecation warning" do + ruby_exe("exit(0)") + -> { + $? & 0 + }.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/) + end + end + end +end diff --git a/spec/ruby/core/process/status/coredump_spec.rb b/spec/ruby/core/process/status/coredump_spec.rb new file mode 100644 index 0000000000..fbbaf926f7 --- /dev/null +++ b/spec/ruby/core/process/status/coredump_spec.rb @@ -0,0 +1,5 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#coredump?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/core/process/status/equal_value_spec.rb b/spec/ruby/core/process/status/equal_value_spec.rb new file mode 100644 index 0000000000..d8a2be26b8 --- /dev/null +++ b/spec/ruby/core/process/status/equal_value_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#==" do + it "returns true when compared to the integer status of an exited child" do + ruby_exe("exit(29)", exit_status: 29) + $?.to_i.should == $? + $?.should == $?.to_i + end + + it "returns true when compared to the integer status of a terminated child" do + ruby_exe("Process.kill(:KILL, $$); exit(29)", exit_status: platform_is(:windows) ? 0 : :SIGKILL) + $?.to_i.should == $? + $?.should == $?.to_i + end +end diff --git a/spec/ruby/core/process/status/exited_spec.rb b/spec/ruby/core/process/status/exited_spec.rb new file mode 100644 index 0000000000..ad14b35000 --- /dev/null +++ b/spec/ruby/core/process/status/exited_spec.rb @@ -0,0 +1,32 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#exited?" do + describe "for a child that exited normally" do + before :each do + ruby_exe("exit(0)") + end + + it "returns true" do + $?.exited?.should == true + end + end + + + describe "for a terminated child" do + before :each do + ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL) + end + + platform_is_not :windows do + it "returns false" do + $?.exited?.should == false + end + end + + platform_is :windows do + it "always returns true" do + $?.exited?.should == true + end + end + end +end diff --git a/spec/ruby/core/process/status/exitstatus_spec.rb b/spec/ruby/core/process/status/exitstatus_spec.rb new file mode 100644 index 0000000000..5c86c2b3c8 --- /dev/null +++ b/spec/ruby/core/process/status/exitstatus_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#exitstatus" do + before :each do + ruby_exe("exit(42)", exit_status: 42) + end + + it "returns the process exit code" do + $?.exitstatus.should == 42 + end + + describe "for a child that raised SignalException" do + before :each do + ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL) + end + + platform_is_not :windows do + # The exitstatus is not set in these cases. See the termsig_spec + # for info on where the signal number (SIGTERM) is available. + it "returns nil" do + $?.exitstatus.should == nil + end + end + end +end diff --git a/spec/ruby/core/process/status/inspect_spec.rb b/spec/ruby/core/process/status/inspect_spec.rb new file mode 100644 index 0000000000..03f0479f2c --- /dev/null +++ b/spec/ruby/core/process/status/inspect_spec.rb @@ -0,0 +1,5 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#inspect" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/core/process/status/pid_spec.rb b/spec/ruby/core/process/status/pid_spec.rb new file mode 100644 index 0000000000..9965fc3bdf --- /dev/null +++ b/spec/ruby/core/process/status/pid_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../../spec_helper' + +platform_is_not :windows do + describe "Process::Status#pid" do + + before :each do + @pid = ruby_exe("print $$").to_i + end + + it "returns the pid of the process" do + $?.pid.should == @pid + end + + end +end diff --git a/spec/ruby/core/process/status/right_shift_spec.rb b/spec/ruby/core/process/status/right_shift_spec.rb new file mode 100644 index 0000000000..5689526f54 --- /dev/null +++ b/spec/ruby/core/process/status/right_shift_spec.rb @@ -0,0 +1,37 @@ +require_relative '../../../spec_helper' + +ruby_version_is ""..."4.0" do + + describe "Process::Status#>>" do + it "returns a right shift of the integer status of an exited child" do + suppress_warning do + ruby_exe("exit(29)", exit_status: 29) + ($? >> 0).should == $?.to_i + ($? >> 1).should == $?.to_i >> 1 + + # Actual value is implementation specific + platform_is :linux do + ($? >> 8).should == 29 + end + end + end + + ruby_version_is ""..."4.0" do + it "raises an ArgumentError if shift value is negative" do + suppress_warning do + ruby_exe("exit(0)") + -> { + $? >> -1 + }.should.raise(ArgumentError, 'negative shift value: -1') + end + end + + it "shows a deprecation warning" do + ruby_exe("exit(0)") + -> { + $? >> 0 + }.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/) + end + end + end +end diff --git a/spec/ruby/core/process/status/signaled_spec.rb b/spec/ruby/core/process/status/signaled_spec.rb new file mode 100644 index 0000000000..8cf409bb42 --- /dev/null +++ b/spec/ruby/core/process/status/signaled_spec.rb @@ -0,0 +1,31 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#signaled?" do + describe "for a cleanly exited child" do + before :each do + ruby_exe("exit(0)") + end + + it "returns false" do + $?.signaled?.should == false + end + end + + describe "for a terminated child" do + before :each do + ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL) + end + + platform_is_not :windows do + it "returns true" do + $?.signaled?.should == true + end + end + + platform_is :windows do + it "always returns false" do + $?.signaled?.should == false + end + end + end +end diff --git a/spec/ruby/core/process/status/stopped_spec.rb b/spec/ruby/core/process/status/stopped_spec.rb new file mode 100644 index 0000000000..bebd441d6f --- /dev/null +++ b/spec/ruby/core/process/status/stopped_spec.rb @@ -0,0 +1,5 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#stopped?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/core/process/status/stopsig_spec.rb b/spec/ruby/core/process/status/stopsig_spec.rb new file mode 100644 index 0000000000..b2a7c5d9e2 --- /dev/null +++ b/spec/ruby/core/process/status/stopsig_spec.rb @@ -0,0 +1,5 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#stopsig" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/core/process/status/success_spec.rb b/spec/ruby/core/process/status/success_spec.rb new file mode 100644 index 0000000000..f61243c667 --- /dev/null +++ b/spec/ruby/core/process/status/success_spec.rb @@ -0,0 +1,41 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#success?" do + describe "for a child that exited normally" do + before :each do + ruby_exe("exit(0)") + end + + it "returns true" do + $?.success?.should == true + end + end + + describe "for a child that exited with a non zero status" do + before :each do + ruby_exe("exit(42)", exit_status: 42) + end + + it "returns false" do + $?.success?.should == false + end + end + + describe "for a child that was terminated" do + before :each do + ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL) + end + + platform_is_not :windows do + it "returns nil" do + $?.success?.should == nil + end + end + + platform_is :windows do + it "always returns true" do + $?.success?.should == true + end + end + end +end diff --git a/spec/ruby/core/process/status/termsig_spec.rb b/spec/ruby/core/process/status/termsig_spec.rb new file mode 100644 index 0000000000..1d57724d12 --- /dev/null +++ b/spec/ruby/core/process/status/termsig_spec.rb @@ -0,0 +1,43 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#termsig" do + describe "for a child that exited normally" do + before :each do + ruby_exe("exit(0)") + end + + it "returns nil" do + $?.termsig.should == nil + end + end + + describe "for a child that raised SignalException" do + before :each do + ruby_exe("raise SignalException, 'SIGTERM'", exit_status: :SIGTERM) + end + + platform_is_not :windows do + it "returns the signal" do + $?.termsig.should == Signal.list["TERM"] + end + end + end + + describe "for a child that was sent a signal" do + before :each do + ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL) + end + + platform_is_not :windows do + it "returns the signal" do + $?.termsig.should == Signal.list["KILL"] + end + end + + platform_is :windows do + it "always returns nil" do + $?.termsig.should == nil + end + end + end +end diff --git a/spec/ruby/core/process/status/to_i_spec.rb b/spec/ruby/core/process/status/to_i_spec.rb new file mode 100644 index 0000000000..0bfb883d23 --- /dev/null +++ b/spec/ruby/core/process/status/to_i_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#to_i" do + it "returns an integer when the child exits" do + ruby_exe('exit 48', exit_status: 48) + $?.to_i.should.instance_of?(Integer) + end + + it "returns an integer when the child is signaled" do + ruby_exe('raise SignalException, "TERM"', exit_status: platform_is(:windows) ? 3 : :SIGTERM) + $?.to_i.should.instance_of?(Integer) + end +end diff --git a/spec/ruby/core/process/status/to_int_spec.rb b/spec/ruby/core/process/status/to_int_spec.rb new file mode 100644 index 0000000000..fb596c1bfb --- /dev/null +++ b/spec/ruby/core/process/status/to_int_spec.rb @@ -0,0 +1,5 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#to_int" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/core/process/status/to_s_spec.rb b/spec/ruby/core/process/status/to_s_spec.rb new file mode 100644 index 0000000000..5c0d4cd30c --- /dev/null +++ b/spec/ruby/core/process/status/to_s_spec.rb @@ -0,0 +1,5 @@ +require_relative '../../../spec_helper' + +describe "Process::Status#to_s" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/core/process/status/wait_spec.rb b/spec/ruby/core/process/status/wait_spec.rb new file mode 100644 index 0000000000..18ecc14f6f --- /dev/null +++ b/spec/ruby/core/process/status/wait_spec.rb @@ -0,0 +1,100 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/common' + +describe "Process::Status.wait" do + ProcessSpecs.use_system_ruby(self) + + before :all do + begin + leaked = Process.waitall + # Ruby-space should not see PIDs used by rjit + raise "subprocesses leaked before wait specs: #{leaked}" unless leaked.empty? + rescue NotImplementedError + end + end + + it "returns a status with pid -1 if there are no child processes" do + Process::Status.wait.pid.should == -1 + end + + platform_is_not :windows do + it "returns a status with its child pid" do + pid = Process.spawn(ruby_cmd('exit')) + status = Process::Status.wait + status.should.instance_of?(Process::Status) + status.pid.should == pid + end + + it "should not set $? to the Process::Status" do + pid = Process.spawn(ruby_cmd('exit')) + status = Process::Status.wait + $?.should_not.equal?(status) + end + + it "should not change the value of $?" do + pid = Process.spawn(ruby_cmd('exit')) + Process.wait + status = $? + Process::Status.wait + status.should.equal?($?) + end + + it "waits for any child process if no pid is given" do + pid = Process.spawn(ruby_cmd('exit')) + Process::Status.wait.pid.should == pid + -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH) + end + + it "waits for a specific child if a pid is given" do + pid1 = Process.spawn(ruby_cmd('exit')) + pid2 = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(pid2).pid.should == pid2 + Process::Status.wait(pid1).pid.should == pid1 + -> { Process.kill(0, pid1) }.should.raise(Errno::ESRCH) + -> { Process.kill(0, pid2) }.should.raise(Errno::ESRCH) + end + + it "coerces the pid to an Integer" do + pid1 = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(mock_int(pid1)).pid.should == pid1 + -> { Process.kill(0, pid1) }.should.raise(Errno::ESRCH) + end + + # This spec is probably system-dependent. + it "waits for a child whose process group ID is that of the calling process" do + pid1 = Process.spawn(ruby_cmd('exit'), pgroup: true) + pid2 = Process.spawn(ruby_cmd('exit')) + + Process::Status.wait(0).pid.should == pid2 + Process::Status.wait.pid.should == pid1 + end + + # This spec is probably system-dependent. + it "doesn't block if no child is available when WNOHANG is used" do + read, write = IO.pipe + pid = Process.fork do + read.close + Signal.trap("TERM") { Process.exit! } + write << 1 + write.close + sleep + end + + Process::Status.wait(pid, Process::WNOHANG).should == nil + + # wait for the child to setup its TERM handler + write.close + read.read(1) + read.close + + Process.kill("TERM", pid) + Process::Status.wait.pid.should == pid + end + + it "always accepts flags=0" do + pid = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(-1, 0).pid.should == pid + -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH) + end + end +end |
