Fix flaky TestWeakMap#test_inspect_garbage

If a GC is ran before the assert_match, then the WeakMap would be empty
and would not have any objects, so the regular expression match would
fail. This changes the regular expression to work even if the WeakMap
is empty.
This commit is contained in:
Peter Zhu 2024-06-18 10:07:27 -04:00
parent b8a592fe6e
commit eb215c8dc6

View File

@ -78,7 +78,7 @@ class TestWeakMap < Test::Unit::TestCase
@wm[i] = Object.new
@wm.inspect
end
assert_match(/\A\#<#{@wm.class.name}:[^:]++:(?:\s\d+\s=>\s\#<(?:Object|collected):[^:<>]*+>(?:,|>\z))+/,
assert_match(/\A\#<#{@wm.class.name}:0x[\da-f]+(?::(?: \d+ => \#<(?:Object|collected):0x[\da-f]+>,?)+)?>\z/,
@wm.inspect)
end