summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-05 14:57:05 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-05 14:57:05 +0000
commit00aae60f73bd800d2789501a732cb6ab7c44e528 (patch)
tree2e5108924b55b40d8b4bba20ac95bb887125febd /test
parent5e9b9ff9cb1f7897eb08c1d4f22ae0e206340f49 (diff)
* test/ruby/test_gc.rb: add tests to achieve over 90% test coverage of
gc.c. * test/ruby/test_objectspace.rb: ditto. * test/ruby/test_marshal.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_gc.rb19
-rw-r--r--test/ruby/test_marshal.rb16
-rw-r--r--test/ruby/test_objectspace.rb15
3 files changed, 50 insertions, 0 deletions
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 72c38e4b27..42b249d0dc 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -32,4 +32,23 @@ class TestGc < Test::Unit::TestCase
GC.stress = prev_stress
end
+
+ def test_enable_disable
+ GC.enable
+ assert_equal(false, GC.enable)
+ assert_equal(false, GC.disable)
+ assert_equal(true, GC.disable)
+ assert_equal(true, GC.disable)
+ assert_nil(GC.start)
+ assert_equal(true, GC.enable)
+ assert_equal(false, GC.enable)
+ ensure
+ GC.enable
+ end
+
+ def test_count
+ c = GC.count
+ GC.start
+ assert_operator(c, :<, GC.count)
+ end
end
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index 2c69367e05..c0e6f996e9 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -152,4 +152,20 @@ class TestMarshal < Test::Unit::TestCase
eval("C3 = Struct.new(:foo, :baz)")
assert_raise(TypeError) { Marshal.load(m) }
end
+
+ class C4
+ def initialize(gc)
+ @gc = gc
+ end
+ def _dump(s)
+ GC.start if @gc
+ "foo"
+ end
+ end
+
+ def test_gc
+ assert_nothing_raised do
+ Marshal.dump((0..1000).map {|x| C4.new(x % 50 == 25) })
+ end
+ end
end
diff --git a/test/ruby/test_objectspace.rb b/test/ruby/test_objectspace.rb
index 0b3eea4e09..c82c26a71f 100644
--- a/test/ruby/test_objectspace.rb
+++ b/test/ruby/test_objectspace.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require_relative 'envutil'
class TestObjectSpace < Test::Unit::TestCase
def self.deftest_id2ref(obj)
@@ -53,4 +54,18 @@ End
assert_same(h0, h)
assert_equal(0, h0[:T_FOO])
end
+
+ def test_finalizer
+ EnvUtil.rubyexec("-e", <<-END) do |w, r, e|
+ a = []
+ ObjectSpace.define_finalizer(a) { p :ok }
+ b = a.dup
+ ObjectSpace.define_finalizer(a) { p :ok }
+ END
+ assert_equal("", e.read)
+ assert_equal(":ok\n:ok\n:ok\n:ok\n", r.read)
+
+ assert_raise(ArgumentError) { ObjectSpace.define_finalizer([], Object.new) }
+ end
+ end
end