diff options
author | Mike Dalessio <[email protected]> | 2023-06-07 10:05:04 -0400 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-08-10 09:38:11 +0900 |
commit | d2343368ab7e270118ea6baa9c6418bfed83135c (patch) | |
tree | 0e25287d42464b9812033f613234f3baa11c5517 /test/ruby/test_io.rb | |
parent | 984109b8363790723693ec04897b1155d899115f (diff) |
Deprecate Kernel#open and IO support for subprocess creation/forking
Deprecate Kernel#open and IO support for subprocess creation and
forking. This deprecates subprocess creation and forking in
- Kernel#open
- URI.open
- IO.binread
- IO.foreach
- IO.readlines
- IO.read
- IO.write
This behavior is slated to be removed in Ruby 4.0
[Feature #19630]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7915
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r-- | test/ruby/test_io.rb | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index aad1530588..7689b52e23 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2412,15 +2412,19 @@ class TestIO < Test::Unit::TestCase end def test_open_pipe - open("|" + EnvUtil.rubybin, "r+") do |f| - f.puts "puts 'foo'" - f.close_write - assert_equal("foo\n", f.read) + assert_deprecated_warning(/Kernel#open with a leading '\|'/) do # https://bugs.ruby-lang.org/issues/19630 + open("|" + EnvUtil.rubybin, "r+") do |f| + f.puts "puts 'foo'" + f.close_write + assert_equal("foo\n", f.read) + end end end def test_read_command - assert_equal("foo\n", IO.read("|echo foo")) + assert_deprecated_warning(/IO process creation with a leading '\|'/) do # https://bugs.ruby-lang.org/issues/19630 + assert_equal("foo\n", IO.read("|echo foo")) + end assert_raise(Errno::ENOENT, Errno::EINVAL) do File.read("|#{EnvUtil.rubybin} -e puts") end @@ -2434,7 +2438,9 @@ class TestIO < Test::Unit::TestCase Class.new(IO).binread("|#{EnvUtil.rubybin} -e puts") end assert_raise(Errno::ESPIPE) do - IO.read("|echo foo", 1, 1) + assert_deprecated_warning(/IO process creation with a leading '\|'/) do # https://bugs.ruby-lang.org/issues/19630 + IO.read("|echo foo", 1, 1) + end end end @@ -2619,11 +2625,16 @@ class TestIO < Test::Unit::TestCase def test_foreach a = [] - IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x } + + assert_deprecated_warning(/IO process creation with a leading '\|'/) do # https://bugs.ruby-lang.org/issues/19630 + IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x } + end assert_equal(["foo\n", "bar\n", "baz\n"], a) a = [] - IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :zot'", :open_args => ["r"]) {|x| a << x } + assert_deprecated_warning(/IO process creation with a leading '\|'/) do # https://bugs.ruby-lang.org/issues/19630 + IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :zot'", :open_args => ["r"]) {|x| a << x } + end assert_equal(["zot\n"], a) make_tempfile {|t| |