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

ruby-changes:2062

From: ko1@a...
Date: 29 Sep 2007 01:52:04 +0900
Subject: [ruby-changes:2062] akr - Ruby:r13553 (trunk): don't generate temporary files under current directory.

akr	2007-09-29 01:51:41 +0900 (Sat, 29 Sep 2007)

  New Revision: 13553

  Modified files:
    trunk/test/dbm/test_dbm.rb
    trunk/test/gdbm/test_gdbm.rb
    trunk/test/ruby/test_file.rb
    trunk/test/ruby/test_system.rb
    trunk/test/ruby/test_whileuntil.rb
    trunk/test/scanf/test_scanf.rb
    trunk/test/scanf/test_scanfblocks.rb
    trunk/test/sdbm/test_sdbm.rb

  Log:
    don't generate temporary files under current directory.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_whileuntil.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_file.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_system.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/scanf/test_scanf.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/dbm/test_dbm.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/gdbm/test_gdbm.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/scanf/test_scanfblocks.rb?r1=13553&r2=13552
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/sdbm/test_sdbm.rb?r1=13553&r2=13552

Index: test/ruby/test_system.rb
===================================================================
--- test/ruby/test_system.rb	(revision 13552)
+++ test/ruby/test_system.rb	(revision 13553)
@@ -1,5 +1,6 @@
 require 'test/unit'
 require 'envutil'
+require 'tmpdir'
 
 class TestSystem < Test::Unit::TestCase
   def valid_syntax?(code, fname)
@@ -14,21 +15,23 @@
     assert_equal("foobar\n", `echo foobar`)
     assert_equal('foobar', `#{ruby} -e 'print "foobar"'`)
 
-    tmp = open("script_tmp", "w")
+    tmpfilename = "#{Dir.tmpdir}/ruby_script_tmp.#{$$}"
+
+    tmp = open(tmpfilename, "w")
     tmp.print "print $zzz\n";
     tmp.close
 
-    assert_equal('true', `#{ruby} -s script_tmp -zzz`)
-    assert_equal('555', `#{ruby} -s script_tmp -zzz=555`)
+    assert_equal('true', `#{ruby} -s #{tmpfilename} -zzz`)
+    assert_equal('555', `#{ruby} -s #{tmpfilename} -zzz=555`)
 
-    tmp = open("script_tmp", "w")
+    tmp = open(tmpfilename, "w")
     tmp.print "#! /usr/local/bin/ruby -s\n";
     tmp.print "print $zzz\n";
     tmp.close
 
-    assert_equal('678', `#{ruby} script_tmp -zzz=678`)
+    assert_equal('678', `#{ruby} #{tmpfilename} -zzz=678`)
 
-    tmp = open("script_tmp", "w")
+    tmp = open(tmpfilename, "w")
     tmp.print "this is a leading junk\n";
     tmp.print "#! /usr/local/bin/ruby -s\n";
     tmp.print "print $zzz\n";
@@ -36,24 +39,24 @@
     tmp.print "this is a trailing junk\n";
     tmp.close
 
-    assert_equal('', `#{ruby} -x script_tmp`)
-    assert_equal('555', `#{ruby} -x script_tmp -zzz=555`)
+    assert_equal('', `#{ruby} -x #{tmpfilename}`)
+    assert_equal('555', `#{ruby} -x #{tmpfilename} -zzz=555`)
 
-    tmp = open("script_tmp", "w")
+    tmp = open(tmpfilename, "w")
     for i in 1..5
       tmp.print i, "\n"
     end
     tmp.close
 
-    `#{ruby} -i.bak -pe '$_.sub!(/^[0-9]+$/){$&.to_i * 5}' script_tmp`
-    tmp = open("script_tmp", "r")
+    `#{ruby} -i.bak -pe '$_.sub!(/^[0-9]+$/){$&.to_i * 5}' #{tmpfilename}`
+    tmp = open(tmpfilename, "r")
     while tmp.gets
       assert_equal(0, $_.to_i % 5)
     end
     tmp.close
 
-    File.unlink "script_tmp" or `/bin/rm -f "script_tmp"`
-    File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"`
+    File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"`
+    File.unlink "#{tmpfilename}.bak" or `/bin/rm -f "#{tmpfilename}.bak"`
   end
 
   def test_syntax
Index: test/ruby/test_file.rb
===================================================================
--- test/ruby/test_file.rb	(revision 13552)
+++ test/ruby/test_file.rb	(revision 13553)
@@ -7,7 +7,7 @@
   # I don't know Ruby's spec about "unlink-before-close" exactly.
   # This test asserts current behaviour.
   def test_unlink_before_close
-    filename = File.basename(__FILE__) + ".#{$$}"
+    filename = Dir.tmpdir + '/' + File.basename(__FILE__) + ".#{$$}"
     w = File.open(filename, "w")
     w << "foo"
     w.close
Index: test/ruby/test_whileuntil.rb
===================================================================
--- test/ruby/test_whileuntil.rb	(revision 13552)
+++ test/ruby/test_whileuntil.rb	(revision 13553)
@@ -1,8 +1,11 @@
 require 'test/unit'
+require 'tmpdir'
 
 class TestWhileuntil < Test::Unit::TestCase
   def test_while
-    tmp = open("while_tmp", "w")
+    tmpfilename = "#{Dir.tmpdir}/ruby_while_tmp.#{$$}"
+
+    tmp = open(tmpfilename, "w")
     tmp.print "tvi925\n";
     tmp.print "tvi920\n";
     tmp.print "vt100\n";
@@ -10,7 +13,7 @@
     tmp.print "paper\n";
     tmp.close
 
-    tmp = open("while_tmp", "r")
+    tmp = open(tmpfilename, "r")
     assert_instance_of(File, tmp)
     
     while line = tmp.gets()
@@ -21,7 +24,7 @@
     assert_match(/vt100/, line)
     tmp.close
 
-    tmp = open("while_tmp", "r")
+    tmp = open(tmpfilename, "r")
     while line = tmp.gets()
       next if /vt100/ =~ line
       assert_no_match(/vt100/, line)
@@ -30,7 +33,7 @@
     assert_no_match(/vt100/, line)
     tmp.close
 
-    tmp = open("while_tmp", "r")
+    tmp = open(tmpfilename, "r")
     while line = tmp.gets()
       lastline = line
       line = line.gsub(/vt100/, 'VT100')
@@ -54,7 +57,7 @@
     end
     assert_equal(220, sum)
 
-    tmp = open("while_tmp", "r")
+    tmp = open(tmpfilename, "r")
     while line = tmp.gets()
       break if 3
       assert_no_match(/vt100/, line)
@@ -63,8 +66,8 @@
     end
     tmp.close
 
-    File.unlink "while_tmp" or `/bin/rm -f "while_tmp"`
-    assert(!File.exist?("while_tmp"))
+    File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"`
+    assert(!File.exist?(tmpfilename))
   end
 
   def test_until
Index: test/sdbm/test_sdbm.rb
===================================================================
--- test/sdbm/test_sdbm.rb	(revision 13552)
+++ test/sdbm/test_sdbm.rb	(revision 13553)
@@ -1,4 +1,5 @@
 require 'test/unit'
+require 'tmpdir'
 
 begin
   require 'sdbm'
@@ -7,7 +8,9 @@
 
 class TestSDBM < Test::Unit::TestCase
   def setup
-    @path = "tmptest_sdbm_"
+    @tmpdir = Dir.tmpdir
+    @prefix = "tmptest_sdbm_#{$$}"
+    @path = "#{@tmpdir}/#{@prefix}_"
     assert_instance_of(SDBM, @sdbm = SDBM.new(@path))
   end
   def teardown
@@ -15,8 +18,8 @@
     ObjectSpace.each_object(SDBM) do |obj|
       obj.close unless obj.closed?
     end
-    File.delete *Dir.glob("tmptest_sdbm*").to_a
-    p Dir.glob("tmptest_sdbm*") if $DEBUG
+    File.delete *Dir.glob("#{@tmpdir}/#{@prefix}*").to_a
+    p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
   end
 
   def check_size(expect, sdbm=@sdbm)
@@ -47,26 +50,26 @@
   def test_s_new_has_no_block
     # SDBM.new ignore the block
     foo = true
-    assert_instance_of(SDBM, sdbm = SDBM.new("tmptest_sdbm") { foo = false })
+    assert_instance_of(SDBM, sdbm = SDBM.new("#{@tmpdir}/#{@prefix}") { foo = false })
     assert_equal(foo, true)
     assert_nil(sdbm.close)
   end
   def test_s_open_no_create
-    assert_nil(sdbm = SDBM.open("tmptest_sdbm", nil))
+    assert_nil(sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", nil))
   ensure
     sdbm.close if sdbm
   end
   def test_s_open_with_block
-    assert_equal(SDBM.open("tmptest_sdbm") { :foo }, :foo)
+    assert_equal(SDBM.open("#{@tmpdir}/#{@prefix}") { :foo }, :foo)
   end
 =begin
   # Is it guaranteed on many OS?
   def test_s_open_lock_one_process
     # locking on one process
-    assert_instance_of(SDBM, sdbm  = SDBM.open("tmptest_sdbm", 0644))
+    assert_instance_of(SDBM, sdbm  = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
     assert_raise(Errno::EWOULDBLOCK) {
       begin
-	SDBM.open("tmptest_sdbm", 0644)
+	SDBM.open("#{@tmpdir}/#{@prefix}", 0644)
       rescue Errno::EAGAIN
 	raise Errno::EWOULDBLOCK
       end
@@ -82,7 +85,7 @@
     return unless have_fork?	# snip this test
 
     pid = fork() {
-      assert_instance_of(SDBM, sdbm  = SDBM.open("tmptest_sdbm", 0644,
+      assert_instance_of(SDBM, sdbm  = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
 						SDBM::NOLOCK))
       sleep 2
     }
@@ -90,17 +93,17 @@
     begin
       sdbm2 = nil
       assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
-	assert_instance_of(SDBM, sdbm2 = SDBM.open("tmptest_sdbm", 0644))
+	assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
       }
     ensure
       Process.wait pid
       sdbm2.close if sdbm2
     end
 
-    p Dir.glob("tmptest_sdbm*") if $DEBUG
+    p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
 
     pid = fork() {
-      assert_instance_of(SDBM, sdbm  = SDBM.open("tmptest_sdbm", 0644))
+      assert_instance_of(SDBM, sdbm  = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
       sleep 2
     }
     begin
@@ -108,7 +111,7 @@
       sdbm2 = nil
       assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
 	# this test is failed on Cygwin98 (???)
-	assert_instance_of(SDBM, sdbm2 = SDBM.open("tmptest_sdbm", 0644,
+	assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
 						   SDBM::NOLOCK))
       }
     ensure
@@ -118,15 +121,15 @@
   end
 
   def test_s_open_error
-    assert_instance_of(SDBM, sdbm = SDBM.open("tmptest_sdbm", 0))
+    assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0))
     assert_raise(Errno::EACCES) {
-      SDBM.open("tmptest_sdbm", 0)
+      SDBM.open("#{@tmpdir}/#{@prefix}", 0)
     }
     sdbm.close
   end
 
   def test_close
-    assert_instance_of(SDBM, sdbm = SDBM.open("tmptest_sdbm"))
+    assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}"))
     assert_nil(sdbm.close)
 
     # closed SDBM file
Index: test/scanf/test_scanfblocks.rb
===================================================================
--- test/scanf/test_scanfblocks.rb	(revision 13552)
+++ test/scanf/test_scanfblocks.rb	(revision 13553)
@@ -7,6 +7,7 @@
 
 require 'test/unit'
 require 'scanf'
+require 'tmpdir'
 
 class TestScanfBlock < Test::Unit::TestCase
 
@@ -49,8 +50,8 @@
   end
 
   def test_io1
-    File.open("iotest.dat", "w") { |fh| fh.puts(@str) }
-    fh = File.open("iotest.dat", "rb")
+    File.open("#{Dir.tmpdir}/iotest.dat", "w") { |fh| fh.puts(@str) }
+    fh = File.open("#{Dir.tmpdir}/iotest.dat", "rb")
     res = fh.scanf("%s%d") { |name, year| "#{name} was born in #{year}." }
 
     assert_equal(
@@ -61,18 +62,18 @@
       "Brahms was born in 1833." ],res)
     fh.close
   ensure
-    File.delete("iotest.dat")  
+    File.delete("#{Dir.tmpdir}/iotest.dat")  
     end
 
   def test_io2
-    File.open("iotest.dat", "w").close
-    fh = File.open("iotest.dat","rb")
+    File.open("#{Dir.tmpdir}/iotest.dat", "w").close
+    fh = File.open("#{Dir.tmpdir}/iotest.dat","rb")
     assert_equal(fh.scanf("") {}, [])
     fh.seek(0)
     assert_equal(fh.scanf("%d%f%s") {}, [])
     fh.close
   ensure
-    File.delete("iotest.dat")  
+    File.delete("#{Dir.tmpdir}/iotest.dat")  
   end
 
 end
Index: test/scanf/test_scanf.rb
===================================================================
--- test/scanf/test_scanf.rb	(revision 13552)
+++ test/scanf/test_scanf.rb	(revision 13553)
@@ -7,6 +7,7 @@
 
 require 'scanf.rb'
 require 'test/unit'
+require 'tmpdir'
 
 # Comment out either of these lines to skip those tests.
 
@@ -295,15 +296,17 @@
 class TestIOScanf
   include Scanf
   extend ScanfTests
+
+  tmpfilename = "#{Dir.tmpdir}/iotest.dat"
   
   i = 1
   self.tests.each do |test|
     define_method("test_#{i}") do ||
-      File.open("iotest.dat", "w") {|fh| fh.print test[1]}
-      File.open("iotest.dat", "r") { |fh|
+      File.open(tmpfilename, "w") {|fh| fh.print test[1]}
+      File.open(tmpfilename, "r") { |fh|
         assert_equal(test[2], fh.scanf(test[0]))
       }
-      File.delete("iotest.dat")
+      File.delete(tmpfilename)
     end
     i += 1
   end
Index: test/dbm/test_dbm.rb
===================================================================
--- test/dbm/test_dbm.rb	(revision 13552)
+++ test/dbm/test_dbm.rb	(revision 13553)
@@ -1,4 +1,5 @@
 require 'test/unit'
+require 'tmpdir'
 
 begin
   require 'dbm'
@@ -27,17 +28,19 @@
     SYSTEM = uname_s
 
     def setup
-      @path = "tmptest_dbm_"
+      @tmpdir = Dir.tmpdir
+      @prefix = "tmptest_dbm_#{$$}"
+      @path = "#{@tmpdir}/#{@prefix}_"
       assert_instance_of(DBM, @dbm = DBM.new(@path))
 
       # prepare to make readonly DBM file
-      DBM.open("tmptest_dbm_rdonly") {|dbm|
+      DBM.open("#{@tmpdir}/#{@prefix}_rdonly") {|dbm|
         dbm['foo'] = 'FOO'
       }
       
-      File.chmod(0400, *Dir.glob("tmptest_dbm_rdonly.*"))
+      File.chmod(0400, *Dir.glob("#{@tmpdir}/#{@prefix}_rdonly.*"))
 
-      assert_instance_of(DBM, @dbm_rdonly = DBM.new("tmptest_dbm_rdonly", nil))
+      assert_instance_of(DBM, @dbm_rdonly = DBM.new("#{@tmpdir}/#{@prefix}_rdonly", nil))
     end
     def teardown
       assert_nil(@dbm.close)
@@ -45,8 +48,8 @@
       ObjectSpace.each_object(DBM) do |obj|
         obj.close unless obj.closed?
       end
-      File.delete *Dir.glob("tmptest_dbm*").to_a
-      p Dir.glob("tmptest_dbm*") if $DEBUG
+      File.delete *Dir.glob("#{@tmpdir}/#{@prefix}*").to_a
+      p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
     end
 
     def check_size(expect, dbm=@dbm)
@@ -73,21 +76,21 @@
     def test_s_new_has_no_block
       # DBM.new ignore the block
       foo = true
-      assert_instance_of(DBM, dbm = DBM.new("tmptest_dbm") { foo = false })
+      assert_instance_of(DBM, dbm = DBM.new("#{@tmpdir}/#{@prefix}") { foo = false })
       assert_equal(foo, true)
       assert_nil(dbm.close)
     end
     def test_s_open_no_create
-      assert_nil(dbm = DBM.open("tmptest_dbm", nil))
+      assert_nil(dbm = DBM.open("#{@tmpdir}/#{@prefix}", nil))
     ensure
       dbm.close if dbm
     end
     def test_s_open_with_block
-      assert_equal(DBM.open("tmptest_dbm") { :foo }, :foo)
+      assert_equal(DBM.open("#{@tmpdir}/#{@prefix}") { :foo }, :foo)
     end
 
     def test_close
-      assert_instance_of(DBM, dbm = DBM.open("tmptest_dbm"))
+      assert_instance_of(DBM, dbm = DBM.open("#{@tmpdir}/#{@prefix}"))
       assert_nil(dbm.close)
 
       # closed DBM file
@@ -498,7 +501,7 @@
     TMPROOT = "#{Dir.tmpdir}/ruby-dbm.#{$$}"
 
     def setup
-      Dir.mkdir TMPROOT
+      Dir.mkdir TMPROOT, 0755
     end
 
     def teardown
Index: test/gdbm/test_gdbm.rb
===================================================================
--- test/gdbm/test_gdbm.rb	(revision 13552)
+++ test/gdbm/test_gdbm.rb	(revision 13553)
@@ -1,4 +1,5 @@
 require 'test/unit'
+require 'tmpdir'
 
 begin
   require 'gdbm'
@@ -27,14 +28,16 @@
     SYSTEM = uname_s
 
     def setup
-      @path = "tmptest_gdbm_"
+      @tmpdir = Dir.tmpdir
+      @prefix = "tmptest_gdbm_#{$$}"
+      @path = "#{@tmpdir}/#{@prefix}_"
       assert_instance_of(GDBM, @gdbm = GDBM.new(@path))
 
       # prepare to make readonly GDBM file
-      GDBM.open("tmptest_gdbm_rdonly", 0400) {|gdbm|
+      GDBM.open("#{@tmpdir}/#{@prefix}_rdonly", 0400) {|gdbm|
         gdbm['foo'] = 'FOO'
       }
-      assert_instance_of(GDBM, @gdbm_rdonly = GDBM.new("tmptest_gdbm_rdonly", nil))
+      assert_instance_of(GDBM, @gdbm_rdonly = GDBM.new("#{@tmpdir}/#{@prefix}_rdonly", nil))
     end
     def teardown
       assert_nil(@gdbm.close)
@@ -42,8 +45,8 @@
       ObjectSpace.each_object(GDBM) do |obj|
         obj.close unless obj.closed?
       end
-      File.delete *Dir.glob("tmptest_gdbm*").to_a
-      p Dir.glob("tmptest_gdbm*") if $DEBUG
+      File.delete *Dir.glob("#{@tmpdir}/#{@prefix}*").to_a
+      p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
     end
 
     def check_size(expect, gdbm=@gdbm)
@@ -70,7 +73,7 @@
     def test_s_new_has_no_block
       # GDBM.new ignore the block
       foo = true
-      assert_instance_of(GDBM, gdbm = GDBM.new("tmptest_gdbm") { foo = false })
+      assert_instance_of(GDBM, gdbm = GDBM.new("#{@tmpdir}/#{@prefix}") { foo = false })
       assert_equal(foo, true)
       assert_nil(gdbm.close)
     end
@@ -79,54 +82,54 @@
 
       save_mask = File.umask(0)
       begin
-        assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm"))
+        assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}"))
         gdbm.close
-        assert_equal(File.stat("tmptest_gdbm").mode & 0777, 0666)
-        assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm2", 0644))
+        assert_equal(File.stat("#{@tmpdir}/#{@prefix}").mode & 0777, 0666)
+        assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}2", 0644))
         gdbm.close
-        assert_equal(File.stat("tmptest_gdbm2").mode & 0777, 0644)
+        assert_equal(File.stat("#{@tmpdir}/#{@prefix}2").mode & 0777, 0644)
       ensure
         File.umask save_mask
       end
     end
     def test_s_open_no_create
       # this test is failed on libgdbm 1.8.0
-      assert_nil(gdbm = GDBM.open("tmptest_gdbm", nil))
+      assert_nil(gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", nil))
     ensure
       gdbm.close if gdbm
     end
     def test_s_open_3rd_arg
-      assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm", 0644,
+      assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0644,
                                                 GDBM::FAST))
       gdbm.close
 
       # gdbm 1.8.0 specific
       if defined? GDBM::SYNC
-        assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm", 0644,
+        assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0644,
                                                   GDBM::SYNC))
         gdbm.close
       end
       # gdbm 1.8.0 specific
       if defined? GDBM::NOLOCK
-        assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm", 0644,
+        assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0644,
                                                   GDBM::NOLOCK))
         gdbm.close
       end
     end
     def test_s_open_with_block
-      assert_equal(GDBM.open("tmptest_gdbm") { :foo }, :foo)
+      assert_equal(GDBM.open("#{@tmpdir}/#{@prefix}") { :foo }, :foo)
     end
     def test_s_open_lock
       return unless have_fork?	# snip this test
       pid = fork() {
-        assert_instance_of(GDBM, gdbm  = GDBM.open("tmptest_gdbm", 0644))
+        assert_instance_of(GDBM, gdbm  = GDBM.open("#{@tmpdir}/#{@prefix}", 0644))
         sleep 2
       }
       begin
         sleep 1
         assert_raise(Errno::EWOULDBLOCK) {
           begin
-            assert_instance_of(GDBM, gdbm2 = GDBM.open("tmptest_gdbm", 0644))
+            assert_instance_of(GDBM, gdbm2 = GDBM.open("#{@tmpdir}/#{@prefix}", 0644))
           rescue Errno::EAGAIN, Errno::EACCES
             raise Errno::EWOULDBLOCK
           end
@@ -140,10 +143,10 @@
     # Is it guaranteed on many OS?
     def test_s_open_lock_one_process
       # locking on one process
-      assert_instance_of(GDBM, gdbm  = GDBM.open("tmptest_gdbm", 0644))
+      assert_instance_of(GDBM, gdbm  = GDBM.open("#{@tmpdir}/#{@prefix}", 0644))
       assert_raise(Errno::EWOULDBLOCK) {
         begin
-          GDBM.open("tmptest_gdbm", 0644)
+          GDBM.open("#{@tmpdir}/#{@prefix}", 0644)
         rescue Errno::EAGAIN
           raise Errno::EWOULDBLOCK
         end
@@ -159,7 +162,7 @@
       return unless have_fork?	# snip this test
 
       pid = fork() {
-        assert_instance_of(GDBM, gdbm  = GDBM.open("tmptest_gdbm", 0644,
+        assert_instance_of(GDBM, gdbm  = GDBM.open("#{@tmpdir}/#{@prefix}", 0644,
                                                   GDBM::NOLOCK))
         sleep 2
       }
@@ -167,17 +170,17 @@
       begin
         gdbm2 = nil
         assert_nothing_raised(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
-          assert_instance_of(GDBM, gdbm2 = GDBM.open("tmptest_gdbm", 0644))
+          assert_instance_of(GDBM, gdbm2 = GDBM.open("#{@tmpdir}/#{@prefix}", 0644))
         }
       ensure
         Process.wait pid
         gdbm2.close if gdbm2
       end
 
-      p Dir.glob("tmptest_gdbm*") if $DEBUG
+      p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
 
       pid = fork() {
-        assert_instance_of(GDBM, gdbm  = GDBM.open("tmptest_gdbm", 0644))
+        assert_instance_of(GDBM, gdbm  = GDBM.open("#{@tmpdir}/#{@prefix}", 0644))
         sleep 2
       }
       begin
@@ -185,7 +188,7 @@
         gdbm2 = nil
         assert_nothing_raised(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
           # this test is failed on Cygwin98 (???)
-          assert_instance_of(GDBM, gdbm2 = GDBM.open("tmptest_gdbm", 0644,
+          assert_instance_of(GDBM, gdbm2 = GDBM.open("#{@tmpdir}/#{@prefix}", 0644,
                                                      GDBM::NOLOCK))
         }
       ensure
@@ -195,15 +198,15 @@
     end
 
     def test_s_open_error
-      assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm", 0))
+      assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0))
       assert_raise(Errno::EACCES) {
-        GDBM.open("tmptest_gdbm", 0)
+        GDBM.open("#{@tmpdir}/#{@prefix}", 0)
       }
       gdbm.close
     end
 
     def test_close
-      assert_instance_of(GDBM, gdbm = GDBM.open("tmptest_gdbm"))
+      assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}"))
       assert_nil(gdbm.close)
 
       # closed GDBM file
@@ -592,10 +595,10 @@
     end
 
     def test_sync
-      assert_instance_of(GDBM, gdbm = GDBM.open('tmptest_gdbm', 0666, GDBM::FAST))
+      assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0666, GDBM::FAST))
       assert_equal(gdbm.sync, gdbm)
       gdbm.close
-      assert_instance_of(GDBM, gdbm = GDBM.open('tmptest_gdbm', 0666))
+      assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0666))
       assert_equal(gdbm.sync, gdbm)
       gdbm.close
     end
@@ -653,7 +656,7 @@
     TMPROOT = "#{Dir.tmpdir}/ruby-gdbm.#{$$}"
 
     def setup
-      Dir.mkdir TMPROOT
+      Dir.mkdir TMPROOT, 0755
     end
 
     def teardown

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

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