diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-01-02 15:50:20 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-01-02 15:50:20 +0900 |
| commit | 8034e9c3d001ca3dff124ab42972684eac8af2ae (patch) | |
| tree | 07d9f6de5837fe14973e73cf24deda966f913cd5 /test | |
| parent | 6cf11ad76eae08ba9d2bdc70c093bc67aca93864 (diff) | |
[Bug #20995] Protect `IO.popen` block from exiting by exception
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12497
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 7057e0b837..9c1836dffb 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 |
