diff options
Diffstat (limited to 'spec/ruby/core/process/status')
| -rw-r--r-- | spec/ruby/core/process/status/bit_and_spec.rb | 37 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/exited_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/right_shift_spec.rb | 36 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/signaled_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/success_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/termsig_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/to_i_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/process/status/wait_spec.rb | 158 |
8 files changed, 162 insertions, 99 deletions
diff --git a/spec/ruby/core/process/status/bit_and_spec.rb b/spec/ruby/core/process/status/bit_and_spec.rb index 97f768fdc1..a5b1123e90 100644 --- a/spec/ruby/core/process/status/bit_and_spec.rb +++ b/spec/ruby/core/process/status/bit_and_spec.rb @@ -1,5 +1,38 @@ require_relative '../../../spec_helper' -describe "Process::Status#&" do - it "needs to be reviewed for spec completeness" +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/exited_spec.rb b/spec/ruby/core/process/status/exited_spec.rb index a61292b146..ad14b35000 100644 --- a/spec/ruby/core/process/status/exited_spec.rb +++ b/spec/ruby/core/process/status/exited_spec.rb @@ -7,7 +7,7 @@ describe "Process::Status#exited?" do end it "returns true" do - $?.exited?.should be_true + $?.exited?.should == true end end @@ -19,13 +19,13 @@ describe "Process::Status#exited?" do platform_is_not :windows do it "returns false" do - $?.exited?.should be_false + $?.exited?.should == false end end platform_is :windows do it "always returns true" do - $?.exited?.should be_true + $?.exited?.should == true 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 index e9dda437e8..5689526f54 100644 --- a/spec/ruby/core/process/status/right_shift_spec.rb +++ b/spec/ruby/core/process/status/right_shift_spec.rb @@ -1,5 +1,37 @@ require_relative '../../../spec_helper' -describe "Process::Status#>>" do - it "needs to be reviewed for spec completeness" +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 index c0de7b8006..8cf409bb42 100644 --- a/spec/ruby/core/process/status/signaled_spec.rb +++ b/spec/ruby/core/process/status/signaled_spec.rb @@ -7,7 +7,7 @@ describe "Process::Status#signaled?" do end it "returns false" do - $?.signaled?.should be_false + $?.signaled?.should == false end end @@ -18,13 +18,13 @@ describe "Process::Status#signaled?" do platform_is_not :windows do it "returns true" do - $?.signaled?.should be_true + $?.signaled?.should == true end end platform_is :windows do it "always returns false" do - $?.signaled?.should be_false + $?.signaled?.should == false end end end diff --git a/spec/ruby/core/process/status/success_spec.rb b/spec/ruby/core/process/status/success_spec.rb index 3589cc611f..f61243c667 100644 --- a/spec/ruby/core/process/status/success_spec.rb +++ b/spec/ruby/core/process/status/success_spec.rb @@ -7,7 +7,7 @@ describe "Process::Status#success?" do end it "returns true" do - $?.success?.should be_true + $?.success?.should == true end end @@ -17,7 +17,7 @@ describe "Process::Status#success?" do end it "returns false" do - $?.success?.should be_false + $?.success?.should == false end end @@ -28,13 +28,13 @@ describe "Process::Status#success?" do platform_is_not :windows do it "returns nil" do - $?.success?.should be_nil + $?.success?.should == nil end end platform_is :windows do it "always returns true" do - $?.success?.should be_true + $?.success?.should == true end end end diff --git a/spec/ruby/core/process/status/termsig_spec.rb b/spec/ruby/core/process/status/termsig_spec.rb index 5d286950f8..1d57724d12 100644 --- a/spec/ruby/core/process/status/termsig_spec.rb +++ b/spec/ruby/core/process/status/termsig_spec.rb @@ -6,8 +6,8 @@ describe "Process::Status#termsig" do ruby_exe("exit(0)") end - it "returns true" do - $?.termsig.should be_nil + it "returns nil" do + $?.termsig.should == nil end end @@ -36,7 +36,7 @@ describe "Process::Status#termsig" do platform_is :windows do it "always returns nil" do - $?.termsig.should be_nil + $?.termsig.should == nil 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 index 39f8e2d84c..0bfb883d23 100644 --- a/spec/ruby/core/process/status/to_i_spec.rb +++ b/spec/ruby/core/process/status/to_i_spec.rb @@ -3,11 +3,11 @@ 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 be_an_instance_of(Integer) + $?.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 be_an_instance_of(Integer) + $?.to_i.should.instance_of?(Integer) end end diff --git a/spec/ruby/core/process/status/wait_spec.rb b/spec/ruby/core/process/status/wait_spec.rb index b9d80e31f4..18ecc14f6f 100644 --- a/spec/ruby/core/process/status/wait_spec.rb +++ b/spec/ruby/core/process/status/wait_spec.rb @@ -1,102 +1,100 @@ require_relative '../../../spec_helper' require_relative '../fixtures/common' -ruby_version_is "3.0" do - 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 mjit - raise "subprocesses leaked before wait specs: #{leaked}" unless leaked.empty? - rescue NotImplementedError - end +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 - it "returns a status with pid -1 if there are no child processes" do - Process::Status.wait.pid.should == -1 + 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 - 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 be_an_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 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 "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 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_error(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 "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_error(Errno::ESRCH) - -> { Process.kill(0, pid2) }.should raise_error(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 - 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_error(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')) - # 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 - Process::Status.wait(0).pid.should == pid2 - Process::Status.wait.pid.should == pid1 + # 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 - # 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 - Process::Status.wait(pid, Process::WNOHANG).should be_nil + # wait for the child to setup its TERM handler + write.close + read.read(1) + read.close - # 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 + 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_error(Errno::ESRCH) - 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 |
