2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2003-12-04 21:54:48 -05:00
|
|
|
require 'test/unit'
|
2008-02-18 03:09:05 -05:00
|
|
|
require_relative 'ut_eof'
|
2003-12-04 21:54:48 -05:00
|
|
|
|
|
|
|
class TestPipe < Test::Unit::TestCase
|
|
|
|
include TestEOF
|
|
|
|
def open_file(content)
|
2003-12-04 23:18:37 -05:00
|
|
|
r, w = IO.pipe
|
|
|
|
w << content
|
|
|
|
w.close
|
|
|
|
begin
|
|
|
|
yield r
|
|
|
|
ensure
|
|
|
|
r.close
|
|
|
|
end
|
2003-12-04 21:54:48 -05:00
|
|
|
end
|
2014-06-06 23:51:57 -04:00
|
|
|
class WithConversion < self
|
|
|
|
def open_file(content)
|
|
|
|
r, w = IO.pipe
|
|
|
|
w << content
|
|
|
|
w.close
|
|
|
|
r.set_encoding("us-ascii:utf-8")
|
|
|
|
begin
|
|
|
|
yield r
|
|
|
|
ensure
|
|
|
|
r.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-31 21:56:28 -05:00
|
|
|
|
|
|
|
def test_stdout_epipe
|
|
|
|
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
|
|
|
|
begin;
|
|
|
|
io = STDOUT
|
|
|
|
begin
|
|
|
|
save = io.dup
|
|
|
|
IO.popen("echo", "w", out: IO::NULL) do |f|
|
|
|
|
io.reopen(f)
|
|
|
|
Process.wait(f.pid)
|
|
|
|
assert_raise(Errno::EPIPE) do
|
|
|
|
io.print "foo\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
io.reopen(save)
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
end
|
2003-12-04 21:54:48 -05:00
|
|
|
end
|