Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/io/binread_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
-> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL)
end

ruby_version_is "3.3" do
ruby_version_is "3.3"..."4.0" do
# https://bugs.ruby-lang.org/issues/19630
it "warns about deprecation given a path with a pipe" do
cmd = "|echo ok"
Expand Down
46 changes: 24 additions & 22 deletions core/io/foreach_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,35 @@
IO.foreach(@name) { $..should == @count += 1 }
end

describe "when the filename starts with |" do
it "gets data from the standard out of the subprocess" do
cmd = "|sh -c 'echo hello;echo line2'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello&echo line2"
end
ruby_version_is ""..."4.0" do
describe "when the filename starts with |" do
it "gets data from the standard out of the subprocess" do
cmd = "|sh -c 'echo hello;echo line2'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello&echo line2"
end

suppress_warning do # https://bugs.ruby-lang.org/issues/19630
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
ScratchPad.recorded.should == ["hello\n", "line2\n"]
end

platform_is_not :windows do
it "gets data from a fork when passed -" do
parent_pid = $$
platform_is_not :windows do
it "gets data from a fork when passed -" do
parent_pid = $$

suppress_warning do # https://bugs.ruby-lang.org/issues/19630
IO.foreach("|-") { |l| ScratchPad << l }
end
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"]
else # child
puts "hello"
puts "from a fork"
exit!
if $$ == parent_pid
ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
else # child
puts "hello"
puts "from a fork"
exit!
end
end
end
end
Expand Down
110 changes: 56 additions & 54 deletions core/io/read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,76 +168,78 @@
end
end

describe "IO.read from a pipe" do
it "runs the rest as a subprocess and returns the standard output" do
cmd = "|sh -c 'echo hello'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello"
end

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 = nil
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
str = IO.read("|-")
ruby_version_is ""..."4.0" do
describe "IO.read from a pipe" do
it "runs the rest as a subprocess and returns the standard output" do
cmd = "|sh -c 'echo hello'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello"
end

if str # parent
str.should == "hello from child\n"
else #child
puts "hello from child"
exit!
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
IO.read(cmd).should == "hello\n"
end
end
end

it "reads only the specified number of bytes requested" do
cmd = "|sh -c 'echo hello'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello"
end
platform_is_not :windows do
it "opens a pipe to a fork if the rest is -" do
str = nil
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
str = IO.read("|-")
end

suppress_warning do # https://bugs.ruby-lang.org/issues/19630
IO.read(cmd, 1).should == "h"
if str # parent
str.should == "hello from child\n"
else #child
puts "hello from child"
exit!
end
end
end
end

platform_is_not :windows do
it "raises Errno::ESPIPE if passed an offset" do
-> {
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
IO.read("|sh -c 'echo hello'", 1, 1)
end
}.should raise_error(Errno::ESPIPE)
it "reads only the specified number of bytes requested" do
cmd = "|sh -c 'echo hello'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello"
end

suppress_warning do # https://bugs.ruby-lang.org/issues/19630
IO.read(cmd, 1).should == "h"
end
end
end

quarantine! do # The process tried to write to a nonexistent pipe.
platform_is :windows do
# TODO: It should raise Errno::ESPIPE on Windows as well
# once https://bugs.ruby-lang.org/issues/12230 is fixed.
it "raises Errno::EINVAL if passed an offset" do
platform_is_not :windows do
it "raises Errno::ESPIPE if passed an offset" do
-> {
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
IO.read("|cmd.exe /C echo hello", 1, 1)
IO.read("|sh -c 'echo hello'", 1, 1)
end
}.should raise_error(Errno::EINVAL)
}.should raise_error(Errno::ESPIPE)
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 '\|'/)
quarantine! do # The process tried to write to a nonexistent pipe.
platform_is :windows do
# TODO: It should raise Errno::ESPIPE on Windows as well
# once https://bugs.ruby-lang.org/issues/12230 is fixed.
it "raises Errno::EINVAL if passed an offset" do
-> {
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" do
cmd = "|echo ok"
-> {
IO.read(cmd)
}.should complain(/IO process creation with a leading '\|'/)
end
end
end
end
Expand Down
62 changes: 32 additions & 30 deletions core/io/readlines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,45 +174,47 @@
$_.should == "test"
end

describe "when passed a string that starts with a |" do
it "gets data from the standard out of the subprocess" do
cmd = "|sh -c 'echo hello;echo line2'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello&echo line2"
end

lines = nil
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
lines = IO.readlines(cmd)
end
lines.should == ["hello\n", "line2\n"]
end
ruby_version_is ""..."4.0" do
describe "when passed a string that starts with a |" do
it "gets data from the standard out of the subprocess" do
cmd = "|sh -c 'echo hello;echo line2'"
platform_is :windows do
cmd = "|cmd.exe /C echo hello&echo line2"
end

platform_is_not :windows do
it "gets data from a fork when passed -" do
lines = nil
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
lines = IO.readlines("|-")
lines = IO.readlines(cmd)
end
lines.should == ["hello\n", "line2\n"]
end

if lines # parent
lines.should == ["hello\n", "from a fork\n"]
else
puts "hello"
puts "from a fork"
exit!
platform_is_not :windows do
it "gets data from a fork when passed -" do
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"]
else
puts "hello"
puts "from a fork"
exit!
end
end
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.readlines(cmd)
}.should complain(/IO process creation with a leading '\|'/)
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
end

Expand Down
2 changes: 1 addition & 1 deletion core/io/write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
end
end

ruby_version_is "3.3" do
ruby_version_is "3.3"..."4.0" do
# https://bugs.ruby-lang.org/issues/19630
it "warns about deprecation given a path with a pipe" do
-> {
Expand Down
94 changes: 48 additions & 46 deletions core/kernel/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,66 @@
open(@name, "r") { |f| f.gets }.should == @content
end

platform_is_not :windows, :wasi do
it "opens an io when path starts with a pipe" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@io = open("|date")
ruby_version_is ""..."4.0" do
platform_is_not :windows, :wasi do
it "opens an io when path starts with a pipe" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@io = open("|date")
end
begin
@io.should be_kind_of(IO)
@io.read
ensure
@io.close
end
end
begin
@io.should be_kind_of(IO)
@io.read
ensure
@io.close
end
end

it "opens an io when called with a block" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@output = open("|date") { |f| f.read }
it "opens an io when called with a block" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@output = open("|date") { |f| f.read }
end
@output.should_not == ''
end
@output.should_not == ''
end

it "opens an io for writing" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
-> {
bytes = open("|cat", "w") { |io| io.write(".") }
bytes.should == 1
}.should output_to_fd(".")
it "opens an io for writing" do
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
end

platform_is :windows do
it "opens an io when path starts with a pipe" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@io = open("|date /t")
platform_is :windows do
it "opens an io when path starts with a pipe" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@io = open("|date /t")
end
begin
@io.should be_kind_of(IO)
@io.read
ensure
@io.close
end
end
begin
@io.should be_kind_of(IO)
@io.read
ensure
@io.close
end
end

it "opens an io when called with a block" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@output = open("|date /t") { |f| f.read }
it "opens an io when called with a block" do
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
@output = open("|date /t") { |f| f.read }
end
@output.should_not == ''
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 '\|'/)
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
end

Expand Down
Loading