1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/test_io.rb: remove temporally files early.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2012-07-19 13:47:08 +00:00
parent f0810814bd
commit 422e8d5adc
2 changed files with 352 additions and 319 deletions

View file

@ -1,3 +1,7 @@
Thu Jul 19 22:46:48 2012 Tanaka Akira <akr@fsij.org>
* test/ruby/test_io.rb: remove temporally files early.
Thu Jul 19 15:38:35 2012 Shugo Maeda <shugo@ruby-lang.org> Thu Jul 19 15:38:35 2012 Shugo Maeda <shugo@ruby-lang.org>
* variable.c (rb_mod_class_variables): return inherited variables * variable.c (rb_mod_class_variables): return inherited variables

View file

@ -205,25 +205,26 @@ class TestIO < Test::Unit::TestCase
end end
def test_ungetbyte def test_ungetbyte
t = make_tempfile make_tempfile {|t|
t.open t.open
t.binmode t.binmode
t.ungetbyte(0x41) t.ungetbyte(0x41)
assert_equal(-1, t.pos) assert_equal(-1, t.pos)
assert_equal(0x41, t.getbyte) assert_equal(0x41, t.getbyte)
t.rewind t.rewind
assert_equal(0, t.pos) assert_equal(0, t.pos)
t.ungetbyte("qux") t.ungetbyte("qux")
assert_equal(-3, t.pos) assert_equal(-3, t.pos)
assert_equal("quxfoo\n", t.gets) assert_equal("quxfoo\n", t.gets)
assert_equal(4, t.pos) assert_equal(4, t.pos)
t.set_encoding("utf-8") t.set_encoding("utf-8")
t.ungetbyte(0x89) t.ungetbyte(0x89)
t.ungetbyte(0x8e) t.ungetbyte(0x8e)
t.ungetbyte("\xe7") t.ungetbyte("\xe7")
t.ungetbyte("\xe7\xb4\x85") t.ungetbyte("\xe7\xb4\x85")
assert_equal(-2, t.pos) assert_equal(-2, t.pos)
assert_equal("\u7d05\u7389bar\n", t.gets) assert_equal("\u7d05\u7389bar\n", t.gets)
}
end end
def test_each_byte def test_each_byte
@ -237,23 +238,25 @@ class TestIO < Test::Unit::TestCase
end end
def test_each_byte_with_seek def test_each_byte_with_seek
t = make_tempfile make_tempfile {|t|
bug5119 = '[ruby-core:38609]' bug5119 = '[ruby-core:38609]'
i = 0 i = 0
open(t.path) do |f| open(t.path) do |f|
f.each_byte {i = f.pos} f.each_byte {i = f.pos}
end end
assert_equal(12, i, bug5119) assert_equal(12, i, bug5119)
}
end end
def test_each_codepoint def test_each_codepoint
t = make_tempfile make_tempfile {|t|
bug2959 = '[ruby-core:28650]' bug2959 = '[ruby-core:28650]'
a = "" a = ""
File.open(t, 'rt') {|f| File.open(t, 'rt') {|f|
f.each_codepoint {|c| a << c} f.each_codepoint {|c| a << c}
}
assert_equal("foo\nbar\nbaz\n", a, bug2959)
} }
assert_equal("foo\nbar\nbaz\n", a, bug2959)
end end
def test_rubydev33072 def test_rubydev33072
@ -1236,38 +1239,38 @@ class TestIO < Test::Unit::TestCase
end end
def test_set_lineno def test_set_lineno
t = make_tempfile make_tempfile {|t|
ruby("-e", <<-SRC, t.path) do |f|
ruby("-e", <<-SRC, t.path) do |f| open(ARGV[0]) do |f|
open(ARGV[0]) do |f| p $.
p $. f.gets; p $.
f.gets; p $. f.gets; p $.
f.gets; p $. f.lineno = 1000; p $.
f.lineno = 1000; p $. f.gets; p $.
f.gets; p $. f.gets; p $.
f.gets; p $. f.rewind; p $.
f.rewind; p $. f.gets; p $.
f.gets; p $. f.gets; p $.
f.gets; p $. f.gets; p $.
f.gets; p $. f.gets; p $.
f.gets; p $. end
SRC
assert_equal("0,1,2,2,1001,1001,1001,1,2,3,3", f.read.chomp.gsub("\n", ","))
end end
SRC
assert_equal("0,1,2,2,1001,1001,1001,1,2,3,3", f.read.chomp.gsub("\n", ","))
end
pipe(proc do |w| pipe(proc do |w|
w.puts "foo" w.puts "foo"
w.puts "bar" w.puts "bar"
w.puts "baz" w.puts "baz"
w.close w.close
end, proc do |r| end, proc do |r|
r.gets; assert_equal(1, $.) r.gets; assert_equal(1, $.)
r.gets; assert_equal(2, $.) r.gets; assert_equal(2, $.)
r.lineno = 1000; assert_equal(2, $.) r.lineno = 1000; assert_equal(2, $.)
r.gets; assert_equal(1001, $.) r.gets; assert_equal(1001, $.)
r.gets; assert_equal(1001, $.) r.gets; assert_equal(1001, $.)
end) end)
}
end end
def test_readline def test_readline
@ -1414,41 +1417,43 @@ class TestIO < Test::Unit::TestCase
end end
def test_pos def test_pos
t = make_tempfile make_tempfile {|t|
open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f| open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
f.write "Hello" f.write "Hello"
assert_equal(5, f.pos) assert_equal(5, f.pos)
end end
open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f| open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
f.sync = true f.sync = true
f.read f.read
f.write "Hello" f.write "Hello"
assert_equal(5, f.pos) assert_equal(5, f.pos)
end end
}
end end
def test_pos_with_getc def test_pos_with_getc
bug6179 = '[ruby-core:43497]' bug6179 = '[ruby-core:43497]'
t = make_tempfile make_tempfile {|t|
["", "t", "b"].each do |mode| ["", "t", "b"].each do |mode|
open(t.path, "w#{mode}") do |f| open(t.path, "w#{mode}") do |f|
f.write "0123456789\n" f.write "0123456789\n"
end end
open(t.path, "r#{mode}") do |f| open(t.path, "r#{mode}") do |f|
assert_equal 0, f.pos, "mode=r#{mode}" assert_equal 0, f.pos, "mode=r#{mode}"
assert_equal '0', f.getc, "mode=r#{mode}" assert_equal '0', f.getc, "mode=r#{mode}"
assert_equal 1, f.pos, "mode=r#{mode}" assert_equal 1, f.pos, "mode=r#{mode}"
assert_equal '1', f.getc, "mode=r#{mode}" assert_equal '1', f.getc, "mode=r#{mode}"
assert_equal 2, f.pos, "mode=r#{mode}" assert_equal 2, f.pos, "mode=r#{mode}"
assert_equal '2', f.getc, "mode=r#{mode}" assert_equal '2', f.getc, "mode=r#{mode}"
assert_equal 3, f.pos, "mode=r#{mode}" assert_equal 3, f.pos, "mode=r#{mode}"
assert_equal '3', f.getc, "mode=r#{mode}" assert_equal '3', f.getc, "mode=r#{mode}"
assert_equal 4, f.pos, "mode=r#{mode}" assert_equal 4, f.pos, "mode=r#{mode}"
assert_equal '4', f.getc, "mode=r#{mode}" assert_equal '4', f.getc, "mode=r#{mode}"
end
end end
end }
end end
@ -1478,39 +1483,39 @@ class TestIO < Test::Unit::TestCase
end end
def test_sysseek def test_sysseek
t = make_tempfile make_tempfile {|t|
open(t.path) do |f|
f.sysseek(-4, IO::SEEK_END)
assert_equal("baz\n", f.read)
end
open(t.path) do |f| open(t.path) do |f|
f.sysseek(-4, IO::SEEK_END) a = [f.getc, f.getc, f.getc]
assert_equal("baz\n", f.read) a.reverse_each {|c| f.ungetc c }
end assert_raise(IOError) { f.sysseek(1) }
end
open(t.path) do |f| }
a = [f.getc, f.getc, f.getc]
a.reverse_each {|c| f.ungetc c }
assert_raise(IOError) { f.sysseek(1) }
end
end end
def test_syswrite def test_syswrite
t = make_tempfile make_tempfile {|t|
open(t.path, "w") do |f|
open(t.path, "w") do |f| o = Object.new
o = Object.new def o.to_s; "FOO\n"; end
def o.to_s; "FOO\n"; end f.syswrite(o)
f.syswrite(o) end
end assert_equal("FOO\n", File.read(t.path))
assert_equal("FOO\n", File.read(t.path)) }
end end
def test_sysread def test_sysread
t = make_tempfile make_tempfile {|t|
open(t.path) do |f|
open(t.path) do |f| a = [f.getc, f.getc, f.getc]
a = [f.getc, f.getc, f.getc] a.reverse_each {|c| f.ungetc c }
a.reverse_each {|c| f.ungetc c } assert_raise(IOError) { f.sysread(1) }
assert_raise(IOError) { f.sysread(1) } end
end }
end end
def test_sysread_with_not_empty_buffer def test_sysread_with_not_empty_buffer
@ -1524,41 +1529,41 @@ class TestIO < Test::Unit::TestCase
end end
def test_flag def test_flag
t = make_tempfile make_tempfile {|t|
assert_raise(ArgumentError) do
open(t.path, "z") { }
end
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
open(t.path, "z") { } open(t.path, "rr") { }
end end
}
assert_raise(ArgumentError) do
open(t.path, "rr") { }
end
end end
def test_sysopen def test_sysopen
t = make_tempfile make_tempfile {|t|
fd = IO.sysopen(t.path)
fd = IO.sysopen(t.path) assert_kind_of(Integer, fd)
assert_kind_of(Integer, fd)
f = IO.for_fd(fd)
assert_equal("foo\nbar\nbaz\n", f.read)
f.close
fd = IO.sysopen(t.path, "w", 0666)
assert_kind_of(Integer, fd)
if defined?(Fcntl::F_GETFL)
f = IO.for_fd(fd) f = IO.for_fd(fd)
else assert_equal("foo\nbar\nbaz\n", f.read)
f = IO.for_fd(fd, 0666) f.close
end
f.write("FOO\n")
f.close
fd = IO.sysopen(t.path, "r") fd = IO.sysopen(t.path, "w", 0666)
assert_kind_of(Integer, fd) assert_kind_of(Integer, fd)
f = IO.for_fd(fd) if defined?(Fcntl::F_GETFL)
assert_equal("FOO\n", f.read) f = IO.for_fd(fd)
f.close else
f = IO.for_fd(fd, 0666)
end
f.write("FOO\n")
f.close
fd = IO.sysopen(t.path, "r")
assert_kind_of(Integer, fd)
f = IO.for_fd(fd)
assert_equal("FOO\n", f.read)
f.close
}
end end
def try_fdopen(fd, autoclose = true, level = 50) def try_fdopen(fd, autoclose = true, level = 50)
@ -1577,21 +1582,23 @@ class TestIO < Test::Unit::TestCase
feature2250 = '[ruby-core:26222]' feature2250 = '[ruby-core:26222]'
pre = 'ft2250' pre = 'ft2250'
t = Tempfile.new(pre) Dir.mktmpdir {|d|
f = IO.for_fd(t.fileno) t = open("#{d}/#{pre}", "w")
assert_equal(true, f.autoclose?) f = IO.for_fd(t.fileno)
f.autoclose = false assert_equal(true, f.autoclose?)
assert_equal(false, f.autoclose?) f.autoclose = false
f.close assert_equal(false, f.autoclose?)
assert_nothing_raised(Errno::EBADF, feature2250) {t.close} f.close
assert_nothing_raised(Errno::EBADF, feature2250) {t.close}
t.open t = open("#{d}/#{pre}", "w")
f = IO.for_fd(t.fileno, autoclose: false) f = IO.for_fd(t.fileno, autoclose: false)
assert_equal(false, f.autoclose?) assert_equal(false, f.autoclose?)
f.autoclose = true f.autoclose = true
assert_equal(true, f.autoclose?) assert_equal(true, f.autoclose?)
f.close f.close
assert_raise(Errno::EBADF, feature2250) {t.close} assert_raise(Errno::EBADF, feature2250) {t.close}
}
end end
def test_autoclose_true_closed_by_finalizer def test_autoclose_true_closed_by_finalizer
@ -1609,6 +1616,8 @@ class TestIO < Test::Unit::TestCase
rescue WeakRef::RefError rescue WeakRef::RefError
assert_raise(Errno::EBADF, feature2250) {t.close} assert_raise(Errno::EBADF, feature2250) {t.close}
end end
ensure
t.unlink
end end
def test_autoclose_false_closed_by_finalizer def test_autoclose_false_closed_by_finalizer
@ -1623,6 +1632,8 @@ class TestIO < Test::Unit::TestCase
rescue WeakRef::RefError rescue WeakRef::RefError
assert_nothing_raised(Errno::EBADF, feature2250) {t.close} assert_nothing_raised(Errno::EBADF, feature2250) {t.close}
end end
ensure
t.unlink
end end
def test_open_redirect def test_open_redirect
@ -1645,48 +1656,48 @@ class TestIO < Test::Unit::TestCase
end end
def test_reopen def test_reopen
t = make_tempfile make_tempfile {|t|
with_pipe do |r, w|
with_pipe do |r, w| assert_raise(SecurityError) do
assert_raise(SecurityError) do safe_4 { r.reopen(t.path) }
safe_4 { r.reopen(t.path) } end
end end
end
open(__FILE__) do |f| open(__FILE__) do |f|
f.gets f.gets
assert_nothing_raised {
f.reopen(t.path)
assert_equal("foo\n", f.gets)
}
end
open(__FILE__) do |f|
f.gets
f2 = open(t.path)
begin
f2.gets
assert_nothing_raised { assert_nothing_raised {
f.reopen(f2) f.reopen(t.path)
assert_equal("bar\n", f.gets, '[ruby-core:24240]') assert_equal("foo\n", f.gets)
} }
ensure
f2.close
end end
end
open(__FILE__) do |f| open(__FILE__) do |f|
f2 = open(t.path) f.gets
begin f2 = open(t.path)
f.reopen(f2) begin
assert_equal("foo\n", f.gets) f2.gets
assert_equal("bar\n", f.gets) assert_nothing_raised {
f.reopen(f2) f.reopen(f2)
assert_equal("baz\n", f.gets, '[ruby-dev:39479]') assert_equal("bar\n", f.gets, '[ruby-core:24240]')
ensure }
f2.close ensure
f2.close
end
end end
end
open(__FILE__) do |f|
f2 = open(t.path)
begin
f.reopen(f2)
assert_equal("foo\n", f.gets)
assert_equal("bar\n", f.gets)
f.reopen(f2)
assert_equal("baz\n", f.gets, '[ruby-dev:39479]')
ensure
f2.close
end
end
}
end end
def test_reopen_inherit def test_reopen_inherit
@ -1707,55 +1718,55 @@ End
IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x } IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a) assert_equal(["foo\n", "bar\n", "baz\n"], a)
t = make_tempfile make_tempfile {|t|
a = []
IO.foreach(t.path) {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = [] a = []
IO.foreach(t.path) {|x| a << x } IO.foreach(t.path, {:mode => "r" }) {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a) assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = [] a = []
IO.foreach(t.path, {:mode => "r" }) {|x| a << x } IO.foreach(t.path, {:open_args => [] }) {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a) assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = [] a = []
IO.foreach(t.path, {:open_args => [] }) {|x| a << x } IO.foreach(t.path, {:open_args => ["r"] }) {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a) assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = [] a = []
IO.foreach(t.path, {:open_args => ["r"] }) {|x| a << x } IO.foreach(t.path, "b") {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a) assert_equal(["foo\nb", "ar\nb", "az\n"], a)
a = [] a = []
IO.foreach(t.path, "b") {|x| a << x } IO.foreach(t.path, 3) {|x| a << x }
assert_equal(["foo\nb", "ar\nb", "az\n"], a) assert_equal(["foo", "\n", "bar", "\n", "baz", "\n"], a)
a = [] a = []
IO.foreach(t.path, 3) {|x| a << x } IO.foreach(t.path, "b", 3) {|x| a << x }
assert_equal(["foo", "\n", "bar", "\n", "baz", "\n"], a) assert_equal(["foo", "\nb", "ar\n", "b", "az\n"], a)
a = [] bug = '[ruby-dev:31525]'
IO.foreach(t.path, "b", 3) {|x| a << x } assert_raise(ArgumentError, bug) {IO.foreach}
assert_equal(["foo", "\nb", "ar\n", "b", "az\n"], a)
bug = '[ruby-dev:31525]' a = nil
assert_raise(ArgumentError, bug) {IO.foreach} assert_nothing_raised(ArgumentError, bug) {a = IO.foreach(t.path).to_a}
assert_equal(["foo\n", "bar\n", "baz\n"], a, bug)
a = nil bug6054 = '[ruby-dev:45267]'
assert_nothing_raised(ArgumentError, bug) {a = IO.foreach(t.path).to_a} e = assert_raise(IOError, bug6054) {IO.foreach(t.path, mode:"w").next}
assert_equal(["foo\n", "bar\n", "baz\n"], a, bug) assert_match(/not opened for reading/, e.message, bug6054)
}
bug6054 = '[ruby-dev:45267]'
e = assert_raise(IOError, bug6054) {IO.foreach(t.path, mode:"w").next}
assert_match(/not opened for reading/, e.message, bug6054)
end end
def test_s_readlines def test_s_readlines
t = make_tempfile make_tempfile {|t|
assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path))
assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path)) assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b")) assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2))
assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2)) assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2)) }
end end
def test_printf def test_printf
@ -1768,9 +1779,11 @@ End
end end
def test_print def test_print
t = make_tempfile make_tempfile {|t|
assert_in_out_err(["-", t.path],
assert_in_out_err(["-", t.path], "print while $<.gets", %w(foo bar baz), []) "print while $<.gets",
%w(foo bar baz), [])
}
end end
def test_print_separators def test_print_separators
@ -1835,30 +1848,32 @@ End
def test_initialize def test_initialize
return unless defined?(Fcntl::F_GETFL) return unless defined?(Fcntl::F_GETFL)
t = make_tempfile make_tempfile {|t|
fd = IO.sysopen(t.path, "w") fd = IO.sysopen(t.path, "w")
assert_kind_of(Integer, fd) assert_kind_of(Integer, fd)
%w[r r+ w+ a+].each do |mode| %w[r r+ w+ a+].each do |mode|
assert_raise(Errno::EINVAL, "#{mode} [ruby-dev:38571]") {IO.new(fd, mode)} assert_raise(Errno::EINVAL, "#{mode} [ruby-dev:38571]") {IO.new(fd, mode)}
end end
f = IO.new(fd, "w") f = IO.new(fd, "w")
f.write("FOO\n") f.write("FOO\n")
f.close f.close
assert_equal("FOO\n", File.read(t.path)) assert_equal("FOO\n", File.read(t.path))
}
end end
def test_reinitialize def test_reinitialize
t = make_tempfile make_tempfile {|t|
f = open(t.path) f = open(t.path)
begin begin
assert_raise(RuntimeError) do assert_raise(RuntimeError) do
f.instance_eval { initialize } f.instance_eval { initialize }
end
ensure
f.close
end end
ensure }
f.close
end
end end
def test_new_with_block def test_new_with_block
@ -1884,11 +1899,11 @@ End
end end
def test_s_read def test_s_read
t = make_tempfile make_tempfile {|t|
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
assert_equal("foo\nbar\nbaz\n", File.read(t.path)) assert_equal("foo\nba", File.read(t.path, 6))
assert_equal("foo\nba", File.read(t.path, 6)) assert_equal("bar\n", File.read(t.path, 4, 4))
assert_equal("bar\n", File.read(t.path, 4, 4)) }
end end
def test_uninitialized def test_uninitialized
@ -1916,14 +1931,16 @@ End
end end
def test_tainted def test_tainted
t = make_tempfile make_tempfile {|t|
assert(File.read(t.path, 4).tainted?, '[ruby-dev:38826]') assert(File.read(t.path, 4).tainted?, '[ruby-dev:38826]')
assert(File.open(t.path) {|f| f.read(4)}.tainted?, '[ruby-dev:38826]') assert(File.open(t.path) {|f| f.read(4)}.tainted?, '[ruby-dev:38826]')
}
end end
def test_binmode_after_closed def test_binmode_after_closed
t = make_tempfile make_tempfile {|t|
assert_raise(IOError) {t.binmode} assert_raise(IOError) {t.binmode}
}
end end
def test_threaded_flush def test_threaded_flush
@ -1945,17 +1962,19 @@ End
def test_flush_in_finalizer1 def test_flush_in_finalizer1
require 'tempfile' require 'tempfile'
bug3910 = '[ruby-dev:42341]' bug3910 = '[ruby-dev:42341]'
t = Tempfile.new("bug3910") Tempfile.open("bug3910") {|t|
path = t.path path = t.path
t.close t.close
fds = [] fds = []
assert_nothing_raised(TypeError, bug3910) do assert_nothing_raised(TypeError, bug3910) do
500.times { 500.times {
f = File.open(path, "w") f = File.open(path, "w")
fds << f.fileno fds << f.fileno
f.print "hoge" f.print "hoge"
} }
end end
t.unlink
}
ensure ensure
GC.start GC.start
end end
@ -1963,75 +1982,83 @@ End
def test_flush_in_finalizer2 def test_flush_in_finalizer2
require 'tempfile' require 'tempfile'
bug3910 = '[ruby-dev:42341]' bug3910 = '[ruby-dev:42341]'
t = Tempfile.new("bug3910") Tempfile.open("bug3910") {|t|
path = t.path path = t.path
t.close t.close
1.times do 1.times do
io = open(path,"w") io = open(path,"w")
io.print "hoge" io.print "hoge"
end end
assert_nothing_raised(TypeError, bug3910) do assert_nothing_raised(TypeError, bug3910) do
GC.start GC.start
end end
t.unlink
}
end end
def test_readlines_limit_0 def test_readlines_limit_0
bug4024 = '[ruby-dev:42538]' bug4024 = '[ruby-dev:42538]'
t = make_tempfile make_tempfile {|t|
open(t.path, "r") do |io| open(t.path, "r") do |io|
assert_raise(ArgumentError, bug4024) do assert_raise(ArgumentError, bug4024) do
io.readlines(0) io.readlines(0)
end
end end
end }
end end
def test_each_line_limit_0 def test_each_line_limit_0
bug4024 = '[ruby-dev:42538]' bug4024 = '[ruby-dev:42538]'
t = make_tempfile make_tempfile {|t|
open(t.path, "r") do |io| open(t.path, "r") do |io|
assert_raise(ArgumentError, bug4024) do assert_raise(ArgumentError, bug4024) do
io.each_line(0).next io.each_line(0).next
end
end end
end }
end end
def test_advise def test_advise
tf = make_tempfile make_tempfile {|tf|
assert_raise(ArgumentError, "no arguments") { tf.advise } assert_raise(ArgumentError, "no arguments") { tf.advise }
%w{normal random sequential willneed dontneed noreuse}.map(&:to_sym).each do |adv| %w{normal random sequential willneed dontneed noreuse}.map(&:to_sym).each do |adv|
[[0,0], [0, 20], [400, 2]].each do |offset, len| [[0,0], [0, 20], [400, 2]].each do |offset, len|
open(tf.path) do |t| open(tf.path) do |t|
assert_equal(t.advise(adv, offset, len), nil) assert_equal(t.advise(adv, offset, len), nil)
assert_raise(ArgumentError, "superfluous arguments") do assert_raise(ArgumentError, "superfluous arguments") do
t.advise(adv, offset, len, offset) t.advise(adv, offset, len, offset)
end
assert_raise(TypeError, "wrong type for first argument") do
t.advise(adv.to_s, offset, len)
end
assert_raise(TypeError, "wrong type for last argument") do
t.advise(adv, offset, Array(len))
end
assert_raise(RangeError, "last argument too big") do
t.advise(adv, offset, 9999e99)
end
end end
assert_raise(TypeError, "wrong type for first argument") do assert_raise(IOError, "closed file") do
t.advise(adv.to_s, offset, len) make_tempfile {|tf2|
tf2.advise(adv.to_sym, offset, len)
}
end end
assert_raise(TypeError, "wrong type for last argument") do
t.advise(adv, offset, Array(len))
end
assert_raise(RangeError, "last argument too big") do
t.advise(adv, offset, 9999e99)
end
end
assert_raise(IOError, "closed file") do
make_tempfile.advise(adv.to_sym, offset, len)
end end
end end
end }
end end
def test_invalid_advise def test_invalid_advise
feature4204 = '[ruby-dev:42887]' feature4204 = '[ruby-dev:42887]'
tf = make_tempfile make_tempfile {|tf|
%w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv| %w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv|
[[0,0], [0, 20], [400, 2]].each do |offset, len| [[0,0], [0, 20], [400, 2]].each do |offset, len|
open(tf.path) do |t| open(tf.path) do |t|
assert_raise(NotImplementedError, feature4204) { t.advise(adv, offset, len) } assert_raise(NotImplementedError, feature4204) { t.advise(adv, offset, len) }
end
end end
end end
end }
end end
def test_fcntl_lock_linux def test_fcntl_lock_linux
@ -2064,6 +2091,7 @@ End
Process.kill :TERM, pid Process.kill :TERM, pid
Process.waitpid2(pid) Process.waitpid2(pid)
f.close(true)
end end
end end
@ -2110,6 +2138,7 @@ End
ensure ensure
IO.for_fd(fd).close IO.for_fd(fd).close
end end
f.unlink
end end
end end