summaryrefslogtreecommitdiff
path: root/test/ruby/test_io.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r--test/ruby/test_io.rb120
1 files changed, 120 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 39dc784050..f8ef71e41e 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -2042,4 +2042,124 @@ End
write_file.close
file.close!
end
+
+ def test_warn
+ stderr = EnvUtil.verbose_warning do
+ warn "warning"
+ end
+ assert_equal("warning\n", stderr)
+
+ stderr = EnvUtil.verbose_warning do
+ warn
+ end
+ assert_equal("", stderr)
+
+ stderr = EnvUtil.verbose_warning do
+ warn "[Feature #5029]", "[ruby-core:38070]"
+ end
+ assert_equal("[Feature #5029]\n[ruby-core:38070]\n", stderr)
+ end
+
+ def test_cloexec
+ return unless defined? Fcntl::FD_CLOEXEC
+ open(__FILE__) {|f|
+ assert(f.close_on_exec?)
+ g = f.dup
+ begin
+ assert(g.close_on_exec?)
+ f.reopen(g)
+ assert(f.close_on_exec?)
+ ensure
+ g.close
+ end
+ g = IO.new(f.fcntl(Fcntl::F_DUPFD))
+ begin
+ assert(g.close_on_exec?)
+ ensure
+ g.close
+ end
+ }
+ IO.pipe {|r,w|
+ assert(r.close_on_exec?)
+ assert(w.close_on_exec?)
+ }
+ end
+
+ def test_ioctl_linux
+ return if /linux/ !~ RUBY_PLATFORM
+
+ assert_nothing_raised do
+ File.open('/dev/urandom'){|f1|
+ entropy_count = ""
+ # get entropy count
+ f1.ioctl(0x80045200, entropy_count)
+ }
+ end
+
+ buf = ''
+ assert_nothing_raised do
+ fionread = 0x541B
+ File.open(__FILE__){|f1|
+ f1.ioctl(fionread, buf)
+ }
+ end
+ assert_equal(File.size(__FILE__), buf.unpack('i!')[0])
+ end
+
+ def test_ioctl_linux2
+ return if /linux/ !~ RUBY_PLATFORM
+ return if /^i?86|^x86_64/ !~ RUBY_PLATFORM
+
+ File.open('/dev/tty') { |f|
+ tiocgwinsz=0x5413
+ winsize=""
+ assert_nothing_raised {
+ f.ioctl(tiocgwinsz, winsize)
+ }
+ }
+ end
+
+ def test_setpos
+ mkcdtmpdir {
+ File.open("tmp.txt", "w") {|f|
+ f.puts "a"
+ f.puts "bc"
+ f.puts "def"
+ }
+ pos1 = pos2 = pos3 = nil
+ File.open("tmp.txt") {|f|
+ assert_equal("a\n", f.gets)
+ pos1 = f.pos
+ assert_equal("bc\n", f.gets)
+ pos2 = f.pos
+ assert_equal("def\n", f.gets)
+ pos3 = f.pos
+ assert_equal(nil, f.gets)
+ }
+ File.open("tmp.txt") {|f|
+ f.pos = pos1
+ assert_equal("bc\n", f.gets)
+ assert_equal("def\n", f.gets)
+ assert_equal(nil, f.gets)
+ }
+ File.open("tmp.txt") {|f|
+ f.pos = pos2
+ assert_equal("def\n", f.gets)
+ assert_equal(nil, f.gets)
+ }
+ File.open("tmp.txt") {|f|
+ f.pos = pos3
+ assert_equal(nil, f.gets)
+ }
+ }
+ end
+
+ def test_std_fileno
+ assert_equal(0, STDIN.fileno)
+ assert_equal(1, STDOUT.fileno)
+ assert_equal(2, STDERR.fileno)
+ assert_equal(0, $stdin.fileno)
+ assert_equal(1, $stdout.fileno)
+ assert_equal(2, $stderr.fileno)
+ end
end