| 1 |
# frozen_string_literal: false |
| 2 |
require 'test/unit' |
| 3 |
|
| 4 |
class TestWait < Test::Unit::TestCase |
| 5 |
require '-test-/wait' |
| 6 |
|
| 7 |
def test_wait_for_valid_fd |
| 8 |
IO.pipe do |r,w| |
| 9 |
rc = IO.io_wait(w, IO::WRITABLE, nil) |
| 10 |
assert_equal IO::WRITABLE, rc |
| 11 |
end |
| 12 |
end |
| 13 |
|
| 14 |
def test_wait_for_invalid_fd |
| 15 |
assert_separately [], <<~'RUBY' |
| 16 |
require '-test-/wait' |
| 17 |
|
| 18 |
r, w = IO.pipe |
| 19 |
r.close |
| 20 |
|
| 21 |
IO.for_fd(w.fileno).close |
| 22 |
|
| 23 |
assert_raise(Errno::EBADF) do |
| 24 |
IO.io_wait(w, IO::WRITABLE, nil) |
| 25 |
end |
| 26 |
RUBY |
| 27 |
end |
| 28 |
|
| 29 |
def test_wait_for_closed_pipe |
| 30 |
IO.pipe do |r,w| |
| 31 |
w.close |
| 32 |
rc = IO.io_wait(r, IO::READABLE, nil) |
| 33 |
assert_equal IO::READABLE, rc |
| 34 |
end |
| 35 |
end |
| 36 |
end |