Skip to content

Commit 481f994

Browse files
committed
[Feature #19630] Limit the versions with the old behavior
It is already declared as: > This behavior is slated to be removed in Ruby 4.0
1 parent 244a37b commit 481f994

File tree

6 files changed

+162
-154
lines changed

6 files changed

+162
-154
lines changed

spec/ruby/core/io/binread_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
-> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL)
4646
end
4747

48-
ruby_version_is "3.3" do
48+
ruby_version_is "3.3"..."4.0" do
4949
# https://bugs.ruby-lang.org/issues/19630
5050
it "warns about deprecation given a path with a pipe" do
5151
cmd = "|echo ok"

spec/ruby/core/io/foreach_spec.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,35 @@
1414
IO.foreach(@name) { $..should == @count += 1 }
1515
end
1616

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

24-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
25-
IO.foreach(cmd) { |l| ScratchPad << l }
25+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
26+
IO.foreach(cmd) { |l| ScratchPad << l }
27+
end
28+
ScratchPad.recorded.should == ["hello\n", "line2\n"]
2629
end
27-
ScratchPad.recorded.should == ["hello\n", "line2\n"]
28-
end
2930

30-
platform_is_not :windows do
31-
it "gets data from a fork when passed -" do
32-
parent_pid = $$
31+
platform_is_not :windows do
32+
it "gets data from a fork when passed -" do
33+
parent_pid = $$
3334

34-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
35-
IO.foreach("|-") { |l| ScratchPad << l }
36-
end
35+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
36+
IO.foreach("|-") { |l| ScratchPad << l }
37+
end
3738

38-
if $$ == parent_pid
39-
ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
40-
else # child
41-
puts "hello"
42-
puts "from a fork"
43-
exit!
39+
if $$ == parent_pid
40+
ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
41+
else # child
42+
puts "hello"
43+
puts "from a fork"
44+
exit!
45+
end
4446
end
4547
end
4648
end

spec/ruby/core/io/read_spec.rb

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -168,76 +168,78 @@
168168
end
169169
end
170170

171-
describe "IO.read from a pipe" do
172-
it "runs the rest as a subprocess and returns the standard output" do
173-
cmd = "|sh -c 'echo hello'"
174-
platform_is :windows do
175-
cmd = "|cmd.exe /C echo hello"
176-
end
177-
178-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
179-
IO.read(cmd).should == "hello\n"
180-
end
181-
end
182-
183-
platform_is_not :windows do
184-
it "opens a pipe to a fork if the rest is -" do
185-
str = nil
186-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
187-
str = IO.read("|-")
171+
ruby_version_is ""..."4.0" do
172+
describe "IO.read from a pipe" do
173+
it "runs the rest as a subprocess and returns the standard output" do
174+
cmd = "|sh -c 'echo hello'"
175+
platform_is :windows do
176+
cmd = "|cmd.exe /C echo hello"
188177
end
189178

190-
if str # parent
191-
str.should == "hello from child\n"
192-
else #child
193-
puts "hello from child"
194-
exit!
179+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
180+
IO.read(cmd).should == "hello\n"
195181
end
196182
end
197-
end
198183

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

205-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
206-
IO.read(cmd, 1).should == "h"
191+
if str # parent
192+
str.should == "hello from child\n"
193+
else #child
194+
puts "hello from child"
195+
exit!
196+
end
197+
end
207198
end
208-
end
209199

210-
platform_is_not :windows do
211-
it "raises Errno::ESPIPE if passed an offset" do
212-
-> {
213-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
214-
IO.read("|sh -c 'echo hello'", 1, 1)
215-
end
216-
}.should raise_error(Errno::ESPIPE)
200+
it "reads only the specified number of bytes requested" do
201+
cmd = "|sh -c 'echo hello'"
202+
platform_is :windows do
203+
cmd = "|cmd.exe /C echo hello"
204+
end
205+
206+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
207+
IO.read(cmd, 1).should == "h"
208+
end
217209
end
218-
end
219210

220-
quarantine! do # The process tried to write to a nonexistent pipe.
221-
platform_is :windows do
222-
# TODO: It should raise Errno::ESPIPE on Windows as well
223-
# once https://bugs.ruby-lang.org/issues/12230 is fixed.
224-
it "raises Errno::EINVAL if passed an offset" do
211+
platform_is_not :windows do
212+
it "raises Errno::ESPIPE if passed an offset" do
225213
-> {
226214
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
227-
IO.read("|cmd.exe /C echo hello", 1, 1)
215+
IO.read("|sh -c 'echo hello'", 1, 1)
228216
end
229-
}.should raise_error(Errno::EINVAL)
217+
}.should raise_error(Errno::ESPIPE)
230218
end
231219
end
232-
end
233220

234-
ruby_version_is "3.3" do
235-
# https://bugs.ruby-lang.org/issues/19630
236-
it "warns about deprecation given a path with a pipe" do
237-
cmd = "|echo ok"
238-
-> {
239-
IO.read(cmd)
240-
}.should complain(/IO process creation with a leading '\|'/)
221+
quarantine! do # The process tried to write to a nonexistent pipe.
222+
platform_is :windows do
223+
# TODO: It should raise Errno::ESPIPE on Windows as well
224+
# once https://bugs.ruby-lang.org/issues/12230 is fixed.
225+
it "raises Errno::EINVAL if passed an offset" do
226+
-> {
227+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
228+
IO.read("|cmd.exe /C echo hello", 1, 1)
229+
end
230+
}.should raise_error(Errno::EINVAL)
231+
end
232+
end
233+
end
234+
235+
ruby_version_is "3.3" do
236+
# https://bugs.ruby-lang.org/issues/19630
237+
it "warns about deprecation" do
238+
cmd = "|echo ok"
239+
-> {
240+
IO.read(cmd)
241+
}.should complain(/IO process creation with a leading '\|'/)
242+
end
241243
end
242244
end
243245
end

spec/ruby/core/io/readlines_spec.rb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,45 +174,47 @@
174174
$_.should == "test"
175175
end
176176

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

191-
platform_is_not :windows do
192-
it "gets data from a fork when passed -" do
193185
lines = nil
194186
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
195-
lines = IO.readlines("|-")
187+
lines = IO.readlines(cmd)
196188
end
189+
lines.should == ["hello\n", "line2\n"]
190+
end
197191

198-
if lines # parent
199-
lines.should == ["hello\n", "from a fork\n"]
200-
else
201-
puts "hello"
202-
puts "from a fork"
203-
exit!
192+
platform_is_not :windows do
193+
it "gets data from a fork when passed -" do
194+
lines = nil
195+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
196+
lines = IO.readlines("|-")
197+
end
198+
199+
if lines # parent
200+
lines.should == ["hello\n", "from a fork\n"]
201+
else
202+
puts "hello"
203+
puts "from a fork"
204+
exit!
205+
end
204206
end
205207
end
206208
end
207-
end
208209

209-
ruby_version_is "3.3" do
210-
# https://bugs.ruby-lang.org/issues/19630
211-
it "warns about deprecation given a path with a pipe" do
212-
cmd = "|echo ok"
213-
-> {
214-
IO.readlines(cmd)
215-
}.should complain(/IO process creation with a leading '\|'/)
210+
ruby_version_is "3.3" do
211+
# https://bugs.ruby-lang.org/issues/19630
212+
it "warns about deprecation given a path with a pipe" do
213+
cmd = "|echo ok"
214+
-> {
215+
IO.readlines(cmd)
216+
}.should complain(/IO process creation with a leading '\|'/)
217+
end
216218
end
217219
end
218220

spec/ruby/core/io/write_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
end
221221
end
222222

223-
ruby_version_is "3.3" do
223+
ruby_version_is "3.3"..."4.0" do
224224
# https://bugs.ruby-lang.org/issues/19630
225225
it "warns about deprecation given a path with a pipe" do
226226
-> {

spec/ruby/core/kernel/open_spec.rb

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,64 +27,66 @@
2727
open(@name, "r") { |f| f.gets }.should == @content
2828
end
2929

30-
platform_is_not :windows, :wasi do
31-
it "opens an io when path starts with a pipe" do
32-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
33-
@io = open("|date")
30+
ruby_version_is ""..."4.0" do
31+
platform_is_not :windows, :wasi do
32+
it "opens an io when path starts with a pipe" do
33+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
34+
@io = open("|date")
35+
end
36+
begin
37+
@io.should be_kind_of(IO)
38+
@io.read
39+
ensure
40+
@io.close
41+
end
3442
end
35-
begin
36-
@io.should be_kind_of(IO)
37-
@io.read
38-
ensure
39-
@io.close
40-
end
41-
end
4243

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

50-
it "opens an io for writing" do
51-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
52-
-> {
53-
bytes = open("|cat", "w") { |io| io.write(".") }
54-
bytes.should == 1
55-
}.should output_to_fd(".")
51+
it "opens an io for writing" do
52+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
53+
-> {
54+
bytes = open("|cat", "w") { |io| io.write(".") }
55+
bytes.should == 1
56+
}.should output_to_fd(".")
57+
end
5658
end
5759
end
58-
end
5960

60-
platform_is :windows do
61-
it "opens an io when path starts with a pipe" do
62-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
63-
@io = open("|date /t")
61+
platform_is :windows do
62+
it "opens an io when path starts with a pipe" do
63+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
64+
@io = open("|date /t")
65+
end
66+
begin
67+
@io.should be_kind_of(IO)
68+
@io.read
69+
ensure
70+
@io.close
71+
end
6472
end
65-
begin
66-
@io.should be_kind_of(IO)
67-
@io.read
68-
ensure
69-
@io.close
70-
end
71-
end
7273

73-
it "opens an io when called with a block" do
74-
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
75-
@output = open("|date /t") { |f| f.read }
74+
it "opens an io when called with a block" do
75+
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
76+
@output = open("|date /t") { |f| f.read }
77+
end
78+
@output.should_not == ''
7679
end
77-
@output.should_not == ''
7880
end
79-
end
8081

81-
ruby_version_is "3.3" do
82-
# https://bugs.ruby-lang.org/issues/19630
83-
it "warns about deprecation given a path with a pipe" do
84-
cmd = "|echo ok"
85-
-> {
86-
open(cmd) { |f| f.read }
87-
}.should complain(/Kernel#open with a leading '\|'/)
82+
ruby_version_is "3.3" do
83+
# https://bugs.ruby-lang.org/issues/19630
84+
it "warns about deprecation given a path with a pipe" do
85+
cmd = "|echo ok"
86+
-> {
87+
open(cmd) { |f| f.read }
88+
}.should complain(/Kernel#open with a leading '\|'/)
89+
end
8890
end
8991
end
9092

0 commit comments

Comments
 (0)