diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 18:01:20 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 18:01:20 -0800 |
| commit | b65cea74295358265dfabc9e1f4d107b21e58e58 (patch) | |
| tree | 656df06ac507ed32ca56c425adffa34a3c65c60e /test/ruby/test_process.rb | |
| parent | c989d90754edeefa4e692d2cd8c351394cb217e7 (diff) | |
merge revision(s) 8034e9c3d001ca3dff124ab42972684eac8af2ae: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
Diffstat (limited to 'test/ruby/test_process.rb')
| -rw-r--r-- | test/ruby/test_process.rb | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 6e8ba484a4..af72053234 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -922,15 +922,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 |
