summaryrefslogtreecommitdiff
path: root/test/objspace/test_objspace.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-07-22 12:47:14 +0200
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-23 10:52:30 +0900
commit6a0cb1d649ecfc3e2af922c74ce82b3ff95fb12a (patch)
tree6483261e24d66c6592b8e3857ca388ff82cf120a /test/objspace/test_objspace.rb
parent5d04ac6ea2fefa4d6e4d22ab9c9903b8ff160167 (diff)
Avoid allocating a string when dumping an anonymous module or class
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3349
Diffstat (limited to 'test/objspace/test_objspace.rb')
-rw-r--r--test/objspace/test_objspace.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 336b30f75a..de270583c1 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -503,4 +503,31 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal h[:immortal_symbol], h[:immortal_dynamic_symbol] + h[:immortal_static_symbol], m
;;;
end
+
+ def test_dump_allocations
+ object = Object.new
+ assert_allocations_count(3) { ObjectSpace.dump(object) }
+ end
+
+ def test_anonymous_class_name
+ klass = Class.new
+ assert_allocations_count(4) { ObjectSpace.dump(klass) }
+ assert_allocations_count(3) { ObjectSpace.dump(klass) }
+
+ mod = Module.new
+ assert_allocations_count(3) { ObjectSpace.dump(mod) }
+
+ assert_not_include ObjectSpace.dump(Class.new), '"name"'
+ assert_not_include ObjectSpace.dump(Module.new), '"name"'
+ end
+
+ private
+
+ def assert_allocations_count(count)
+ ObjectSpace.dump(Object.new) # warming up
+
+ before = GC.stat(:total_allocated_objects)
+ yield
+ assert_equal count, GC.stat(:total_allocated_objects) - before
+ end
end