上级 6997109f
......@@ -203,16 +203,6 @@ Outstanding ones only.
take request headers as a Hash in the second argument when the first
argument is a URI. [[Feature #16686]]
* Tempfile
* Modified method
* `Tempfile.open { ... }` will now unlink the file at the end of the
block (https://github.com/ruby/tempfile/pull/3), such that once the
block finishes execution nothing leaks.
## Compatibility issues
Excluding feature bug fixes.
......
......@@ -2079,14 +2079,12 @@ def finish
end
private def vi_histedit(key)
Tempfile.open { |fp|
path = Tempfile.open { |fp|
fp.write @line
path = fp.path
fp.close
system("#{ENV['EDITOR']} #{path}")
@line = File.read(path)
fp.path
}
system("#{ENV['EDITOR']} #{path}")
@line = File.read(path)
finish
end
......
......@@ -38,10 +38,8 @@
end
it "is passed an array [base, suffix] as first argument" do
Tempfile.open(["specs", ".tt"]) { |tempfile|
@tempfile = tempfile
tempfile.path.should =~ /specs.*\.tt$/
}
Tempfile.open(["specs", ".tt"]) { |tempfile| @tempfile = tempfile }
@tempfile.path.should =~ /specs.*\.tt$/
end
it "passes the third argument (options) to open" do
......@@ -67,7 +65,7 @@
end
after :each do
# Tempfile.open with block does not unlink in Ruby <= 2.7
# Tempfile.open with block does not unlink
@tempfile.close! if @tempfile
end
......@@ -96,24 +94,4 @@
Tempfile.open("specs") { |tempfile| @tempfile = tempfile }
@tempfile.closed?.should be_true
end
ruby_version_is ""..."2.8" do
it "does not unlink the file after the block ends" do
path = Tempfile.open("specs") { |tempfile|
@tempfile = tempfile
tempfile.path
}
File.should.exist?(path)
end
end
ruby_version_is "2.8" do
it "unlinks the file after the block ends" do
path = Tempfile.open("specs") { |tempfile|
@tempfile = tempfile
tempfile.path
}
File.should_not.exist?(path)
end
end
end
......@@ -33,21 +33,20 @@ def test_add_file
]
cert1 = issue_cert(@ca1, @rsa1024, 1, ca_exts, nil, nil)
cert2 = issue_cert(@ca2, @rsa2048, 1, ca_exts, nil, nil)
Tempfile.open { |tmpfile|
tmpfile << cert1.to_pem << cert2.to_pem
tmpfile.close
store = OpenSSL::X509::Store.new
assert_equal false, store.verify(cert1)
assert_equal false, store.verify(cert2)
store.add_file(tmpfile.path)
assert_equal true, store.verify(cert1)
assert_equal true, store.verify(cert2)
# OpenSSL < 1.1.1 leaks an error on a duplicate certificate
assert_nothing_raised { store.add_file(tmpfile.path) }
assert_equal [], OpenSSL.errors
}
tmpfile = Tempfile.open { |f| f << cert1.to_pem << cert2.to_pem; f }
store = OpenSSL::X509::Store.new
assert_equal false, store.verify(cert1)
assert_equal false, store.verify(cert2)
store.add_file(tmpfile.path)
assert_equal true, store.verify(cert1)
assert_equal true, store.verify(cert2)
# OpenSSL < 1.1.1 leaks an error on a duplicate certificate
assert_nothing_raised { store.add_file(tmpfile.path) }
assert_equal [], OpenSSL.errors
ensure
tmpfile and tmpfile.close!
end
def test_verify
......
......@@ -2814,7 +2814,7 @@ def test_threaded_flush
def test_flush_in_finalizer1
bug3910 = '[ruby-dev:42341]'
Tempfile.open("bug3910") {|t|
tmp = Tempfile.open("bug3910") {|t|
path = t.path
t.close
fds = []
......@@ -2826,6 +2826,7 @@ def test_flush_in_finalizer1
f.print "hoge"
}
end
t
}
ensure
ObjectSpace.each_object(File) {|f|
......@@ -2833,6 +2834,7 @@ def test_flush_in_finalizer1
f.close
end
}
tmp.close!
end
def test_flush_in_finalizer2
......@@ -2856,6 +2858,7 @@ def test_flush_in_finalizer2
end
}
end
t.close!
}
end
......
......@@ -122,11 +122,16 @@ def diff exp, act
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
need_to_diff
tempfile_a = nil
tempfile_b = nil
Tempfile.open("expect") do |a|
tempfile_a = a
a.puts expect
a.flush
Tempfile.open("butwas") do |b|
tempfile_b = b
b.puts butwas
b.flush
......@@ -147,6 +152,9 @@ def diff exp, act
end
result
ensure
tempfile_a.close! if tempfile_a
tempfile_b.close! if tempfile_b
end
##
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册