From 483ef3a0d2a6c097ca1606c5cb4a0fae8f3d4f43 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Sat, 20 Dec 2025 17:01:05 -0500 Subject: Test test_remove_instance_variable_re_embed separately Shape tree pollution could cause this test to flake. --- test/ruby/test_object.rb | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index 41585ba150..f4dfe2251b 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -356,40 +356,41 @@ class TestObject < Test::Unit::TestCase end def test_remove_instance_variable_re_embed - require "objspace" + assert_separately(%w[-robjspace], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + c = Class.new do + attr_reader :a, :b, :c - c = Class.new do - attr_reader :a, :b, :c - - def initialize - @a = nil - @b = nil - @c = nil + def initialize + @a = nil + @b = nil + @c = nil + end end - end - o1 = c.new - o2 = c.new - - o1.instance_variable_set(:@foo, 5) - o1.instance_variable_set(:@a, 0) - o1.instance_variable_set(:@b, 1) - o1.instance_variable_set(:@c, 2) - refute_includes ObjectSpace.dump(o1), '"embedded":true' - o1.remove_instance_variable(:@foo) - assert_includes ObjectSpace.dump(o1), '"embedded":true' - - o2.instance_variable_set(:@a, 0) - o2.instance_variable_set(:@b, 1) - o2.instance_variable_set(:@c, 2) - assert_includes ObjectSpace.dump(o2), '"embedded":true' - - assert_equal(0, o1.a) - assert_equal(1, o1.b) - assert_equal(2, o1.c) - assert_equal(0, o2.a) - assert_equal(1, o2.b) - assert_equal(2, o2.c) + o1 = c.new + o2 = c.new + + o1.instance_variable_set(:@foo, 5) + o1.instance_variable_set(:@a, 0) + o1.instance_variable_set(:@b, 1) + o1.instance_variable_set(:@c, 2) + refute_includes ObjectSpace.dump(o1), '"embedded":true' + o1.remove_instance_variable(:@foo) + assert_includes ObjectSpace.dump(o1), '"embedded":true' + + o2.instance_variable_set(:@a, 0) + o2.instance_variable_set(:@b, 1) + o2.instance_variable_set(:@c, 2) + assert_includes ObjectSpace.dump(o2), '"embedded":true' + + assert_equal(0, o1.a) + assert_equal(1, o1.b) + assert_equal(2, o1.c) + assert_equal(0, o2.a) + assert_equal(1, o2.b) + assert_equal(2, o2.c) + end; end def test_convert_string -- cgit v1.2.3