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

ruby-changes:24418

From: akr <ko1@a...>
Date: Thu, 19 Jul 2012 22:47:22 +0900 (JST)
Subject: [ruby-changes:24418] akr:r36469 (trunk): * test/ruby/test_io.rb: remove temporally files early.

akr	2012-07-19 22:47:08 +0900 (Thu, 19 Jul 2012)

  New Revision: 36469

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

  Log:
    * test/ruby/test_io.rb: remove temporally files early.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_io.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36468)
+++ ChangeLog	(revision 36469)
@@ -1,3 +1,7 @@
+Thu Jul 19 22:46:48 2012  Tanaka Akira  <akr@f...>
+
+	* test/ruby/test_io.rb: remove temporally files early.
+
 Thu Jul 19 15:38:35 2012  Shugo Maeda  <shugo@r...>
 
 	* variable.c (rb_mod_class_variables): return inherited variables
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 36468)
+++ test/ruby/test_io.rb	(revision 36469)
@@ -205,25 +205,26 @@
   end
 
   def test_ungetbyte
-    t = make_tempfile
-    t.open
-    t.binmode
-    t.ungetbyte(0x41)
-    assert_equal(-1, t.pos)
-    assert_equal(0x41, t.getbyte)
-    t.rewind
-    assert_equal(0, t.pos)
-    t.ungetbyte("qux")
-    assert_equal(-3, t.pos)
-    assert_equal("quxfoo\n", t.gets)
-    assert_equal(4, t.pos)
-    t.set_encoding("utf-8")
-    t.ungetbyte(0x89)
-    t.ungetbyte(0x8e)
-    t.ungetbyte("\xe7")
-    t.ungetbyte("\xe7\xb4\x85")
-    assert_equal(-2, t.pos)
-    assert_equal("\u7d05\u7389bar\n", t.gets)
+    make_tempfile {|t|
+      t.open
+      t.binmode
+      t.ungetbyte(0x41)
+      assert_equal(-1, t.pos)
+      assert_equal(0x41, t.getbyte)
+      t.rewind
+      assert_equal(0, t.pos)
+      t.ungetbyte("qux")
+      assert_equal(-3, t.pos)
+      assert_equal("quxfoo\n", t.gets)
+      assert_equal(4, t.pos)
+      t.set_encoding("utf-8")
+      t.ungetbyte(0x89)
+      t.ungetbyte(0x8e)
+      t.ungetbyte("\xe7")
+      t.ungetbyte("\xe7\xb4\x85")
+      assert_equal(-2, t.pos)
+      assert_equal("\u7d05\u7389bar\n", t.gets)
+    }
   end
 
   def test_each_byte
@@ -237,23 +238,25 @@
   end
 
   def test_each_byte_with_seek
-    t = make_tempfile
-    bug5119 = '[ruby-core:38609]'
-    i = 0
-    open(t.path) do |f|
-      f.each_byte {i = f.pos}
-    end
-    assert_equal(12, i, bug5119)
+    make_tempfile {|t|
+      bug5119 = '[ruby-core:38609]'
+      i = 0
+      open(t.path) do |f|
+        f.each_byte {i = f.pos}
+      end
+      assert_equal(12, i, bug5119)
+    }
   end
 
   def test_each_codepoint
-    t = make_tempfile
-    bug2959 = '[ruby-core:28650]'
-    a = ""
-    File.open(t, 'rt') {|f|
-      f.each_codepoint {|c| a << c}
+    make_tempfile {|t|
+      bug2959 = '[ruby-core:28650]'
+      a = ""
+      File.open(t, 'rt') {|f|
+        f.each_codepoint {|c| a << c}
+      }
+      assert_equal("foo\nbar\nbaz\n", a, bug2959)
     }
-    assert_equal("foo\nbar\nbaz\n", a, bug2959)
   end
 
   def test_rubydev33072
@@ -1236,38 +1239,38 @@
   end
 
   def test_set_lineno
-    t = make_tempfile
-
-    ruby("-e", <<-SRC, t.path) do |f|
-      open(ARGV[0]) do |f|
-        p $.
-        f.gets; p $.
-        f.gets; p $.
-        f.lineno = 1000; p $.
-        f.gets; p $.
-        f.gets; p $.
-        f.rewind; p $.
-        f.gets; p $.
-        f.gets; p $.
-        f.gets; p $.
-        f.gets; p $.
+    make_tempfile {|t|
+      ruby("-e", <<-SRC, t.path) do |f|
+        open(ARGV[0]) do |f|
+          p $.
+          f.gets; p $.
+          f.gets; p $.
+          f.lineno = 1000; p $.
+          f.gets; p $.
+          f.gets; p $.
+          f.rewind; p $.
+          f.gets; p $.
+          f.gets; p $.
+          f.gets; p $.
+          f.gets; p $.
+        end
+      SRC
+        assert_equal("0,1,2,2,1001,1001,1001,1,2,3,3", f.read.chomp.gsub("\n", ","))
       end
-    SRC
-      assert_equal("0,1,2,2,1001,1001,1001,1,2,3,3", f.read.chomp.gsub("\n", ","))
-    end
 
-    pipe(proc do |w|
-      w.puts "foo"
-      w.puts "bar"
-      w.puts "baz"
-      w.close
-    end, proc do |r|
-      r.gets; assert_equal(1, $.)
-      r.gets; assert_equal(2, $.)
-      r.lineno = 1000; assert_equal(2, $.)
-      r.gets; assert_equal(1001, $.)
-      r.gets; assert_equal(1001, $.)
-    end)
+      pipe(proc do |w|
+        w.puts "foo"
+        w.puts "bar"
+        w.puts "baz"
+        w.close
+      end, proc do |r|
+        r.gets; assert_equal(1, $.)
+        r.gets; assert_equal(2, $.)
+        r.lineno = 1000; assert_equal(2, $.)
+        r.gets; assert_equal(1001, $.)
+        r.gets; assert_equal(1001, $.)
+      end)
+    }
   end
 
   def test_readline
@@ -1414,41 +1417,43 @@
   end
 
   def test_pos
-    t = make_tempfile
+    make_tempfile {|t|
 
-    open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
-      f.write "Hello"
-      assert_equal(5, f.pos)
-    end
-    open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
-      f.sync = true
-      f.read
-      f.write "Hello"
-      assert_equal(5, f.pos)
-    end
+      open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
+        f.write "Hello"
+        assert_equal(5, f.pos)
+      end
+      open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f|
+        f.sync = true
+        f.read
+        f.write "Hello"
+        assert_equal(5, f.pos)
+      end
+    }
   end
 
   def test_pos_with_getc
     bug6179 = '[ruby-core:43497]'
-    t = make_tempfile
-    ["", "t", "b"].each do |mode|
-      open(t.path, "w#{mode}") do |f|
-        f.write "0123456789\n"
-      end
+    make_tempfile {|t|
+      ["", "t", "b"].each do |mode|
+        open(t.path, "w#{mode}") do |f|
+          f.write "0123456789\n"
+        end
 
-      open(t.path, "r#{mode}") do |f|
-        assert_equal 0, f.pos, "mode=r#{mode}"
-        assert_equal '0', f.getc, "mode=r#{mode}"
-        assert_equal 1, f.pos, "mode=r#{mode}"
-        assert_equal '1', f.getc, "mode=r#{mode}"
-        assert_equal 2, f.pos, "mode=r#{mode}"
-        assert_equal '2', f.getc, "mode=r#{mode}"
-        assert_equal 3, f.pos, "mode=r#{mode}"
-        assert_equal '3', f.getc, "mode=r#{mode}"
-        assert_equal 4, f.pos, "mode=r#{mode}"
-        assert_equal '4', f.getc, "mode=r#{mode}"
+        open(t.path, "r#{mode}") do |f|
+          assert_equal 0, f.pos, "mode=r#{mode}"
+          assert_equal '0', f.getc, "mode=r#{mode}"
+          assert_equal 1, f.pos, "mode=r#{mode}"
+          assert_equal '1', f.getc, "mode=r#{mode}"
+          assert_equal 2, f.pos, "mode=r#{mode}"
+          assert_equal '2', f.getc, "mode=r#{mode}"
+          assert_equal 3, f.pos, "mode=r#{mode}"
+          assert_equal '3', f.getc, "mode=r#{mode}"
+          assert_equal 4, f.pos, "mode=r#{mode}"
+          assert_equal '4', f.getc, "mode=r#{mode}"
+        end
       end
-    end
+    }
   end
 
 
@@ -1478,39 +1483,39 @@
   end
 
   def test_sysseek
-    t = make_tempfile
+    make_tempfile {|t|
+      open(t.path) do |f|
+        f.sysseek(-4, IO::SEEK_END)
+        assert_equal("baz\n", f.read)
+      end
 
-    open(t.path) do |f|
-      f.sysseek(-4, IO::SEEK_END)
-      assert_equal("baz\n", f.read)
-    end
-
-    open(t.path) do |f|
-      a = [f.getc, f.getc, f.getc]
-      a.reverse_each {|c| f.ungetc c }
-      assert_raise(IOError) { f.sysseek(1) }
-    end
+      open(t.path) do |f|
+        a = [f.getc, f.getc, f.getc]
+        a.reverse_each {|c| f.ungetc c }
+        assert_raise(IOError) { f.sysseek(1) }
+      end
+    }
   end
 
   def test_syswrite
-    t = make_tempfile
-
-    open(t.path, "w") do |f|
-      o = Object.new
-      def o.to_s; "FOO\n"; end
-      f.syswrite(o)
-    end
-    assert_equal("FOO\n", File.read(t.path))
+    make_tempfile {|t|
+      open(t.path, "w") do |f|
+        o = Object.new
+        def o.to_s; "FOO\n"; end
+        f.syswrite(o)
+      end
+      assert_equal("FOO\n", File.read(t.path))
+    }
   end
 
   def test_sysread
-    t = make_tempfile
-
-    open(t.path) do |f|
-      a = [f.getc, f.getc, f.getc]
-      a.reverse_each {|c| f.ungetc c }
-      assert_raise(IOError) { f.sysread(1) }
-    end
+    make_tempfile {|t|
+      open(t.path) do |f|
+        a = [f.getc, f.getc, f.getc]
+        a.reverse_each {|c| f.ungetc c }
+        assert_raise(IOError) { f.sysread(1) }
+      end
+    }
   end
 
   def test_sysread_with_not_empty_buffer
@@ -1524,41 +1529,41 @@
   end
 
   def test_flag
-    t = make_tempfile
+    make_tempfile {|t|
+      assert_raise(ArgumentError) do
+        open(t.path, "z") { }
+      end
 
-    assert_raise(ArgumentError) do
-      open(t.path, "z") { }
-    end
-
-    assert_raise(ArgumentError) do
-      open(t.path, "rr") { }
-    end
+      assert_raise(ArgumentError) do
+        open(t.path, "rr") { }
+      end
+    }
   end
 
   def test_sysopen
-    t = make_tempfile
+    make_tempfile {|t|
+      fd = IO.sysopen(t.path)
+      assert_kind_of(Integer, fd)
+      f = IO.for_fd(fd)
+      assert_equal("foo\nbar\nbaz\n", f.read)
+      f.close
 
-    fd = IO.sysopen(t.path)
-    assert_kind_of(Integer, fd)
-    f = IO.for_fd(fd)
-    assert_equal("foo\nbar\nbaz\n", f.read)
-    f.close
+      fd = IO.sysopen(t.path, "w", 0666)
+      assert_kind_of(Integer, fd)
+      if defined?(Fcntl::F_GETFL)
+        f = IO.for_fd(fd)
+      else
+        f = IO.for_fd(fd, 0666)
+      end
+      f.write("FOO\n")
+      f.close
 
-    fd = IO.sysopen(t.path, "w", 0666)
-    assert_kind_of(Integer, fd)
-    if defined?(Fcntl::F_GETFL)
+      fd = IO.sysopen(t.path, "r")
+      assert_kind_of(Integer, fd)
       f = IO.for_fd(fd)
-    else
-      f = IO.for_fd(fd, 0666)
-    end
-    f.write("FOO\n")
-    f.close
-
-    fd = IO.sysopen(t.path, "r")
-    assert_kind_of(Integer, fd)
-    f = IO.for_fd(fd)
-    assert_equal("FOO\n", f.read)
-    f.close
+      assert_equal("FOO\n", f.read)
+      f.close
+    }
   end
 
   def try_fdopen(fd, autoclose = true, level = 50)
@@ -1577,21 +1582,23 @@
     feature2250 = '[ruby-core:26222]'
     pre = 'ft2250'
 
-    t = Tempfile.new(pre)
-    f = IO.for_fd(t.fileno)
-    assert_equal(true, f.autoclose?)
-    f.autoclose = false
-    assert_equal(false, f.autoclose?)
-    f.close
-    assert_nothing_raised(Errno::EBADF, feature2250) {t.close}
+    Dir.mktmpdir {|d|
+      t = open("#{d}/#{pre}", "w")
+      f = IO.for_fd(t.fileno)
+      assert_equal(true, f.autoclose?)
+      f.autoclose = false
+      assert_equal(false, f.autoclose?)
+      f.close
+      assert_nothing_raised(Errno::EBADF, feature2250) {t.close}
 
-    t.open
-    f = IO.for_fd(t.fileno, autoclose: false)
-    assert_equal(false, f.autoclose?)
-    f.autoclose = true
-    assert_equal(true, f.autoclose?)
-    f.close
-    assert_raise(Errno::EBADF, feature2250) {t.close}
+      t = open("#{d}/#{pre}", "w")
+      f = IO.for_fd(t.fileno, autoclose: false)
+      assert_equal(false, f.autoclose?)
+      f.autoclose = true
+      assert_equal(true, f.autoclose?)
+      f.close
+      assert_raise(Errno::EBADF, feature2250) {t.close}
+    }
   end
 
   def test_autoclose_true_closed_by_finalizer
@@ -1609,6 +1616,8 @@
     rescue WeakRef::RefError
       assert_raise(Errno::EBADF, feature2250) {t.close}
     end
+  ensure
+    t.unlink
   end
 
   def test_autoclose_false_closed_by_finalizer
@@ -1623,6 +1632,8 @@
     rescue WeakRef::RefError
       assert_nothing_raised(Errno::EBADF, feature2250) {t.close}
     end
+  ensure
+    t.unlink
   end
 
   def test_open_redirect
@@ -1645,48 +1656,48 @@
   end
 
   def test_reopen
-    t = make_tempfile
-
-    with_pipe do |r, w|
-      assert_raise(SecurityError) do
-        safe_4 { r.reopen(t.path) }
+    make_tempfile {|t|
+      with_pipe do |r, w|
+        assert_raise(SecurityError) do
+          safe_4 { r.reopen(t.path) }
+        end
       end
-    end
 
-    open(__FILE__) do |f|
-      f.gets
-      assert_nothing_raised {
-        f.reopen(t.path)
-        assert_equal("foo\n", f.gets)
-      }
-    end
-
-    open(__FILE__) do |f|
-      f.gets
-      f2 = open(t.path)
-      begin
-        f2.gets
+      open(__FILE__) do |f|
+        f.gets
         assert_nothing_raised {
-          f.reopen(f2)
-          assert_equal("bar\n", f.gets, '[ruby-core:24240]')
+          f.reopen(t.path)
+          assert_equal("foo\n", f.gets)
         }
-      ensure
-        f2.close
       end
-    end
 
-    open(__FILE__) do |f|
-      f2 = open(t.path)
-      begin
-        f.reopen(f2)
-        assert_equal("foo\n", f.gets)
-        assert_equal("bar\n", f.gets)
-        f.reopen(f2)
-        assert_equal("baz\n", f.gets, '[ruby-dev:39479]')
-      ensure
-        f2.close
+      open(__FILE__) do |f|
+        f.gets
+        f2 = open(t.path)
+        begin
+          f2.gets
+          assert_nothing_raised {
+            f.reopen(f2)
+            assert_equal("bar\n", f.gets, '[ruby-core:24240]')
+          }
+        ensure
+          f2.close
+        end
       end
-    end
+
+      open(__FILE__) do |f|
+        f2 = open(t.path)
+        begin
+          f.reopen(f2)
+          assert_equal("foo\n", f.gets)
+          assert_equal("bar\n", f.gets)
+          f.reopen(f2)
+          assert_equal("baz\n", f.gets, '[ruby-dev:39479]')
+        ensure
+          f2.close
+        end
+      end
+    }
   end
 
   def test_reopen_inherit
@@ -1707,55 +1718,55 @@
     IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x }
     assert_equal(["foo\n", "bar\n", "baz\n"], a)
 
-    t = make_tempfile
+    make_tempfile {|t|
+      a = []
+      IO.foreach(t.path) {|x| a << x }
+      assert_equal(["foo\n", "bar\n", "baz\n"], a)
 
-    a = []
-    IO.foreach(t.path) {|x| a << x }
-    assert_equal(["foo\n", "bar\n", "baz\n"], a)
+      a = []
+      IO.foreach(t.path, {:mode => "r" }) {|x| a << x }
+      assert_equal(["foo\n", "bar\n", "baz\n"], a)
 
-    a = []
-    IO.foreach(t.path, {:mode => "r" }) {|x| a << x }
-    assert_equal(["foo\n", "bar\n", "baz\n"], a)
+      a = []
+      IO.foreach(t.path, {:open_args => [] }) {|x| a << x }
+      assert_equal(["foo\n", "bar\n", "baz\n"], a)
 
-    a = []
-    IO.foreach(t.path, {:open_args => [] }) {|x| a << x }
-    assert_equal(["foo\n", "bar\n", "baz\n"], a)
+      a = []
+      IO.foreach(t.path, {:open_args => ["r"] }) {|x| a << x }
+      assert_equal(["foo\n", "bar\n", "baz\n"], a)
 
-    a = []
-    IO.foreach(t.path, {:open_args => ["r"] }) {|x| a << x }
-    assert_equal(["foo\n", "bar\n", "baz\n"], a)
+      a = []
+      IO.foreach(t.path, "b") {|x| a << x }
+      assert_equal(["foo\nb", "ar\nb", "az\n"], a)
 
-    a = []
-    IO.foreach(t.path, "b") {|x| a << x }
-    assert_equal(["foo\nb", "ar\nb", "az\n"], a)
+      a = []
+      IO.foreach(t.path, 3) {|x| a << x }
+      assert_equal(["foo", "\n", "bar", "\n", "baz", "\n"], a)
 
-    a = []
-    IO.foreach(t.path, 3) {|x| a << x }
-    assert_equal(["foo", "\n", "bar", "\n", "baz", "\n"], a)
+      a = []
+      IO.foreach(t.path, "b", 3) {|x| a << x }
+      assert_equal(["foo", "\nb", "ar\n", "b", "az\n"], a)
 
-    a = []
-    IO.foreach(t.path, "b", 3) {|x| a << x }
-    assert_equal(["foo", "\nb", "ar\n", "b", "az\n"], a)
+      bug = '[ruby-dev:31525]'
+      assert_raise(ArgumentError, bug) {IO.foreach}
 
-    bug = '[ruby-dev:31525]'
-    assert_raise(ArgumentError, bug) {IO.foreach}
+      a = nil
+      assert_nothing_raised(ArgumentError, bug) {a = IO.foreach(t.path).to_a}
+      assert_equal(["foo\n", "bar\n", "baz\n"], a, bug)
 
-    a = nil
-    assert_nothing_raised(ArgumentError, bug) {a = IO.foreach(t.path).to_a}
-    assert_equal(["foo\n", "bar\n", "baz\n"], a, bug)
-
-    bug6054 = '[ruby-dev:45267]'
-    e = assert_raise(IOError, bug6054) {IO.foreach(t.path, mode:"w").next}
-    assert_match(/not opened for reading/, e.message, bug6054)
+      bug6054 = '[ruby-dev:45267]'
+      e = assert_raise(IOError, bug6054) {IO.foreach(t.path, mode:"w").next}
+      assert_match(/not opened for reading/, e.message, bug6054)
+    }
   end
 
   def test_s_readlines
-    t = make_tempfile
-
-    assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path))
-    assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
-    assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2))
-    assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
+    make_tempfile {|t|
+      assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path))
+      assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
+      assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2))
+      assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
+    }
   end
 
   def test_printf
@@ -1768,9 +1779,11 @@
   end
 
   def test_print
-    t = make_tempfile
-
-    assert_in_out_err(["-", t.path], "print while $<.gets", %w(foo bar baz), [])
+    make_tempfile {|t|
+      assert_in_out_err(["-", t.path],
+                        "print while $<.gets",
+                        %w(foo bar baz), [])
+    }
   end
 
   def test_print_separators
@@ -1835,30 +1848,32 @@
   def test_initialize
     return unless defined?(Fcntl::F_GETFL)
 
-    t = make_tempfile
+    make_tempfile {|t|
 
-    fd = IO.sysopen(t.path, "w")
-    assert_kind_of(Integer, fd)
-    %w[r r+ w+ a+].each do |mode|
-      assert_raise(Errno::EINVAL, "#{mode} [ruby-dev:38571]") {IO.new(fd, mode)}
-    end
-    f = IO.new(fd, "w")
-    f.write("FOO\n")
-    f.close
+      fd = IO.sysopen(t.path, "w")
+      assert_kind_of(Integer, fd)
+      %w[r r+ w+ a+].each do |mode|
+        assert_raise(Errno::EINVAL, "#{mode} [ruby-dev:38571]") {IO.new(fd, mode)}
+      end
+      f = IO.new(fd, "w")
+      f.write("FOO\n")
+      f.close
 
-    assert_equal("FOO\n", File.read(t.path))
+      assert_equal("FOO\n", File.read(t.path))
+    }
   end
 
   def test_reinitialize
-    t = make_tempfile
-    f = open(t.path)
-    begin
-      assert_raise(RuntimeError) do
-        f.instance_eval { initialize }
+    make_tempfile {|t|
+      f = open(t.path)
+      begin
+        assert_raise(RuntimeError) do
+          f.instance_eval { initialize }
+        end
+      ensure
+        f.close
       end
-    ensure
-      f.close
-    end
+    }
   end
 
   def test_new_with_block
@@ -1884,11 +1899,11 @@
   end
 
   def test_s_read
-    t = make_tempfile
-
-    assert_equal("foo\nbar\nbaz\n", File.read(t.path))
-    assert_equal("foo\nba", File.read(t.path, 6))
-    assert_equal("bar\n", File.read(t.path, 4, 4))
+    make_tempfile {|t|
+      assert_equal("foo\nbar\nbaz\n", File.read(t.path))
+      assert_equal("foo\nba", File.read(t.path, 6))
+      assert_equal("bar\n", File.read(t.path, 4, 4))
+    }
   end
 
   def test_uninitialized
@@ -1916,14 +1931,16 @@
   end
 
   def test_tainted
-    t = make_tempfile
-    assert(File.read(t.path, 4).tainted?, '[ruby-dev:38826]')
-    assert(File.open(t.path) {|f| f.read(4)}.tainted?, '[ruby-dev:38826]')
+    make_tempfile {|t|
+      assert(File.read(t.path, 4).tainted?, '[ruby-dev:38826]')
+      assert(File.open(t.path) {|f| f.read(4)}.tainted?, '[ruby-dev:38826]')
+    }
   end
 
   def test_binmode_after_closed
-    t = make_tempfile
-    assert_raise(IOError) {t.binmode}
+    make_tempfile {|t|
+      assert_raise(IOError) {t.binmode}
+    }
   end
 
   def test_threaded_flush
@@ -1945,17 +1962,19 @@
   def test_flush_in_finalizer1
     require 'tempfile'
     bug3910 = '[ruby-dev:42341]'
-    t = Tempfile.new("bug3910")
-    path = t.path
-    t.close
-    fds = []
-    assert_nothing_raised(TypeError, bug3910) do
-      500.times {
-        f = File.open(path, "w")
-        fds << f.fileno
-        f.print "hoge"
-      }
-    end
+    Tempfile.open("bug3910") {|t|
+      path = t.path
+      t.close
+      fds = []
+      assert_nothing_raised(TypeError, bug3910) do
+        500.times {
+          f = File.open(path, "w")
+          fds << f.fileno
+          f.print "hoge"
+        }
+      end
+      t.unlink
+    }
   ensure
     GC.start
   end
@@ -1963,75 +1982,83 @@
   def test_flush_in_finalizer2
     require 'tempfile'
     bug3910 = '[ruby-dev:42341]'
-    t = Tempfile.new("bug3910")
-    path = t.path
-    t.close
-    1.times do
-      io = open(path,"w")
-    (... truncated)

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

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