diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-14 16:06:09 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-14 16:06:09 +0000 |
commit | 91aa8da578e64a1f2b4bd3ea75d9c3c48d113e3c (patch) | |
tree | 949fa6145024335a235a1d3f70568ac77d1586fb /test/objspace | |
parent | 6cbe261626f91e8dd9a4c046df69b66884aebeeb (diff) |
objspace_dump.c: refine output
* ext/objspace/objspace_dump.c (dump_output): allow IO object as
output, and use Tempfile.create and return open file instead of
mkstemp() and path name for :file output.
[ruby-core:58266] [Bug #9102]
* test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please):
remove temporary output file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/objspace')
-rw-r--r-- | test/objspace/test_objspace.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 0394a8a92f..850b523862 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -204,17 +204,38 @@ class TestObjSpace < Test::Unit::TestCase end end - def test_dump + def test_dump_to_default + line = nil info = nil ObjectSpace.trace_object_allocations do + line = __LINE__ + 1 str = "hello world" info = ObjectSpace.dump(str) end + assert_dump_object(info, line) + end + + def test_dump_to_io + line = nil + info = IO.pipe do |r, w| + th = Thread.start {r.read} + ObjectSpace.trace_object_allocations do + line = __LINE__ + 1 + str = "hello world" + ObjectSpace.dump(str, output: w) + end + w.close + th.value + end + assert_dump_object(info, line) + end + def assert_dump_object(info, line) + loc = caller_locations(1, 1)[0] assert_match /"type":"STRING"/, info assert_match /"embedded":true, "bytesize":11, "value":"hello world", "encoding":"UTF-8"/, info - assert_match /"file":"#{Regexp.escape __FILE__}", "line":#{__LINE__-6}/, info - assert_match /"method":"test_dump"/, info + assert_match /"file":"#{Regexp.escape __FILE__}", "line":#{line}/, info + assert_match /"method":"#{loc.base_label}"/, info end def test_dump_all @@ -235,13 +256,14 @@ class TestObjSpace < Test::Unit::TestCase ObjectSpace.trace_object_allocations_start GC.start "TEST STRING".force_encoding("UTF-8") - ObjectSpace.dump_all() + ObjectSpace.dump_all().path end puts dump_my_heap_please end; skip if /is not supported/ =~ error assert_match(entry, File.read(output)) + File.unlink(output) end end end |