summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-10-24 05:55:26 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-10-24 05:55:26 +0000
commit5d2671d2bc4b0009d8d2b419369f80f9c2ada1e8 (patch)
treeff1df4fd9c26ddb398fd42dbc0b14353c5f23b25
parent124bdf881594b09dc5748d0dec4e27519aac5c68 (diff)
use Dir.mktmpdir.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/pathname/test_pathname.rb8
-rw-r--r--test/ruby/test_dir.rb12
-rw-r--r--test/ruby/test_file.rb30
3 files changed, 23 insertions, 27 deletions
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 206a0eb108..9bc780f6d3 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -287,16 +287,12 @@ class TestPathname < Test::Unit::TestCase
return
rescue TypeError
end
- dir = "#{Dir.tmpdir}/tst-pathname-#$$"
- Dir.mkdir(dir)
- begin
+ Dir.mktmpdir {|dir|
File.symlink("not-exist-target", "#{dir}/not-exist")
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
File.symlink("loop", "#{dir}/loop")
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop") }
- ensure
- FileUtils.rmtree(dir)
- end
+ }
end
def descend(path)
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 164f13f716..e3a24e8583 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -5,25 +5,23 @@ require 'fileutils'
class TestDir < Test::Unit::TestCase
- ROOT = File.join(Dir.tmpdir, "__test_dir__#{$$}")
-
def setup
- Dir.mkdir(ROOT)
+ @root = Dir.mktmpdir
for i in ?a..?z
if i.ord % 2 == 0
- FileUtils.touch(File.join(ROOT, i))
+ FileUtils.touch(File.join(@root, i))
else
- FileUtils.mkdir(File.join(ROOT, i))
+ FileUtils.mkdir(File.join(@root, i))
end
end
end
def teardown
- FileUtils.rm_rf ROOT if File.directory?(ROOT)
+ FileUtils.remove_entry_secure @root if File.directory?(@root)
end
def test_seek
- dir = Dir.open(ROOT)
+ dir = Dir.open(@root)
begin
cache = []
loop do
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb
index 2670933de2..49203ab2ea 100644
--- a/test/ruby/test_file.rb
+++ b/test/ruby/test_file.rb
@@ -7,21 +7,23 @@ class TestFile < Test::Unit::TestCase
# I don't know Ruby's spec about "unlink-before-close" exactly.
# This test asserts current behaviour.
def test_unlink_before_close
- filename = Dir.tmpdir + '/' + File.basename(__FILE__) + ".#{$$}"
- w = File.open(filename, "w")
- w << "foo"
- w.close
- r = File.open(filename, "r")
- begin
- if /(mswin|bccwin|mingw|emx)/ =~ RUBY_PLATFORM
- assert_raise(Errno::EACCES) {File.unlink(filename)}
- else
- assert_nothing_raised {File.unlink(filename)}
+ Dir.mktmpdir {|tmpdir|
+ filename = tmpdir + '/' + File.basename(__FILE__) + ".#{$$}"
+ w = File.open(filename, "w")
+ w << "foo"
+ w.close
+ r = File.open(filename, "r")
+ begin
+ if /(mswin|bccwin|mingw|emx)/ =~ RUBY_PLATFORM
+ assert_raise(Errno::EACCES) {File.unlink(filename)}
+ else
+ assert_nothing_raised {File.unlink(filename)}
+ end
+ ensure
+ r.close
+ File.unlink(filename) if File.exist?(filename)
end
- ensure
- r.close
- File.unlink(filename) if File.exist?(filename)
- end
+ }
end
include TestEOF