mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
use Dir.mktmpdir.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
124bdf8815
commit
5d2671d2bc
3 changed files with 23 additions and 27 deletions
|
@ -287,16 +287,12 @@ class TestPathname < Test::Unit::TestCase
|
||||||
return
|
return
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
end
|
end
|
||||||
dir = "#{Dir.tmpdir}/tst-pathname-#$$"
|
Dir.mktmpdir {|dir|
|
||||||
Dir.mkdir(dir)
|
|
||||||
begin
|
|
||||||
File.symlink("not-exist-target", "#{dir}/not-exist")
|
File.symlink("not-exist-target", "#{dir}/not-exist")
|
||||||
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
|
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
|
||||||
File.symlink("loop", "#{dir}/loop")
|
File.symlink("loop", "#{dir}/loop")
|
||||||
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop") }
|
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop") }
|
||||||
ensure
|
}
|
||||||
FileUtils.rmtree(dir)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def descend(path)
|
def descend(path)
|
||||||
|
|
|
@ -5,25 +5,23 @@ require 'fileutils'
|
||||||
|
|
||||||
class TestDir < Test::Unit::TestCase
|
class TestDir < Test::Unit::TestCase
|
||||||
|
|
||||||
ROOT = File.join(Dir.tmpdir, "__test_dir__#{$$}")
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Dir.mkdir(ROOT)
|
@root = Dir.mktmpdir
|
||||||
for i in ?a..?z
|
for i in ?a..?z
|
||||||
if i.ord % 2 == 0
|
if i.ord % 2 == 0
|
||||||
FileUtils.touch(File.join(ROOT, i))
|
FileUtils.touch(File.join(@root, i))
|
||||||
else
|
else
|
||||||
FileUtils.mkdir(File.join(ROOT, i))
|
FileUtils.mkdir(File.join(@root, i))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
FileUtils.rm_rf ROOT if File.directory?(ROOT)
|
FileUtils.remove_entry_secure @root if File.directory?(@root)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_seek
|
def test_seek
|
||||||
dir = Dir.open(ROOT)
|
dir = Dir.open(@root)
|
||||||
begin
|
begin
|
||||||
cache = []
|
cache = []
|
||||||
loop do
|
loop do
|
||||||
|
|
|
@ -7,7 +7,8 @@ class TestFile < Test::Unit::TestCase
|
||||||
# I don't know Ruby's spec about "unlink-before-close" exactly.
|
# I don't know Ruby's spec about "unlink-before-close" exactly.
|
||||||
# This test asserts current behaviour.
|
# This test asserts current behaviour.
|
||||||
def test_unlink_before_close
|
def test_unlink_before_close
|
||||||
filename = Dir.tmpdir + '/' + File.basename(__FILE__) + ".#{$$}"
|
Dir.mktmpdir {|tmpdir|
|
||||||
|
filename = tmpdir + '/' + File.basename(__FILE__) + ".#{$$}"
|
||||||
w = File.open(filename, "w")
|
w = File.open(filename, "w")
|
||||||
w << "foo"
|
w << "foo"
|
||||||
w.close
|
w.close
|
||||||
|
@ -22,6 +23,7 @@ class TestFile < Test::Unit::TestCase
|
||||||
r.close
|
r.close
|
||||||
File.unlink(filename) if File.exist?(filename)
|
File.unlink(filename) if File.exist?(filename)
|
||||||
end
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
include TestEOF
|
include TestEOF
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue