Skip to content

Commit

Permalink
Merge pull request #1183 from ruby/finalizer-spec
Browse files Browse the repository at this point in the history
Add more specs for ObjectSpace.define_finalizer
  • Loading branch information
andrykonchin authored Jul 23, 2024
2 parents 46888f9 + c8285d3 commit 56d1337
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/objectspace/define_finalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,31 @@ def finalizer(zelf)
ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"]
end

it "defines same finalizer only once" do
code = <<~RUBY
obj = Object.new
p = proc { |id| print "ok" }
ObjectSpace.define_finalizer(obj, p.dup)
ObjectSpace.define_finalizer(obj, p.dup)
RUBY

ruby_exe(code).should == "ok"
end

it "returns the defined finalizer" do
obj = Object.new
p = proc { |id| }
p2 = p.dup

ret = ObjectSpace.define_finalizer(obj, p)
ret.should == [0, p]
ret[1].should.equal?(p)

ret = ObjectSpace.define_finalizer(obj, p2)
ret.should == [0, p]
ret[1].should.equal?(p)
end

ruby_version_is "3.1" do
describe "when $VERBOSE is not nil" do
it "warns if an exception is raised in finalizer" do
Expand Down

0 comments on commit 56d1337

Please sign in to comment.