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

ruby-changes:21939

From: naruse <ko1@a...>
Date: Thu, 8 Dec 2011 23:52:23 +0900 (JST)
Subject: [ruby-changes:21939] naruse:r33988 (trunk): Generate temporary file in tmpdir.

naruse	2011-12-08 23:52:13 +0900 (Thu, 08 Dec 2011)

  New Revision: 33988

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33988

  Log:
    Generate temporary file in tmpdir.

  Modified files:
    trunk/test/test_pstore.rb

Index: test/test_pstore.rb
===================================================================
--- test/test_pstore.rb	(revision 33987)
+++ test/test_pstore.rb	(revision 33988)
@@ -1,10 +1,11 @@
 require 'test/unit'
 require 'pstore'
+require 'tmpdir'
 require_relative 'ruby/envutil'
 
 class PStoreTest < Test::Unit::TestCase
   def setup
-    @pstore_file = "pstore.tmp.#{Process.pid}"
+    @pstore_file = File.join(Dir.tmpdir, "pstore.tmp.#{Process.pid}")
     @pstore = PStore.new(@pstore_file)
   end
 
@@ -87,7 +88,7 @@
       @pstore.transaction {}
     end
     assert_block do
-      pstore = PStore.new("pstore.tmp2.#{Process.pid}",true)
+      pstore = PStore.new(second_file, true)
       flag = false
       Thread.new do
         pstore.transaction do
@@ -98,18 +99,21 @@
       end
       until flag; end
       pstore.transaction { pstore[:foo] == "bar" }
-      File.unlink("pstore.tmp2.#{Process.pid}") rescue nil
     end
+  ensure
+    File.unlink(second_file) rescue nil
   end
 
   def test_nested_transaction_raises_error
     assert_raise(PStore::Error) do
       @pstore.transaction { @pstore.transaction { } }
     end
-    pstore = PStore.new("pstore.tmp2.#{Process.pid}", true)
+    pstore = PStore.new(second_file, true)
     assert_raise(PStore::Error) do
       pstore.transaction { pstore.transaction { } }
     end
+  ensure
+    File.unlink(second_file) rescue nil
   end
 
   # Test that PStore's file operations do not blow up when default encodings are set
@@ -126,4 +130,8 @@
     SRC
     assert_equal(bug5311, @pstore.transaction {@pstore["Bug5311"]}, bug5311)
   end
+
+  def second_file
+    File.join(Dir.tmpdir, "pstore.tmp2.#{Process.pid}")
+  end
 end

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

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