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

ruby-changes:62756

From: Benoit <ko1@a...>
Date: Sat, 29 Aug 2020 19:31:01 +0900 (JST)
Subject: [ruby-changes:62756] e8c3872555 (master): Simplify Tempfile.open calls with a block as they now unlink the file automatically

https://git.ruby-lang.org/ruby.git/commit/?id=e8c3872555

From e8c3872555fc85640505974e6b1c39d315572689 Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Sat, 29 Aug 2020 12:17:07 +0200
Subject: Simplify Tempfile.open calls with a block as they now unlink the file
 automatically


diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb
index 305e1dc..39408fa 100644
--- a/lib/rubygems/ext/ext_conf_builder.rb
+++ b/lib/rubygems/ext/ext_conf_builder.rb
@@ -36,7 +36,6 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L36
       siteconf.close
 
       destdir = ENV["DESTDIR"]
-
       begin
         cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../../..", __FILE__) <<
               "-r" << get_relative_path(siteconf.path) << File.basename(extension)
@@ -76,7 +75,6 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L75
         end
       ensure
         ENV["DESTDIR"] = destdir
-        siteconf.close!
       end
     end
 
diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb
index 7cc3c2d..cd43aca 100644
--- a/test/rdoc/test_rdoc_parser.rb
+++ b/test/rdoc/test_rdoc_parser.rb
@@ -106,7 +106,7 @@ class TestRDocParser < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser.rb#L106
   def test_class_for_forbidden
     omit 'chmod not supported' if Gem.win_platform?
 
-    tf = Tempfile.open 'forbidden' do |io|
+    Tempfile.open 'forbidden' do |io|
       begin
         File.chmod 0000, io.path
         forbidden = @store.add_file io.path
@@ -117,9 +117,7 @@ class TestRDocParser < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser.rb#L117
       ensure
         File.chmod 0400, io.path
       end
-      io
     end
-    tf.close!
   end
 
   def test_class_for_modeline
diff --git a/test/rdoc/test_rdoc_rd_block_parser.rb b/test/rdoc/test_rdoc_rd_block_parser.rb
index 22f432e..24413ee 100644
--- a/test/rdoc/test_rdoc_rd_block_parser.rb
+++ b/test/rdoc/test_rdoc_rd_block_parser.rb
@@ -154,7 +154,7 @@ class TestRDocRdBlockParser < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rd_block_parser.rb#L154
         blank_line,
         blank_line)
 
-    tf = Tempfile.open %w[parse_include .rd] do |io|
+    Tempfile.open %w[parse_include .rd] do |io|
       io.puts "=begin\ninclude ((*worked*))\n=end"
       io.flush
 
@@ -163,9 +163,7 @@ class TestRDocRdBlockParser < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rd_block_parser.rb#L163
       STR
 
       assert_equal expected, parse(str)
-      io
     end
-    tf.close!
   end
 
   def test_parse_heading
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
index f2cc901..7824099 100644
--- a/test/rdoc/test_rdoc_rdoc.rb
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -342,16 +342,14 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L342
     @rdoc.options.encoding = Encoding::ISO_8859_1
     @rdoc.store = RDoc::Store.new
 
-    tf = Tempfile.open 'test.txt' do |io|
+    Tempfile.open 'test.txt' do |io|
       io.write 'hi'
       io.rewind
 
       top_level = @rdoc.parse_file io.path
 
       assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
-      io
     end
-    tf.close!
   end
 
   def test_parse_file_forbidden
@@ -360,7 +358,7 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L358
 
     @rdoc.store = RDoc::Store.new
 
-    tf = Tempfile.open 'test.txt' do |io|
+    Tempfile.open 'test.txt' do |io|
       io.write 'hi'
       io.rewind
 
@@ -379,9 +377,7 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L377
       ensure
         File.chmod 0400, io.path
       end
-      io
     end
-    tf.close!
   end
 
   def test_remove_unparseable
@@ -478,7 +474,7 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L474
   end
 
   def test_setup_output_dir_exists_file
-    tf = Tempfile.open 'test_rdoc_rdoc' do |tempfile|
+    Tempfile.open 'test_rdoc_rdoc' do |tempfile|
       path = tempfile.path
 
       e = assert_raise RDoc::Error do
@@ -487,9 +483,7 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L483
 
       assert_match(%r%#{Regexp.escape path} exists and is not a directory%,
                    e.message)
-      tempfile
     end
-    tf.close!
   end
 
   def test_setup_output_dir_exists_not_rdoc
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index fafb082..c528eea 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -2814,7 +2814,7 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2814
 
   def test_flush_in_finalizer1
     bug3910 = '[ruby-dev:42341]'
-    tmp = Tempfile.open("bug3910") {|t|
+    Tempfile.open("bug3910") {|t|
       path = t.path
       t.close
       fds = []
@@ -2826,7 +2826,6 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2826
           f.print "hoge"
         }
       end
-      t
     }
   ensure
     ObjectSpace.each_object(File) {|f|
@@ -2834,7 +2833,6 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2833
         f.close
       end
     }
-    tmp.close!
   end
 
   def test_flush_in_finalizer2
@@ -2858,7 +2856,6 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2856
           end
         }
       end
-      t.close!
     }
   end
 
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 5e9c3b7..b6f785f 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -887,7 +887,7 @@ class TestGemPackage < Gem::Package::TarTestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package.rb#L887
 
   def test_verify_corrupt
     skip "jruby strips the null byte and does not think it's corrupt" if Gem.java_platform?
-    tf = Tempfile.open 'corrupt' do |io|
+    Tempfile.open 'corrupt' do |io|
       data = Gem::Util.gzip 'a' * 10
       io.write \
         tar_file_header('metadata.gz', "\000x", 0644, data.length, Time.now)
@@ -902,9 +902,7 @@ class TestGemPackage < Gem::Package::TarTestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package.rb#L902
 
       assert_equal "tar is corrupt, name contains null byte in #{io.path}",
                    e.message
-      io
     end
-    tf.close!
   end
 
   def test_verify_empty
diff --git a/test/rubygems/test_gem_request_set.rb b/test/rubygems/test_gem_request_set.rb
index 54ae772..7a21424 100644
--- a/test/rubygems/test_gem_request_set.rb
+++ b/test/rubygems/test_gem_request_set.rb
@@ -261,16 +261,14 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L261
   def test_load_gemdeps
     rs = Gem::RequestSet.new
 
-    tf = Tempfile.open 'gem.deps.rb' do |io|
+    Tempfile.open 'gem.deps.rb' do |io|
       io.puts 'gem "a"'
       io.flush
 
       gem_deps = rs.load_gemdeps io.path
 
       assert_kind_of Gem::RequestSet::GemDependencyAPI, gem_deps
-      io
     end
-    tf.close!
 
     assert_equal [dep('a')], rs.dependencies
 
@@ -281,7 +279,7 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L279
   def test_load_gemdeps_installing
     rs = Gem::RequestSet.new
 
-    tf = Tempfile.open 'gem.deps.rb' do |io|
+    Tempfile.open 'gem.deps.rb' do |io|
       io.puts 'ruby "0"'
       io.puts 'gem "a"'
       io.flush
@@ -289,9 +287,7 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L287
       gem_deps = rs.load_gemdeps io.path, [], true
 
       assert_kind_of Gem::RequestSet::GemDependencyAPI, gem_deps
-      io
     end
-    tf.close!
 
     assert_equal [dep('a')], rs.dependencies
   end
@@ -299,14 +295,12 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L295
   def test_load_gemdeps_without_groups
     rs = Gem::RequestSet.new
 
-    tf = Tempfile.open 'gem.deps.rb' do |io|
+    Tempfile.open 'gem.deps.rb' do |io|
       io.puts 'gem "a", :group => :test'
       io.flush
 
       rs.load_gemdeps io.path, [:test]
-      io
     end
-    tf.close!
 
     assert_empty rs.dependencies
   end
@@ -394,7 +388,7 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L388
 
     rs = Gem::RequestSet.new
 
-    tf = Tempfile.open 'gem.deps.rb' do |io|
+    Tempfile.open 'gem.deps.rb' do |io|
       io.puts <<-GEMS_DEPS_RB
         gem "#{name}", :git => "#{repository}"
       GEMS_DEPS_RB
@@ -402,9 +396,7 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L396
       io.flush
 
       rs.load_gemdeps io.path
-      io
     end
-    tf.close!
 
     res = rs.resolve
     assert_equal 1, res.size
@@ -457,7 +449,7 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L449
 
     rs = Gem::RequestSet.new
 
-    tf = Tempfile.open 'gem.deps.rb' do |io|
+    Tempfile.open 'gem.deps.rb' do |io|
       io.puts <<-GEMS_DEPS_RB
         gem "#{a_name}", :path => "#{a_directory}"
         gem "#{b_name}", :path => "#{b_directory}"
@@ -466,9 +458,7 @@ ruby "0" https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_set.rb#L458
       io.flush
 
       rs.load_gemdeps io.path
-      io
     end
-    tf.close!
 
     res = rs.resolve
     assert_equal 2, res.size
diff --git a/test/rubygems/test_gem_request_set_gem_dependency_api.rb b/test/rubygems/test_gem_request_set_gem_dependency_api.rb
index 2a96639..249f2e1 100644
--- a/test/rubygems/test_gem_request_set_gem_dependency_api.rb
+++ b/test/rubygems/test_gem_request (... truncated)

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

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