diff options
author | Mike Dalessio <mike.dalessio@gmail.com> | 2023-06-07 10:05:04 -0400 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-08-10 09:38:11 +0900 |
commit | d2343368ab7e270118ea6baa9c6418bfed83135c (patch) | |
tree | 0e25287d42464b9812033f613234f3baa11c5517 /spec | |
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 'spec')
-rw-r--r-- | spec/ruby/core/io/binread_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/io/foreach_spec.rb | 19 | ||||
-rw-r--r-- | spec/ruby/core/io/read_spec.rb | 34 | ||||
-rw-r--r-- | spec/ruby/core/io/readlines_spec.rb | 21 | ||||
-rw-r--r-- | spec/ruby/core/io/write_spec.rb | 11 | ||||
-rw-r--r-- | spec/ruby/core/kernel/open_spec.rb | 36 |
6 files changed, 114 insertions, 17 deletions
diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb index a3f752d8f9..418e89213b 100644 --- a/spec/ruby/core/io/binread_spec.rb +++ b/spec/ruby/core/io/binread_spec.rb @@ -44,4 +44,14 @@ describe "IO.binread" do it "raises an Errno::EINVAL when not passed a valid offset" do -> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) end + + ruby_version_is "3.3" do + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + IO.binread(cmd) + }.should complain(/IO process creation with a leading '\|'/) + end + end end diff --git a/spec/ruby/core/io/foreach_spec.rb b/spec/ruby/core/io/foreach_spec.rb index c2276cf544..c361d27879 100644 --- a/spec/ruby/core/io/foreach_spec.rb +++ b/spec/ruby/core/io/foreach_spec.rb @@ -20,7 +20,10 @@ describe "IO.foreach" do platform_is :windows do cmd = "|cmd.exe /C echo hello&echo line2" end - IO.foreach(cmd) { |l| ScratchPad << l } + + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + IO.foreach(cmd) { |l| ScratchPad << l } + end ScratchPad.recorded.should == ["hello\n", "line2\n"] end @@ -28,7 +31,9 @@ describe "IO.foreach" do it "gets data from a fork when passed -" do parent_pid = $$ - IO.foreach("|-") { |l| ScratchPad << l } + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + IO.foreach("|-") { |l| ScratchPad << l } + end if $$ == parent_pid ScratchPad.recorded.should == ["hello\n", "from a fork\n"] @@ -39,6 +44,16 @@ describe "IO.foreach" do end end end + + ruby_version_is "3.3" do + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + IO.foreach(cmd).to_a + }.should complain(/IO process creation with a leading '\|'/) + end + end end end diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index a829ffd18c..bd22fb6d6e 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -165,12 +165,19 @@ describe "IO.read from a pipe" do platform_is :windows do cmd = "|cmd.exe /C echo hello" end - IO.read(cmd).should == "hello\n" + + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + IO.read(cmd).should == "hello\n" + end end platform_is_not :windows do it "opens a pipe to a fork if the rest is -" do - str = IO.read("|-") + str = nil + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + str = IO.read("|-") + end + if str # parent str.should == "hello from child\n" else #child @@ -185,13 +192,18 @@ describe "IO.read from a pipe" do platform_is :windows do cmd = "|cmd.exe /C echo hello" end - IO.read(cmd, 1).should == "h" + + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + IO.read(cmd, 1).should == "h" + end end platform_is_not :windows do it "raises Errno::ESPIPE if passed an offset" do -> { - IO.read("|sh -c 'echo hello'", 1, 1) + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + IO.read("|sh -c 'echo hello'", 1, 1) + end }.should raise_error(Errno::ESPIPE) end end @@ -202,11 +214,23 @@ quarantine! do # The process tried to write to a nonexistent pipe. # once https://bugs.ruby-lang.org/issues/12230 is fixed. it "raises Errno::EINVAL if passed an offset" do -> { - IO.read("|cmd.exe /C echo hello", 1, 1) + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + IO.read("|cmd.exe /C echo hello", 1, 1) + end }.should raise_error(Errno::EINVAL) end end end + + ruby_version_is "3.3" do + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + IO.read(cmd) + }.should complain(/IO process creation with a leading '\|'/) + end + end end describe "IO.read on an empty file" do diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb index d6c4d539cf..3a6ff3d0f3 100644 --- a/spec/ruby/core/io/readlines_spec.rb +++ b/spec/ruby/core/io/readlines_spec.rb @@ -180,13 +180,20 @@ describe "IO.readlines" do platform_is :windows do cmd = "|cmd.exe /C echo hello&echo line2" end - lines = IO.readlines(cmd) + + lines = nil + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + lines = IO.readlines(cmd) + end lines.should == ["hello\n", "line2\n"] end platform_is_not :windows do it "gets data from a fork when passed -" do - lines = IO.readlines("|-") + lines = nil + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + lines = IO.readlines("|-") + end if lines # parent lines.should == ["hello\n", "from a fork\n"] @@ -199,6 +206,16 @@ describe "IO.readlines" do end end + ruby_version_is "3.3" do + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + IO.readlines(cmd) + }.should complain(/IO process creation with a leading '\|'/) + end + end + it_behaves_like :io_readlines, :readlines it_behaves_like :io_readlines_options_19, :readlines end diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb index 3f04fb053f..2e39b4fadd 100644 --- a/spec/ruby/core/io/write_spec.rb +++ b/spec/ruby/core/io/write_spec.rb @@ -215,6 +215,17 @@ describe "IO.write" do end end end + + ruby_version_is "3.3" do + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + -> { + -> { + IO.write("|cat", "xxx") + }.should output_to_fd("xxx") + }.should complain(/IO process creation with a leading '\|'/) + end + end end end diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb index 99793294c5..bb42c31f31 100644 --- a/spec/ruby/core/kernel/open_spec.rb +++ b/spec/ruby/core/kernel/open_spec.rb @@ -29,7 +29,9 @@ describe "Kernel#open" do platform_is_not :windows, :wasi do it "opens an io when path starts with a pipe" do - @io = open("|date") + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + @io = open("|date") + end begin @io.should be_kind_of(IO) @io.read @@ -39,21 +41,27 @@ describe "Kernel#open" do end it "opens an io when called with a block" do - @output = open("|date") { |f| f.read } + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + @output = open("|date") { |f| f.read } + end @output.should_not == '' end it "opens an io for writing" do - -> do - bytes = open("|cat", "w") { |io| io.write(".") } - bytes.should == 1 - end.should output_to_fd(".") + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + -> { + bytes = open("|cat", "w") { |io| io.write(".") } + bytes.should == 1 + }.should output_to_fd(".") + end end end platform_is :windows do it "opens an io when path starts with a pipe" do - @io = open("|date /t") + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + @io = open("|date /t") + end begin @io.should be_kind_of(IO) @io.read @@ -63,11 +71,23 @@ describe "Kernel#open" do end it "opens an io when called with a block" do - @output = open("|date /t") { |f| f.read } + suppress_warning do # https://bugs.ruby-lang.org/issues/19630 + @output = open("|date /t") { |f| f.read } + end @output.should_not == '' end end + ruby_version_is "3.3" do + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + open(cmd) { |f| f.read } + }.should complain(/Kernel#open with a leading '\|'/) + end + end + it "raises an ArgumentError if not passed one argument" do -> { open }.should raise_error(ArgumentError) end |