|
168 | 168 | end |
169 | 169 | end |
170 | 170 |
|
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" |
188 | 177 | end |
189 | 178 |
|
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" |
195 | 181 | end |
196 | 182 | end |
197 | | - end |
198 | 183 |
|
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 |
204 | 190 |
|
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 |
207 | 198 | end |
208 | | - end |
209 | 199 |
|
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 |
217 | 209 | end |
218 | | - end |
219 | 210 |
|
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 |
225 | 213 | -> { |
226 | 214 | 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) |
228 | 216 | end |
229 | | - }.should raise_error(Errno::EINVAL) |
| 217 | + }.should raise_error(Errno::ESPIPE) |
230 | 218 | end |
231 | 219 | end |
232 | | - end |
233 | 220 |
|
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 |
241 | 243 | end |
242 | 244 | end |
243 | 245 | end |
|
0 commit comments