Skip to content

Commit

Permalink
Merge pull request #548 from modcloth/mbh/backtick-process-status
Browse files Browse the repository at this point in the history
Kernel#` sets $?
  • Loading branch information
alex committed Mar 27, 2013
2 parents 1d2d23f + ac6f2b0 commit 12e3f07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib-topaz/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ def loop
def `(cmd)
cmd = cmd.to_str if cmd.respond_to?(:to_str)
raise TypeError.new("can't convert #{cmd.class} into String") unless cmd.is_a?(String)
IO.popen(cmd) { |r| r.read }
res = ''
IO.popen(cmd) do |r|
res << r.read
Process.waitpid(r.pid)
end
res
end

def to_enum(method = :each, *args)
Expand Down
6 changes: 6 additions & 0 deletions lib-topaz/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def initialize(pid, exitstatus)
@exitstatus = exitstatus
end

def success?
@exitstatus == 0
end

alias exited? success?

def pid
@pid
end
Expand Down
8 changes: 8 additions & 0 deletions tests/modules/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ def test_backtick(self, space):
w_res = space.execute("return `echo 10`")
assert self.unwrap(space, w_res) == "10\n"

def test_backtick_sets_process_status(self, space):
w_res = space.execute("""
$? = nil
`echo`
return $?.class.name
""")
assert self.unwrap(space, w_res) == "Process::Status"


class TestRequire(BaseTopazTest):
def test_simple(self, space, tmpdir):
Expand Down

0 comments on commit 12e3f07

Please sign in to comment.