Skip to content

Commit 0c73ebc

Browse files
committed
Refined uncommon device type tests
1 parent 12ae3df commit 0c73ebc

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

test/io/wait/test_io_wait_uncommon.rb

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@
66
# We may optimize IO#wait_*able for non-Linux kernels in the future
77
class TestIOWaitUncommon < Test::Unit::TestCase
88
def test_tty_wait
9-
begin
10-
tty = File.open('/dev/tty', 'w+')
11-
rescue Errno::ENOENT, Errno::ENXIO => e
12-
skip "/dev/tty: #{e.message} (#{e.class})"
9+
check_dev('/dev/tty', mode: 'w+') do |tty|
10+
assert_include [ nil, tty ], tty.wait_readable(0)
11+
assert_equal tty, tty.wait_writable(1), 'portability test'
1312
end
14-
assert_include [ nil, tty ], tty.wait_readable(0)
15-
assert_equal tty, tty.wait_writable(1), 'portability test'
16-
ensure
17-
tty&.close
1813
end
1914

2015
def test_fifo_wait
@@ -44,36 +39,40 @@ def test_fifo_wait
4439

4540
# used to find portability problems because some ppoll implementations
4641
# are incomplete and do not work for certain "file" types
47-
def check_dev(dev, m = :wait_readable)
42+
def check_dev(dev, m = :wait_readable, mode: m == :wait_readable ? 'r' : 'w', &block)
4843
begin
49-
fp = File.open("/dev/#{dev}", m == :wait_readable ? 'r' : 'w')
44+
fp = File.open(dev, mode)
45+
rescue Errno::ENOENT
46+
return # Ignore silently
5047
rescue SystemCallError => e
5148
skip "#{dev} could not be opened #{e.message} (#{e.class})"
5249
end
53-
assert_same fp, fp.__send__(m)
50+
if block
51+
yield fp
52+
else
53+
assert_same fp, fp.__send__(m)
54+
end
5455
ensure
5556
fp&.close
5657
end
5758

5859
def test_wait_readable_urandom
59-
check_dev 'urandom'
60+
check_dev('/dev/urandom')
6061
end
6162

6263
def test_wait_readable_random
63-
File.open('/dev/random') do |fp|
64+
check_dev('/dev/random') do |fp|
6465
assert_nothing_raised do
6566
fp.wait_readable(0)
6667
end
6768
end
68-
rescue SystemCallError => e
69-
skip "/dev/random could not be opened #{e.message} (#{e.class})"
7069
end
7170

7271
def test_wait_readable_zero
73-
check_dev 'zero'
72+
check_dev('/dev/zero')
7473
end
7574

7675
def test_wait_writable_null
77-
check_dev 'null', :wait_writable
76+
check_dev(IO::NULL, :wait_writable)
7877
end
7978
end

0 commit comments

Comments
 (0)