1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test_weakref.rb: use single level WeakRef

* test/test_weakref.rb (make_weakref): return single level
  WeakRef, instead of multiple level, since the second level
  object may be still alive even after the final object get
  finalized, in test_recycled.

* test/test_weakref.rb (test_ref): move living object assertions
  from test_recycled.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-12-12 06:17:23 +00:00
parent 1149533821
commit 994bb6d36d

View file

@ -4,21 +4,22 @@ require_relative './ruby/envutil'
class TestWeakRef < Test::Unit::TestCase
def make_weakref(level = 10)
obj = Object.new
str = obj.to_s
level.times {obj = WeakRef.new(obj)}
return WeakRef.new(obj), str
if level > 0
make_weakref(level - 1)
else
WeakRef.new(Object.new)
end
end
def test_ref
weak, str = make_weakref
assert_equal(str, weak.to_s)
obj = Object.new
weak = WeakRef.new(obj)
assert_equal(obj.to_s, weak.to_s)
assert_predicate(weak, :weakref_alive?)
end
def test_recycled
weak, str = make_weakref
assert_nothing_raised(WeakRef::RefError) {weak.to_s}
assert_predicate(weak, :weakref_alive?)
weak = make_weakref
ObjectSpace.garbage_collect
ObjectSpace.garbage_collect
assert_raise(WeakRef::RefError) {weak.to_s}