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:
parent
f0810814bd
commit
422e8d5adc
2 changed files with 352 additions and 319 deletions
|
@ -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>
|
||||
|
||||
* variable.c (rb_mod_class_variables): return inherited variables
|
||||
|
|
|
@ -205,7 +205,7 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_ungetbyte
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
t.open
|
||||
t.binmode
|
||||
t.ungetbyte(0x41)
|
||||
|
@ -224,6 +224,7 @@ class TestIO < Test::Unit::TestCase
|
|||
t.ungetbyte("\xe7\xb4\x85")
|
||||
assert_equal(-2, t.pos)
|
||||
assert_equal("\u7d05\u7389bar\n", t.gets)
|
||||
}
|
||||
end
|
||||
|
||||
def test_each_byte
|
||||
|
@ -237,23 +238,25 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_each_byte_with_seek
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
bug5119 = '[ruby-core:38609]'
|
||||
i = 0
|
||||
open(t.path) do |f|
|
||||
f.each_byte {i = f.pos}
|
||||
end
|
||||
assert_equal(12, i, bug5119)
|
||||
}
|
||||
end
|
||||
|
||||
def test_each_codepoint
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
bug2959 = '[ruby-core:28650]'
|
||||
a = ""
|
||||
File.open(t, 'rt') {|f|
|
||||
f.each_codepoint {|c| a << c}
|
||||
}
|
||||
assert_equal("foo\nbar\nbaz\n", a, bug2959)
|
||||
}
|
||||
end
|
||||
|
||||
def test_rubydev33072
|
||||
|
@ -1236,8 +1239,7 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_set_lineno
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
ruby("-e", <<-SRC, t.path) do |f|
|
||||
open(ARGV[0]) do |f|
|
||||
p $.
|
||||
|
@ -1268,6 +1270,7 @@ class TestIO < Test::Unit::TestCase
|
|||
r.gets; assert_equal(1001, $.)
|
||||
r.gets; assert_equal(1001, $.)
|
||||
end)
|
||||
}
|
||||
end
|
||||
|
||||
def test_readline
|
||||
|
@ -1414,7 +1417,7 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_pos
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
|
||||
open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
|
||||
f.write "Hello"
|
||||
|
@ -1426,11 +1429,12 @@ class TestIO < Test::Unit::TestCase
|
|||
f.write "Hello"
|
||||
assert_equal(5, f.pos)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_pos_with_getc
|
||||
bug6179 = '[ruby-core:43497]'
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
["", "t", "b"].each do |mode|
|
||||
open(t.path, "w#{mode}") do |f|
|
||||
f.write "0123456789\n"
|
||||
|
@ -1449,6 +1453,7 @@ class TestIO < Test::Unit::TestCase
|
|||
assert_equal '4', f.getc, "mode=r#{mode}"
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
|
@ -1478,8 +1483,7 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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)
|
||||
|
@ -1490,27 +1494,28 @@ class TestIO < Test::Unit::TestCase
|
|||
a.reverse_each {|c| f.ungetc c }
|
||||
assert_raise(IOError) { f.sysseek(1) }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_syswrite
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
open(t.path, "w") do |f|
|
||||
o = Object.new
|
||||
def o.to_s; "FOO\n"; end
|
||||
f.syswrite(o)
|
||||
end
|
||||
assert_equal("FOO\n", File.read(t.path))
|
||||
}
|
||||
end
|
||||
|
||||
def test_sysread
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
open(t.path) do |f|
|
||||
a = [f.getc, f.getc, f.getc]
|
||||
a.reverse_each {|c| f.ungetc c }
|
||||
assert_raise(IOError) { f.sysread(1) }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_sysread_with_not_empty_buffer
|
||||
|
@ -1524,8 +1529,7 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_flag
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
assert_raise(ArgumentError) do
|
||||
open(t.path, "z") { }
|
||||
end
|
||||
|
@ -1533,11 +1537,11 @@ class TestIO < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError) do
|
||||
open(t.path, "rr") { }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_sysopen
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
fd = IO.sysopen(t.path)
|
||||
assert_kind_of(Integer, fd)
|
||||
f = IO.for_fd(fd)
|
||||
|
@ -1559,6 +1563,7 @@ class TestIO < Test::Unit::TestCase
|
|||
f = IO.for_fd(fd)
|
||||
assert_equal("FOO\n", f.read)
|
||||
f.close
|
||||
}
|
||||
end
|
||||
|
||||
def try_fdopen(fd, autoclose = true, level = 50)
|
||||
|
@ -1577,7 +1582,8 @@ class TestIO < Test::Unit::TestCase
|
|||
feature2250 = '[ruby-core:26222]'
|
||||
pre = 'ft2250'
|
||||
|
||||
t = Tempfile.new(pre)
|
||||
Dir.mktmpdir {|d|
|
||||
t = open("#{d}/#{pre}", "w")
|
||||
f = IO.for_fd(t.fileno)
|
||||
assert_equal(true, f.autoclose?)
|
||||
f.autoclose = false
|
||||
|
@ -1585,13 +1591,14 @@ class TestIO < Test::Unit::TestCase
|
|||
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)
|
||||
assert_equal(false, f.autoclose?)
|
||||
f.autoclose = true
|
||||
assert_equal(true, f.autoclose?)
|
||||
f.close
|
||||
assert_raise(Errno::EBADF, feature2250) {t.close}
|
||||
}
|
||||
end
|
||||
|
||||
def test_autoclose_true_closed_by_finalizer
|
||||
|
@ -1609,6 +1616,8 @@ class TestIO < Test::Unit::TestCase
|
|||
rescue WeakRef::RefError
|
||||
assert_raise(Errno::EBADF, feature2250) {t.close}
|
||||
end
|
||||
ensure
|
||||
t.unlink
|
||||
end
|
||||
|
||||
def test_autoclose_false_closed_by_finalizer
|
||||
|
@ -1623,6 +1632,8 @@ class TestIO < Test::Unit::TestCase
|
|||
rescue WeakRef::RefError
|
||||
assert_nothing_raised(Errno::EBADF, feature2250) {t.close}
|
||||
end
|
||||
ensure
|
||||
t.unlink
|
||||
end
|
||||
|
||||
def test_open_redirect
|
||||
|
@ -1645,8 +1656,7 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_reopen
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
with_pipe do |r, w|
|
||||
assert_raise(SecurityError) do
|
||||
safe_4 { r.reopen(t.path) }
|
||||
|
@ -1687,6 +1697,7 @@ class TestIO < Test::Unit::TestCase
|
|||
f2.close
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_reopen_inherit
|
||||
|
@ -1707,8 +1718,7 @@ End
|
|||
IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x }
|
||||
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)
|
||||
|
@ -1747,15 +1757,16 @@ End
|
|||
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
|
||||
|
||||
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\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", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
|
||||
}
|
||||
end
|
||||
|
||||
def test_printf
|
||||
|
@ -1768,9 +1779,11 @@ End
|
|||
end
|
||||
|
||||
def test_print
|
||||
t = make_tempfile
|
||||
|
||||
assert_in_out_err(["-", t.path], "print while $<.gets", %w(foo bar baz), [])
|
||||
make_tempfile {|t|
|
||||
assert_in_out_err(["-", t.path],
|
||||
"print while $<.gets",
|
||||
%w(foo bar baz), [])
|
||||
}
|
||||
end
|
||||
|
||||
def test_print_separators
|
||||
|
@ -1835,7 +1848,7 @@ End
|
|||
def test_initialize
|
||||
return unless defined?(Fcntl::F_GETFL)
|
||||
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
|
||||
fd = IO.sysopen(t.path, "w")
|
||||
assert_kind_of(Integer, fd)
|
||||
|
@ -1847,10 +1860,11 @@ End
|
|||
f.close
|
||||
|
||||
assert_equal("FOO\n", File.read(t.path))
|
||||
}
|
||||
end
|
||||
|
||||
def test_reinitialize
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
f = open(t.path)
|
||||
begin
|
||||
assert_raise(RuntimeError) do
|
||||
|
@ -1859,6 +1873,7 @@ End
|
|||
ensure
|
||||
f.close
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_new_with_block
|
||||
|
@ -1884,11 +1899,11 @@ End
|
|||
end
|
||||
|
||||
def test_s_read
|
||||
t = make_tempfile
|
||||
|
||||
make_tempfile {|t|
|
||||
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
|
||||
assert_equal("foo\nba", File.read(t.path, 6))
|
||||
assert_equal("bar\n", File.read(t.path, 4, 4))
|
||||
}
|
||||
end
|
||||
|
||||
def test_uninitialized
|
||||
|
@ -1916,14 +1931,16 @@ End
|
|||
end
|
||||
|
||||
def test_tainted
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
assert(File.read(t.path, 4).tainted?, '[ruby-dev:38826]')
|
||||
assert(File.open(t.path) {|f| f.read(4)}.tainted?, '[ruby-dev:38826]')
|
||||
}
|
||||
end
|
||||
|
||||
def test_binmode_after_closed
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
assert_raise(IOError) {t.binmode}
|
||||
}
|
||||
end
|
||||
|
||||
def test_threaded_flush
|
||||
|
@ -1945,7 +1962,7 @@ End
|
|||
def test_flush_in_finalizer1
|
||||
require 'tempfile'
|
||||
bug3910 = '[ruby-dev:42341]'
|
||||
t = Tempfile.new("bug3910")
|
||||
Tempfile.open("bug3910") {|t|
|
||||
path = t.path
|
||||
t.close
|
||||
fds = []
|
||||
|
@ -1956,6 +1973,8 @@ End
|
|||
f.print "hoge"
|
||||
}
|
||||
end
|
||||
t.unlink
|
||||
}
|
||||
ensure
|
||||
GC.start
|
||||
end
|
||||
|
@ -1963,7 +1982,7 @@ End
|
|||
def test_flush_in_finalizer2
|
||||
require 'tempfile'
|
||||
bug3910 = '[ruby-dev:42341]'
|
||||
t = Tempfile.new("bug3910")
|
||||
Tempfile.open("bug3910") {|t|
|
||||
path = t.path
|
||||
t.close
|
||||
1.times do
|
||||
|
@ -1973,30 +1992,34 @@ End
|
|||
assert_nothing_raised(TypeError, bug3910) do
|
||||
GC.start
|
||||
end
|
||||
t.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_readlines_limit_0
|
||||
bug4024 = '[ruby-dev:42538]'
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
open(t.path, "r") do |io|
|
||||
assert_raise(ArgumentError, bug4024) do
|
||||
io.readlines(0)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_each_line_limit_0
|
||||
bug4024 = '[ruby-dev:42538]'
|
||||
t = make_tempfile
|
||||
make_tempfile {|t|
|
||||
open(t.path, "r") do |io|
|
||||
assert_raise(ArgumentError, bug4024) do
|
||||
io.each_line(0).next
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_advise
|
||||
tf = make_tempfile
|
||||
make_tempfile {|tf|
|
||||
assert_raise(ArgumentError, "no arguments") { tf.advise }
|
||||
%w{normal random sequential willneed dontneed noreuse}.map(&:to_sym).each do |adv|
|
||||
[[0,0], [0, 20], [400, 2]].each do |offset, len|
|
||||
|
@ -2016,15 +2039,18 @@ End
|
|||
end
|
||||
end
|
||||
assert_raise(IOError, "closed file") do
|
||||
make_tempfile.advise(adv.to_sym, offset, len)
|
||||
make_tempfile {|tf2|
|
||||
tf2.advise(adv.to_sym, offset, len)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_invalid_advise
|
||||
feature4204 = '[ruby-dev:42887]'
|
||||
tf = make_tempfile
|
||||
make_tempfile {|tf|
|
||||
%w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv|
|
||||
[[0,0], [0, 20], [400, 2]].each do |offset, len|
|
||||
open(tf.path) do |t|
|
||||
|
@ -2032,6 +2058,7 @@ End
|
|||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_fcntl_lock_linux
|
||||
|
@ -2064,6 +2091,7 @@ End
|
|||
|
||||
Process.kill :TERM, pid
|
||||
Process.waitpid2(pid)
|
||||
f.close(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2110,6 +2138,7 @@ End
|
|||
ensure
|
||||
IO.for_fd(fd).close
|
||||
end
|
||||
f.unlink
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue