summaryrefslogtreecommitdiff
path: root/test/test_tempfile.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_tempfile.rb')
-rw-r--r--test/test_tempfile.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index ccebbf3c1a..1e40e4e480 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -3,6 +3,8 @@ require 'test/unit'
require 'tempfile'
class TestTempfile < Test::Unit::TestCase
+ LIB_TEMPFILE_RB_PATH = File.expand_path(__dir__ + "/../lib/tempfile.rb")
+
def initialize(*)
super
@tempfile = nil
@@ -172,6 +174,38 @@ class TestTempfile < Test::Unit::TestCase
end
end unless /mswin|mingw/ =~ RUBY_PLATFORM
+ def test_finalizer_removes_file
+ assert_in_out_err(["-r#{LIB_TEMPFILE_RB_PATH}"], <<~RUBY) do |(filename,*), (error,*)|
+ file = Tempfile.new("foo")
+ puts file.path
+ RUBY
+ assert_file.not_exist?(filename)
+ assert_nil error
+ end
+ end
+
+ def test_finalizer_removes_file_when_dup
+ assert_in_out_err(["-r#{LIB_TEMPFILE_RB_PATH}"], <<~RUBY) do |(filename,*), (error,*)|
+ file = Tempfile.new("foo")
+ file.dup
+ puts file.path
+ RUBY
+ assert_file.not_exist?(filename)
+ assert_nil error
+ end
+ end
+
+ def test_finalizer_removes_file_when_clone
+ assert_in_out_err(["-r#{LIB_TEMPFILE_RB_PATH}"], <<~RUBY) do |(filename,*), (error,*)|
+ file = Tempfile.new("foo")
+ file.clone
+ puts file.path
+ RUBY
+ assert_file.not_exist?(filename)
+ assert_nil error
+ end
+ end
+
def test_finalizer_does_not_unlink_if_already_unlinked
assert_in_out_err('-rtempfile', <<-'EOS') do |(filename,*), (error,*)|
file = Tempfile.new('foo')
@@ -474,5 +508,4 @@ puts Tempfile.new('foo').path
assert_equal(true, t.autoclose?)
}
end
-
end