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

ruby-changes:21302

From: ayumin <ko1@a...>
Date: Wed, 28 Sep 2011 04:44:13 +0900 (JST)
Subject: [ruby-changes:21302] ayumin:r33351 (trunk): * test/psych/test_yamlstore.rb: use tmpdir for tmpfile.

ayumin	2011-09-28 04:44:02 +0900 (Wed, 28 Sep 2011)

  New Revision: 33351

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

  Log:
    * test/psych/test_yamlstore.rb: use tmpdir for tmpfile.
    * test/syck/test_yamlstore.rb: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/test/psych/test_yamlstore.rb
    trunk/test/syck/test_yamlstore.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33350)
+++ ChangeLog	(revision 33351)
@@ -1,3 +1,8 @@
+Wed Sep 28 04:41:35 2011  Ayumu AIZAWA  <ayumu.aizawa@g...>
+
+	* test/psych/test_yamlstore.rb: use tmpdir for tmpfile.
+	* test/syck/test_yamlstore.rb: ditto.
+
 Wed Sep 28 04:10:46 2011  Ayumu AIZAWA  <ayumu.aizawa@g...>
 
 	* ext/bigdecimal/README: update report to.
Index: test/psych/test_yamlstore.rb
===================================================================
--- test/psych/test_yamlstore.rb	(revision 33350)
+++ test/psych/test_yamlstore.rb	(revision 33351)
@@ -1,20 +1,28 @@
 require 'test/unit'
 require 'yaml/store'
+require 'tmpdir'
+
 Psych::Store = YAML::Store unless defined?(Psych::Store)
 
 module Psych
   class YAMLStoreTest < Test::Unit::TestCase
     def setup
       @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
-      @yamlstore_file = "yamlstore.tmp.#{Process.pid}"
+      @dir = Dir.mktmpdir("rubytest-file")
+      File.chown(-1, Process.gid, @dir)
+      @yamlstore_file = make_tmp_filename("yamlstore")
       @yamlstore = YAML::Store.new(@yamlstore_file)
     end
 
     def teardown
       YAML::ENGINE.yamler = @engine
-      File.unlink(@yamlstore_file) rescue nil
+      FileUtils.remove_entry_secure @dir
     end
 
+    def make_tmp_filename(prefix)
+      @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
+    end
+
     def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
       @yamlstore.transaction(true) do
         assert_nil @yamlstore[:foo]
Index: test/syck/test_yamlstore.rb
===================================================================
--- test/syck/test_yamlstore.rb	(revision 33350)
+++ test/syck/test_yamlstore.rb	(revision 33351)
@@ -1,20 +1,28 @@
 require 'test/unit'
 require 'yaml/store'
+require 'tmpdir'
+
 Syck::Store = YAML::Store unless defined?(Syck::Store)
 
 module Syck
   class YAMLStoreTest < Test::Unit::TestCase
     def setup
       @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'syck'
-      @yamlstore_file = "yamlstore.tmp.#{Process.pid}"
+      @dir = Dir.mktmpdir("rubytest-file")
+      File.chown(-1, Process.gid, @dir)
+      @yamlstore_file = make_tmp_filename("yamlstore")
       @yamlstore = YAML::Store.new(@yamlstore_file)
     end
 
     def teardown
       YAML::ENGINE.yamler = @engine
-      File.unlink(@yamlstore_file) rescue nil
+      FileUtils.remove_entry_secure @dir
     end
 
+    def make_tmp_filename(prefix)
+      @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
+    end
+
     def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
       @yamlstore.transaction(true) do
         assert_nil @yamlstore[:foo]

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

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