Skip to content

Commit

Permalink
Merge pull request #3270 from rubinius/process-initialize
Browse files Browse the repository at this point in the history
Changes to make Process::Status compatible with MRI
  • Loading branch information
brixen committed Jan 7, 2015
2 parents a360a9e + 9e6a904 commit 56274d3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
23 changes: 13 additions & 10 deletions kernel/common/process.rb
Expand Up @@ -522,44 +522,47 @@ def self.coerce_rlimit_resource(resource)

class Status

attr_reader :exitstatus
attr_reader :termsig
attr_reader :stopsig

def initialize(pid, exitstatus, termsig=nil, stopsig=nil)
def initialize(pid=nil, status=nil, termsig=nil, stopsig=nil)
@pid = pid
@exitstatus = exitstatus
@status = status
@termsig = termsig
@stopsig = stopsig
end

def exitstatus
@status
end

def to_i
@exitstatus
@status
end

def to_s
@exitstatus.to_s
@status.to_s
end

def &(num)
@exitstatus & num
@status & num
end

def ==(other)
other = other.to_i if other.kind_of? Process::Status
@exitstatus == other
@status == other
end

def >>(num)
@exitstatus >> num
@status >> num
end

def coredump?
false
end

def exited?
@exitstatus != nil
@status != nil
end

def pid
Expand All @@ -576,7 +579,7 @@ def stopped?

def success?
if exited?
@exitstatus == 0
@status == 0
else
nil
end
Expand Down
7 changes: 7 additions & 0 deletions spec/ruby/core/process/exitstatus_spec.rb
@@ -0,0 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe 'Process::Status#exitstatus' do
it 'returns the exit status as a Fixnum' do
Process::Status.new(42, 1).exitstatus.should == 1
end
end
31 changes: 31 additions & 0 deletions spec/ruby/core/process/initialize_spec.rb
@@ -0,0 +1,31 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe 'Process::Status#initialize' do
it 'initializes a new Process::Status instance' do
Process::Status.new.should be_an_instance_of(Process::Status)
end

it 'initializes Process::Status with a PID' do
status = Process::Status.new(42)

status.pid.should == 42
end

it 'initializes Process::Status with a PID and status' do
status = Process::Status.new(42, 1)

status.exitstatus.should == 1
end

it 'initializes Process::Status with a PID, status and term signal' do
status = Process::Status.new(42, 1, 2)

status.termsig.should == 2
end

it 'initializes Process::Status with a PID, status, term signal and stop signal' do
status = Process::Status.new(42, 1, 2, 3)

status.stopsig.should == 3
end
end

0 comments on commit 56274d3

Please sign in to comment.