From f150d67b7d389eb88e0cd13694d3529895d55579 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 11 Jan 2025 15:30:06 +0900 Subject: merge revision(s) 8034e9c3d001ca3dff124ab42972684eac8af2ae: [Backport #20995] [Bug #20995] Protect `IO.popen` block from exiting by exception --- test/ruby/test_process.rb | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 07407a7d2f..f48c4982c2 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -905,15 +905,29 @@ class TestProcess < Test::Unit::TestCase } end - def test_popen_fork - IO.popen("-") {|io| - if !io - puts "fooo" - else - assert_equal("fooo\n", io.read) + if Process.respond_to?(:fork) + def test_popen_fork + IO.popen("-") do |io| + if !io + puts "fooo" + else + assert_equal("fooo\n", io.read) + end end - } - rescue NotImplementedError + end + + def test_popen_fork_ensure + IO.popen("-") do |io| + if !io + STDERR.reopen(STDOUT) + raise "fooo" + else + assert_empty io.read + end + end + rescue RuntimeError + abort "[Bug #20995] should not reach here" + end end def test_fd_inheritance -- cgit v1.2.3