diff options
Diffstat (limited to 'test/objspace')
-rw-r--r-- | test/objspace/test_objspace.rb | 50 | ||||
-rw-r--r-- | test/objspace/test_ractor.rb | 24 |
2 files changed, 56 insertions, 18 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 4757c26630..17f73e4433 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -141,6 +141,7 @@ class TestObjSpace < Test::Unit::TestCase end def test_reachable_objects_during_iteration + omit 'flaky on Visual Studio with: [BUG] Unnormalized Fixnum value' if /mswin/ =~ RUBY_PLATFORM opts = %w[--disable-gem --disable=frozen-string-literal -robjspace] assert_separately opts, "#{<<-"begin;"}\n#{<<-'end;'}" begin; @@ -225,6 +226,13 @@ class TestObjSpace < Test::Unit::TestCase assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(o4)) assert_equal(line4, ObjectSpace.allocation_sourceline(o4)) + # The line number should be based on newarray instead of getinstancevariable. + line5 = __LINE__; o5 = [ # newarray (leaf) + @ivar, # getinstancevariable (not leaf) + ] + assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(o5)) + assert_equal(line5, ObjectSpace.allocation_sourceline(o5)) + # [Bug #19482] EnvUtil.under_gc_stress do 100.times do @@ -408,7 +416,7 @@ class TestObjSpace < Test::Unit::TestCase assert_equal('true', ObjectSpace.dump(true)) assert_equal('false', ObjectSpace.dump(false)) assert_equal('0', ObjectSpace.dump(0)) - assert_equal('{"type":"SYMBOL", "value":"foo"}', ObjectSpace.dump(:foo)) + assert_equal('{"type":"SYMBOL", "value":"test_dump_special_consts"}', ObjectSpace.dump(:test_dump_special_consts)) end def test_dump_singleton_class @@ -555,9 +563,30 @@ class TestObjSpace < Test::Unit::TestCase end end + def test_dump_callinfo_includes_mid + assert_in_out_err(%w[-robjspace --disable-gems], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| + begin; + class Foo + def foo + super(bar: 123) # should not crash on 0 mid + end + + def bar + baz(bar: 123) # mid: baz + end + end + + ObjectSpace.dump_all(output: $stdout) + end; + assert_empty error + assert(output.count > 1) + assert_includes output.grep(/"imemo_type":"callinfo"/).join("\n"), '"mid":"baz"' + end + end + def test_dump_string_coderange assert_includes ObjectSpace.dump("TEST STRING"), '"coderange":"7bit"' - unknown = "TEST STRING".dup.force_encoding(Encoding::BINARY) + unknown = "TEST STRING".dup.force_encoding(Encoding::UTF_16BE) 2.times do # ensure that dumping the string doesn't mutate it assert_includes ObjectSpace.dump(unknown), '"coderange":"unknown"' end @@ -632,13 +661,19 @@ class TestObjSpace < Test::Unit::TestCase end end - entry_hash = JSON.parse(test_string_in_dump_all[1]) + strs = test_string_in_dump_all.reject do |s| + s.include?("fstring") + end + + assert_equal(1, strs.length) + + entry_hash = JSON.parse(strs[0]) assert_equal(5, entry_hash["bytesize"], "bytesize is wrong") assert_equal("TEST2", entry_hash["value"], "value is wrong") assert_equal("UTF-8", entry_hash["encoding"], "encoding is wrong") assert_equal("-", entry_hash["file"], "file is wrong") - assert_equal(4, entry_hash["line"], "line is wrong") + assert_equal(5, entry_hash["line"], "line is wrong") assert_equal("dump_my_heap_please", entry_hash["method"], "method is wrong") assert_not_nil(entry_hash["generation"]) end @@ -647,6 +682,7 @@ class TestObjSpace < Test::Unit::TestCase opts = %w[--disable-gem --disable=frozen-string-literal -robjspace] assert_in_out_err(opts, "#{<<-"begin;"}#{<<-'end;'}") do |output, error| + # frozen_string_literal: false begin; def dump_my_heap_please ObjectSpace.trace_object_allocations_start @@ -663,6 +699,7 @@ class TestObjSpace < Test::Unit::TestCase assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}#{<<-'end;'}") do |(output), (error)| begin; + # frozen_string_literal: false def dump_my_heap_please ObjectSpace.trace_object_allocations_start GC.start @@ -793,6 +830,7 @@ class TestObjSpace < Test::Unit::TestCase def test_objspace_trace assert_in_out_err(%w[-robjspace/trace], "#{<<-"begin;"}\n#{<<-'end;'}") do |out, err| begin; + # frozen_string_literal: false a = "foo" b = "b" + "a" + "r" c = 42 @@ -800,8 +838,8 @@ class TestObjSpace < Test::Unit::TestCase end; assert_equal ["objspace/trace is enabled"], err assert_equal 3, out.size - assert_equal '"foo" @ -:2', out[0] - assert_equal '"bar" @ -:3', out[1] + assert_equal '"foo" @ -:3', out[0] + assert_equal '"bar" @ -:4', out[1] assert_equal '42', out[2] end end diff --git a/test/objspace/test_ractor.rb b/test/objspace/test_ractor.rb index b7008ea731..4901eeae2e 100644 --- a/test/objspace/test_ractor.rb +++ b/test/objspace/test_ractor.rb @@ -1,17 +1,17 @@ require "test/unit" class TestObjSpaceRactor < Test::Unit::TestCase - def test_tracing_does_not_crash - assert_ractor(<<~RUBY, require: 'objspace') - ObjectSpace.trace_object_allocations do - r = Ractor.new do - obj = 'a' * 1024 - Ractor.yield obj - end + def test_tracing_does_not_crash + assert_ractor(<<~RUBY, require: 'objspace') + ObjectSpace.trace_object_allocations do + r = Ractor.new do + obj = 'a' * 1024 + Ractor.yield obj + end - r.take - r.take - end - RUBY - end + r.take + r.take + end + RUBY + end end |