Skip to content

Commit

Permalink
Add specs for exception in finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ytjmt authored and eregon committed Dec 26, 2022
1 parent 1ac296c commit 55e1223
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/objectspace/define_finalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,26 @@ def finalizer(zelf)

ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"]
end

ruby_version_is "3.1" do
describe "when $VERBOSE is not nil" do
it "warns if an exception is raised in finalizer" do
code = <<-RUBY
ObjectSpace.define_finalizer(Object.new) { raise "finalizing" }
RUBY

ruby_exe(code, args: "2>&1").should include("warning: Exception in finalizer", "finalizing")
end
end

describe "when $VERBOSE is nil" do
it "does not warn even if an exception is raised in finalizer" do
code = <<-RUBY
ObjectSpace.define_finalizer(Object.new) { raise "finalizing" }
RUBY

ruby_exe(code, args: "2>&1", options: "-W0").should == ""
end
end
end
end

0 comments on commit 55e1223

Please sign in to comment.