diff options
author | Chris Seaton <chris@chrisseaton.com> | 2019-07-02 14:19:15 +0100 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-03 04:05:22 +0900 |
commit | 928260c2a613bbdd4402c300e0bf86ae7562e52a (patch) | |
tree | 00e025542b7ae654ea1bc2dd249851f7d912f9b7 /spec/ruby | |
parent | efde19ce440f8656c3ce631a1d2a56e830961e9d (diff) | |
download | ruby-928260c2a613bbdd4402c300e0bf86ae7562e52a.tar.gz |
Warn in verbose mode on defining a finalizer that captures the object
[Feature #15974]
Closes: https://github.com/ruby/ruby/pull/2264
Diffstat (limited to 'spec/ruby')
-rw-r--r-- | spec/ruby/core/objectspace/define_finalizer_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/ruby/core/objectspace/define_finalizer_spec.rb b/spec/ruby/core/objectspace/define_finalizer_spec.rb index b7e47473a0..3a9132ef93 100644 --- a/spec/ruby/core/objectspace/define_finalizer_spec.rb +++ b/spec/ruby/core/objectspace/define_finalizer_spec.rb @@ -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 |