aboutsummaryrefslogtreecommitdiffstats
path: root/test/objspace
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-11 05:04:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-11 05:04:22 +0000
commitcfb2b14ddce37c3a1c388748e6aaa897ce99923e (patch)
tree02dd20c48609e16108c545be59cbf440251f3933 /test/objspace
parent0f11cda48ca73fdcdbbe9f72e185d017d218d196 (diff)
downloadruby-cfb2b14ddce37c3a1c388748e6aaa897ce99923e.tar.gz
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
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb13
1 files changed, 13 insertions, 0 deletions
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