From 23378ef7f726391e2f99fad3294463c855211f7f Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 10 Sep 2026 14:27:31 +0900 Subject: [PATCH] Mask object addresses in message assertions The expected message bakes the receiver's `#inspect` into a heredoc before the block raises, so a moving GC that relocates the receiver in between makes the two addresses disagree. That is why these tests fail intermittently under MMTk. `GC.verify_compaction_references` reproduces the same failure with the default GC. https://github.com/ruby/ruby/pull/18731 Co-Authored-By: Claude Opus 5 --- test/test_error_highlight.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/test_error_highlight.rb b/test/test_error_highlight.rb index 76db103..6681d1d 100644 --- a/test/test_error_highlight.rb +++ b/test/test_error_highlight.rb @@ -40,6 +40,12 @@ def preprocess(msg) end end + # A moving GC can relocate the receiver between the expected message baking + # `#inspect` and the error being raised, so the two addresses need not agree. + def mask_addresses(msg) + msg.gsub(/0x\h+/, "0xXXXX") + end + if Exception.method_defined?(:detailed_message) def assert_error_message(klass, expected_msg, &blk) omit unless klass < ErrorHighlight::CoreExt @@ -55,13 +61,14 @@ def assert_error_message(klass, expected_msg, &blk) assert_kind_of(Array, spot[:script_lines]) end end - assert_equal(preprocess(expected_msg).chomp, err.detailed_message(highlight: false).sub(/ \((?:NoMethod|Name)Error\)/, "")) + actual_msg = err.detailed_message(highlight: false).sub(/ \((?:NoMethod|Name)Error\)/, "") + assert_equal(mask_addresses(preprocess(expected_msg).chomp), mask_addresses(actual_msg)) end else def assert_error_message(klass, expected_msg, &blk) omit unless klass < ErrorHighlight::CoreExt err = assert_raise(klass, &blk) - assert_equal(preprocess(expected_msg).chomp, err.message) + assert_equal(mask_addresses(preprocess(expected_msg).chomp), mask_addresses(err.message)) end end