Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Omit tests using ISeq#to_binary under coverage measurement #13225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions test/ruby/test_iseq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_cdhash_after_roundtrip
42
end
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
end

def test_forwardable
Expand All @@ -102,7 +102,7 @@ def bar(a, b); a + b; end
def foo(...); bar(...); end
}
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval.new.foo(40, 2))
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval.new.foo(40, 2))
end

def test_super_with_block
Expand All @@ -112,7 +112,7 @@ def (Object.new).touch(*) # :nodoc:
end
42
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
end

def test_super_with_block_hash_0
Expand All @@ -123,7 +123,7 @@ def (Object.new).touch(req, *)
end
42
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
end

def test_super_with_block_and_kwrest
Expand All @@ -133,7 +133,7 @@ def (Object.new).touch(**) # :nodoc:
end
42
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
end

def test_lambda_with_ractor_roundtrip
Expand All @@ -143,7 +143,7 @@ def test_lambda_with_ractor_roundtrip
Ractor.make_shareable(y)
y.call
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
end

def test_super_with_anonymous_block
Expand All @@ -153,7 +153,7 @@ def (Object.new).touch(&) # :nodoc:
end
42
EOF
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
end

def test_ractor_unshareable_outer_variable
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_ractor_shareable_value_frozen_core
# shareable_constant_value: literal
REGEX = /#{}/ # [Bug #20569]
RUBY
assert_includes iseq.to_binary, "REGEX".b
assert_includes iseq_to_binary(iseq), "REGEX".b
end

def test_disasm_encoding
Expand Down Expand Up @@ -566,16 +566,20 @@ def hexdump(bin)
}
end

def iseq_to_binary(iseq)
iseq.to_binary
rescue RuntimeError => e
omit e.message if /compile with coverage/ =~ e.message
raise
end

def assert_iseq_to_binary(code, mesg = nil)
iseq = RubyVM::InstructionSequence.compile(code)
bin = assert_nothing_raised(mesg) do
iseq.to_binary
rescue RuntimeError => e
omit e.message if /compile with coverage/ =~ e.message
raise
iseq_to_binary(iseq)
end
10.times do
bin2 = iseq.to_binary
bin2 = iseq_to_binary(iseq)
assert_equal(bin, bin2, message(mesg) {diff hexdump(bin), hexdump(bin2)})
end
iseq2 = RubyVM::InstructionSequence.load_from_binary(bin)
Expand All @@ -593,7 +597,7 @@ def assert_iseq_to_binary(code, mesg = nil)
def test_to_binary_with_hidden_local_variables
assert_iseq_to_binary("for _foo in bar; end")

bin = RubyVM::InstructionSequence.compile(<<-RUBY).to_binary
bin = iseq_to_binary(RubyVM::InstructionSequence.compile(<<-RUBY))
Object.new.instance_eval do
a = []
def self.bar; [1] end
Expand Down Expand Up @@ -668,7 +672,7 @@ def self.foo
end
RUBY

iseq_bin = iseq.to_binary
iseq_bin = iseq_to_binary(iseq)
iseq = ISeq.load_from_binary(iseq_bin)
lines = []
TracePoint.new(tracepoint_type){|tp|
Expand Down Expand Up @@ -764,7 +768,7 @@ def test_iseq_builtin_to_a
def test_iseq_builtin_load
Tempfile.create(["builtin", ".iseq"]) do |f|
f.binmode
f.write(RubyVM::InstructionSequence.of(1.method(:abs)).to_binary)
f.write(iseq_to_binary(RubyVM::InstructionSequence.of(1.method(:abs))))
f.close
assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
Expand Down Expand Up @@ -857,7 +861,7 @@ def test_unreachable_next_in_block

def test_loading_kwargs_memory_leak
assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true)
a = RubyVM::InstructionSequence.compile("foo(bar: :baz)").to_binary
a = iseq_to_binary(RubyVM::InstructionSequence.compile("foo(bar: :baz)"))
begin;
1_000_000.times do
RubyVM::InstructionSequence.load_from_binary(a)
Expand All @@ -868,7 +872,7 @@ def test_loading_kwargs_memory_leak
def test_ibf_bignum
iseq = RubyVM::InstructionSequence.compile("0x0"+"_0123_4567_89ab_cdef"*5)
expected = iseq.eval
result = RubyVM::InstructionSequence.load_from_binary(iseq.to_binary).eval
result = RubyVM::InstructionSequence.load_from_binary(iseq_to_binary(iseq)).eval
assert_equal expected, result, proc {sprintf("expected: %x, result: %x", expected, result)}
end

Expand Down
Loading