mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Warn in verbose mode on defining a finalizer that captures the object
[Feature #15974] Closes: https://github.com/ruby/ruby/pull/2264
This commit is contained in:
parent
efde19ce44
commit
928260c2a6
2 changed files with 69 additions and 0 deletions
|
|
@ -65,4 +65,30 @@ describe "ObjectSpace.define_finalizer" do
|
|||
|
||||
ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"]
|
||||
end
|
||||
|
||||
it "warns in verbose mode if it is self-referencing" do
|
||||
code = <<-RUBY
|
||||
obj = "Test"
|
||||
handler = Proc.new { puts "finalized" }
|
||||
ObjectSpace.define_finalizer(obj, handler)
|
||||
exit 0
|
||||
RUBY
|
||||
|
||||
ruby_exe(code, :options => "-w", :args => "2>&1").should include("warning: object is reachable from finalizer - it may never be run")
|
||||
end
|
||||
|
||||
it "warns in verbose mode if it is indirectly self-referencing" do
|
||||
code = <<-RUBY
|
||||
def scoped(indirect)
|
||||
Proc.new { puts "finalized" }
|
||||
end
|
||||
obj = "Test"
|
||||
indirect = [obj]
|
||||
handler = scoped(indirect)
|
||||
ObjectSpace.define_finalizer(obj, handler)
|
||||
exit 0
|
||||
RUBY
|
||||
|
||||
ruby_exe(code, :options => "-w", :args => "2>&1").should include("warning: object is reachable from finalizer - it may never be run")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue