Project

General

Profile

Bug #8768 ยป 0001-lib-tempfile.rb-Tempfile-unlink-undefine-finalizer.patch

patch incuding testcase - normalperson (Eric Wong), 08/11/2013 04:41 AM

View differences:

lib/tempfile.rb
190 190
  def close!
191 191
    _close
192 192
    unlink
193
    ObjectSpace.undefine_finalizer(self)
194 193
  end
195 194

  
196 195
  # Unlinks (deletes) the file from the filesystem. One should always unlink
......
238 237
    # remove tmpname from remover
239 238
    @data[0] = @data[1] = nil
240 239
    @tmpname = nil
240
    ObjectSpace.undefine_finalizer(self)
241 241
  end
242 242
  alias delete unlink
243 243

  
test/test_tempfile.rb
206 206
    end
207 207
  end
208 208

  
209
  def test_tempfile_finalizer_does_not_run_if_unlinked
210
    args = %w(--debug --disable-gems -rtempfile)
211
    assert_in_out_err(args, <<-'EOS') do |(filename), (error)|
212
tmp = Tempfile.new('foo')
213
puts tmp.path
214
tmp.unlink
215
    EOS
216
      assert !File.exist?(filename)
217
      assert_nil error, "we used to get a confusing 'removing ...done' here"
218
    end
219
  end
220

  
209 221
  def test_size_flushes_buffer_before_determining_file_size
210 222
    t = tempfile("foo")
211 223
    t.write("hello")
212
-