diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2025-01-14 17:59:12 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-01-14 17:59:12 -0800 |
| commit | 12a0807965624a0be37dc79371a69b5d787cc8d1 (patch) | |
| tree | ab1d227edb33d192c8872992bb0309fc741e917f /test | |
| parent | 0d6459249d13e247cd0eae28f59ef51b862bce80 (diff) | |
merge revision(s) 8034e9c3d001ca3dff124ab42972684eac8af2ae: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
Diffstat (limited to 'test')
| -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 d9804aaa57..ffcca99eb3 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -923,15 +923,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 |
