Skip to content

Commit

Permalink
Set $? after closing result of IO.popen
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Jul 11, 2024
1 parent 1188773 commit 678df03
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
14 changes: 3 additions & 11 deletions spec/core/io/close_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
end

describe "IO#close on an IO.popen stream" do

it "clears #pid" do
io = IO.popen ruby_cmd('r = loop{puts "y"; 0} rescue 1; exit r'), 'r'

Expand All @@ -103,25 +102,18 @@
io = IO.popen ruby_cmd('exit 0'), 'r'
io.close

NATFIXME 'Handle $? with IO.popen', exception: NoMethodError, message: "undefined method `exitstatus' for nil" do
$?.exitstatus.should == 0
end
$?.exitstatus.should == 0

io = IO.popen ruby_cmd('exit 1'), 'r'
io.close

NATFIXME 'Handle $? with IO.popen', exception: NoMethodError, message: "undefined method `exitstatus' for nil" do
$?.exitstatus.should == 1
end
$?.exitstatus.should == 1
end

it "waits for the child to exit" do
io = IO.popen ruby_cmd('r = loop{puts "y"; 0} rescue 1; exit r'), 'r'
io.close

NATFIXME 'Handle $? with IO.popen', exception: NoMethodError, message: "undefined method `exitstatus' for nil" do
$?.exitstatus.should_not == 0
end
$?.exitstatus.should_not == 0
end

end
8 changes: 2 additions & 6 deletions spec/core/io/popen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
io = IO.popen ruby_cmd('r = loop{puts "y"; 0} rescue 1; exit r'), 'r'
io.close

NATFIXME 'Handle $? with IO.popen', exception: NoMethodError, message: "undefined method `exitstatus' for nil" do
$?.exitstatus.should_not == 0
end
$?.exitstatus.should_not == 0
end

it "writes to a write-only pipe" do
Expand Down Expand Up @@ -70,9 +68,7 @@
@io.write("bar")
@io.close

NATFIXME 'Handle $? with IO.popen', exception: NoMethodError, message: "undefined method `exitstatus' for nil" do
$?.exitstatus.should == 0
end
$?.exitstatus.should == 0

File.read(@fname).should == "bar"
end
Expand Down
1 change: 1 addition & 0 deletions src/io_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ Value IoObject::close(Env *env) {
int result;
if (m_fileptr && m_pid > 0) {
result = pclose2(m_fileptr, m_pid);
set_status_object(env, m_pid, result);
} else {
result = ::close(m_fileno);
}
Expand Down

0 comments on commit 678df03

Please sign in to comment.