summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-08 23:43:45 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-08 23:43:45 +0000
commitc5768e4366ceacad4aee0874e6b9f7689dd489ca (patch)
tree3d149f95a5dcd0888d7bac5a0096d323c8b0cad9 /test
parent48291d5212849430631b939b99542e1044dfd10c (diff)
ext/objspace/objspace_dump.c: print addresses consistently
The format addresses are printed in are different if you use `ObjectSpace.dump_all(output: :stdout)` vs. `ObjectSpace.dump_all(output: :string)` (or `ObjectSpace.dump`) due to differences in the underlying `vfprintf` implementation. Use %"PRIxPTR" instead to be consistent across both. Co-authored-by: Ashe Connor <ashe@kivikakk.ee> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/objspace/test_objspace.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 0e1ad327b9..947170203a 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -318,6 +318,62 @@ class TestObjSpace < Test::Unit::TestCase
end
end
+ def test_dump_addresses_match_dump_all_addresses
+ assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
+ begin;
+ def dump_my_heap_please
+ obj = Object.new
+ puts ObjectSpace.dump(obj)
+ ObjectSpace.dump_all(output: $stdout)
+ end
+
+ dump_my_heap_please
+ end;
+ needle = JSON.parse(output.first)
+ addr = needle['address']
+ found = output.drop(1).find { |l| JSON.parse(l)['address'] == addr }
+ assert found, "object #{addr} should be findable in full heap dump"
+ end
+ end
+
+ def test_dump_class_addresses_match_dump_all_addresses
+ assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
+ begin;
+ def dump_my_heap_please
+ obj = Object.new
+ puts ObjectSpace.dump(obj)
+ ObjectSpace.dump_all(output: $stdout)
+ end
+
+ dump_my_heap_please
+ end;
+ needle = JSON.parse(output.first)
+ addr = needle['class']
+ found = output.drop(1).find { |l| JSON.parse(l)['address'] == addr }
+ assert found, "object #{addr} should be findable in full heap dump"
+ end
+ end
+
+ def test_dump_reference_addresses_match_dump_all_addresses
+ assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
+ begin;
+ def dump_my_heap_please
+ obj = Object.new
+ obj2 = Object.new
+ obj2.instance_variable_set(:@ref, obj)
+ puts ObjectSpace.dump(obj)
+ ObjectSpace.dump_all(output: $stdout)
+ end
+
+ dump_my_heap_please
+ end;
+ needle = JSON.parse(output.first)
+ addr = needle['address']
+ found = output.drop(1).find { |l| (JSON.parse(l)['references'] || []).include? addr }
+ assert found, "object #{addr} should be findable in full heap dump"
+ end
+ end
+
def test_dump_all
entry = /"bytesize":11, "value":"TEST STRING", "encoding":"UTF-8", "file":"-", "line":4, "method":"dump_my_heap_please", "generation":/