From cfb2b14ddce37c3a1c388748e6aaa897ce99923e Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 11 Jun 2016 05:04:22 +0000 Subject: ObjectSpace.dump_all: valid JSON * ext/objspace/objspace_dump.c: generate valid JSON for dump_all. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/objspace/test_objspace.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index f3ea88f6e4..d141fa9161 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -1,6 +1,10 @@ # frozen_string_literal: false require "test/unit" require "objspace" +begin + require "json" +rescue LoadError +end class TestObjSpace < Test::Unit::TestCase def test_memsize_of @@ -218,6 +222,7 @@ class TestObjSpace < Test::Unit::TestCase info = ObjectSpace.dump("foo".freeze) assert_match /"wb_protected":true, "old":true/, info assert_match /"fstring":true/, info + JSON.parse(info) if defined?(JSON) end def test_dump_to_default @@ -252,6 +257,7 @@ class TestObjSpace < Test::Unit::TestCase assert_match /"embedded":true, "bytesize":11, "value":"hello world", "encoding":"UTF-8"/, info assert_match /"file":"#{Regexp.escape __FILE__}", "line":#{line}/, info assert_match /"method":"#{loc.base_label}"/, info + JSON.parse(info) if defined?(JSON) end def test_dump_special_consts @@ -300,6 +306,13 @@ class TestObjSpace < Test::Unit::TestCase assert_match(entry, File.readlines(output).grep(/TEST STRING/).join("\n")) File.unlink(output) end + + if defined?(JSON) + assert_ruby_status(%w[-rjson -robjspace], "#{<<-"begin;"}\n#{<<-"end;"}") + begin; + JSON.parse(ObjectSpace.dump_all(output: :string)) + end; + end end def test_dump_uninitialized_file -- cgit v1.2.3