Skip to content

Commit 2de6892

Browse files
committed
test/ruby/test_iseq.rb: hexdump to diff
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent eaf5e34 commit 2de6892

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/ruby/test_iseq.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ class C # line 7 empty class
396396
}
397397
end
398398

399+
def hexdump(bin)
400+
bin.unpack1("H*").gsub(/.{1,32}/) {|s|
401+
"#{'%04x:' % $~.begin(0)}#{s.gsub(/../, " \\&").tap{|_|_[24]&&="-"}}\n"
402+
}
403+
end
404+
399405
def assert_iseq_to_binary(code, mesg = nil)
400406
skip "does not work on other than x86" unless /x(?:86|64)|i\d86/ =~ RUBY_PLATFORM
401407
iseq = RubyVM::InstructionSequence.compile(code)
@@ -406,10 +412,13 @@ def assert_iseq_to_binary(code, mesg = nil)
406412
raise
407413
end
408414
10.times do
409-
assert_equal(bin, iseq.to_binary, mesg)
415+
bin2 = iseq.to_binary
416+
assert_equal(bin, bin2, message(mesg) {diff hexdump(bin), hexdump(bin2)})
410417
end
411418
iseq2 = RubyVM::InstructionSequence.load_from_binary(bin)
412-
assert_equal(iseq.to_a, iseq2.to_a, mesg)
419+
a1 = iseq.to_a
420+
a2 = iseq2.to_a
421+
assert_equal(a1, a2, message(mesg) {diff iseq.disassemble, iseq2.disassemble})
413422
iseq2
414423
end
415424

0 commit comments

Comments
 (0)