Skip to content

Commit

Permalink
Don't depend on TTY ioctls for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed May 31, 2011
1 parent 7a294d1 commit 030c23e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions spec/ruby/core/io/ioctl_spec.rb
Expand Up @@ -8,23 +8,20 @@

platform_is :os => :linux do
it "replaces a String's content with the output buffer" do
File.open('/dev/tty', 'r') do |f|
# Process group ID and session ID.
# Ruby has Process.getpgrp but no method to get the session ID.
ids = `ps -j --no-heading -p #{Process.pid}`.split[1, 2].map(&:to_i)
File.open(__FILE__, 'r') do |f|
buffer = ''
# TIOCGPGRP in /usr/include/asm-generic/ioctls.h
f.ioctl 0x540F, buffer
ids.should include(buffer.unpack('I').first)
# FIONREAD in /usr/include/asm-generic/ioctls.h
f.ioctl 0x541B, buffer
buffer.unpack('I').first.should be_kind_of(Integer)
end
end

it "raises an Errno error when ioctl fails" do
File.open('/dev/tty', 'r') do |f|
File.open(__FILE__, 'r') do |f|
lambda {
# TIOCGPGRP in /usr/include/asm-generic/ioctls.h
f.ioctl 0x540F, nil
}.should raise_error(Errno::EFAULT)
# TIOCGWINSZ in /usr/include/asm-generic/ioctls.h
f.ioctl 0x5413, nil
}.should raise_error(Errno::ENOTTY)
end
end
end
Expand Down

0 comments on commit 030c23e

Please sign in to comment.