[前][次][番号順一覧][スレッド一覧]

ruby-changes:2270

From: ko1@a...
Date: 24 Oct 2007 14:55:58 +0900
Subject: [ruby-changes:2270] akr - Ruby:r13761 (trunk): use Dir.mktmpdir.

akr	2007-10-24 14:55:26 +0900 (Wed, 24 Oct 2007)

  New Revision: 13761

  Modified files:
    trunk/test/pathname/test_pathname.rb
    trunk/test/ruby/test_dir.rb
    trunk/test/ruby/test_file.rb

  Log:
    use Dir.mktmpdir.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_file.rb?r1=13761&r2=13760
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/pathname/test_pathname.rb?r1=13761&r2=13760
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_dir.rb?r1=13761&r2=13760

Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 13760)
+++ test/ruby/test_dir.rb	(revision 13761)
@@ -5,25 +5,23 @@
 
 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
Index: test/ruby/test_file.rb
===================================================================
--- test/ruby/test_file.rb	(revision 13760)
+++ test/ruby/test_file.rb	(revision 13761)
@@ -7,21 +7,23 @@
   # 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
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 13760)
+++ test/pathname/test_pathname.rb	(revision 13761)
@@ -287,16 +287,12 @@
       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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]