Skip to content

Commit e8ad728

Browse files
committed
Omit tests using ISeq#to_binary under coverage measurement
... because ISeq#to_binary does not work
1 parent 1c89b1e commit e8ad728

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

test/ruby/test_iseq.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_cdhash_after_roundtrip
9292
42
9393
end
9494
EOF
95-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
95+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
9696
end
9797

9898
def test_forwardable
@@ -102,7 +102,7 @@ def bar(a, b); a + b; end
102102
def foo(...); bar(...); end
103103
}
104104
EOF
105-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval.new.foo(40, 2))
105+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval.new.foo(40, 2))
106106
end
107107

108108
def test_super_with_block
@@ -112,7 +112,7 @@ def (Object.new).touch(*) # :nodoc:
112112
end
113113
42
114114
EOF
115-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
115+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
116116
end
117117

118118
def test_super_with_block_hash_0
@@ -123,7 +123,7 @@ def (Object.new).touch(req, *)
123123
end
124124
42
125125
EOF
126-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
126+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
127127
end
128128

129129
def test_super_with_block_and_kwrest
@@ -133,7 +133,7 @@ def (Object.new).touch(**) # :nodoc:
133133
end
134134
42
135135
EOF
136-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
136+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
137137
end
138138

139139
def test_lambda_with_ractor_roundtrip
@@ -143,7 +143,7 @@ def test_lambda_with_ractor_roundtrip
143143
Ractor.make_shareable(y)
144144
y.call
145145
EOF
146-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
146+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
147147
end
148148

149149
def test_super_with_anonymous_block
@@ -153,7 +153,7 @@ def (Object.new).touch(&) # :nodoc:
153153
end
154154
42
155155
EOF
156-
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
156+
assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval)
157157
end
158158

159159
def test_ractor_unshareable_outer_variable
@@ -182,7 +182,7 @@ def test_ractor_shareable_value_frozen_core
182182
# shareable_constant_value: literal
183183
REGEX = /#{}/ # [Bug #20569]
184184
RUBY
185-
assert_includes iseq.to_binary, "REGEX".b
185+
assert_includes iseq_to_binary(iseq), "REGEX".b
186186
end
187187

188188
def test_disasm_encoding
@@ -566,16 +566,20 @@ def hexdump(bin)
566566
}
567567
end
568568

569+
def iseq_to_binary(iseq)
570+
iseq.to_binary
571+
rescue RuntimeError => e
572+
omit e.message if /compile with coverage/ =~ e.message
573+
raise
574+
end
575+
569576
def assert_iseq_to_binary(code, mesg = nil)
570577
iseq = RubyVM::InstructionSequence.compile(code)
571578
bin = assert_nothing_raised(mesg) do
572-
iseq.to_binary
573-
rescue RuntimeError => e
574-
omit e.message if /compile with coverage/ =~ e.message
575-
raise
579+
iseq_to_binary(iseq)
576580
end
577581
10.times do
578-
bin2 = iseq.to_binary
582+
bin2 = iseq_to_binary(iseq)
579583
assert_equal(bin, bin2, message(mesg) {diff hexdump(bin), hexdump(bin2)})
580584
end
581585
iseq2 = RubyVM::InstructionSequence.load_from_binary(bin)
@@ -593,7 +597,7 @@ def assert_iseq_to_binary(code, mesg = nil)
593597
def test_to_binary_with_hidden_local_variables
594598
assert_iseq_to_binary("for _foo in bar; end")
595599

596-
bin = RubyVM::InstructionSequence.compile(<<-RUBY).to_binary
600+
bin = iseq_to_binary(RubyVM::InstructionSequence.compile(<<-RUBY))
597601
Object.new.instance_eval do
598602
a = []
599603
def self.bar; [1] end
@@ -668,7 +672,7 @@ def self.foo
668672
end
669673
RUBY
670674

671-
iseq_bin = iseq.to_binary
675+
iseq_bin = iseq_to_binary(iseq)
672676
iseq = ISeq.load_from_binary(iseq_bin)
673677
lines = []
674678
TracePoint.new(tracepoint_type){|tp|
@@ -764,7 +768,7 @@ def test_iseq_builtin_to_a
764768
def test_iseq_builtin_load
765769
Tempfile.create(["builtin", ".iseq"]) do |f|
766770
f.binmode
767-
f.write(RubyVM::InstructionSequence.of(1.method(:abs)).to_binary)
771+
f.write(iseq_to_binary(RubyVM::InstructionSequence.of(1.method(:abs))))
768772
f.close
769773
assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~'end;'}")
770774
begin;
@@ -857,7 +861,7 @@ def test_unreachable_next_in_block
857861

858862
def test_loading_kwargs_memory_leak
859863
assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true)
860-
a = RubyVM::InstructionSequence.compile("foo(bar: :baz)").to_binary
864+
a = iseq_to_binary(RubyVM::InstructionSequence.compile("foo(bar: :baz)"))
861865
begin;
862866
1_000_000.times do
863867
RubyVM::InstructionSequence.load_from_binary(a)
@@ -868,7 +872,7 @@ def test_loading_kwargs_memory_leak
868872
def test_ibf_bignum
869873
iseq = RubyVM::InstructionSequence.compile("0x0"+"_0123_4567_89ab_cdef"*5)
870874
expected = iseq.eval
871-
result = RubyVM::InstructionSequence.load_from_binary(iseq.to_binary).eval
875+
result = RubyVM::InstructionSequence.load_from_binary(iseq_to_binary(iseq)).eval
872876
assert_equal expected, result, proc {sprintf("expected: %x, result: %x", expected, result)}
873877
end
874878

0 commit comments

Comments
 (0)