1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/test_weakref.rb
nobu 4bce9fc7bd more GCable
* test/test_weakref.rb (make_weakref): more GCable, probably.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-14 02:29:48 +00:00

24 lines
544 B
Ruby

require 'test/unit'
require 'weakref'
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
end
def test_ref
weak, str = make_weakref
assert_equal(str, weak.to_s)
end
def test_recycled
weak, str = make_weakref
assert_nothing_raised(WeakRef::RefError) {weak.to_s}
ObjectSpace.garbage_collect
ObjectSpace.garbage_collect
assert_raise(WeakRef::RefError) {weak.to_s}
end
end