1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/ruby/test_iseq.rb: Use __LINE__ to make the error log easy to see

This commit is contained in:
Yusuke Endoh 2021-11-24 15:42:00 +09:00
parent df8f858115
commit 3454a456d1

View file

@ -10,13 +10,16 @@ class TestISeq < Test::Unit::TestCase
end end
def compile(src, line = nil, opt = nil) def compile(src, line = nil, opt = nil)
unless line
line = caller_locations(1).first.lineno
end
EnvUtil.suppress_warning do EnvUtil.suppress_warning do
ISeq.new(src, __FILE__, __FILE__, line, opt) ISeq.new(src, __FILE__, __FILE__, line, opt)
end end
end end
def lines src def lines src, lines = nil
body = compile(src).to_a[13] body = compile(src, lines).to_a[13]
body.find_all{|e| e.kind_of? Integer} body.find_all{|e| e.kind_of? Integer}
end end
@ -25,24 +28,22 @@ class TestISeq < Test::Unit::TestCase
end end
def test_to_a_lines def test_to_a_lines
src = <<-EOS assert_equal [__LINE__+1, __LINE__+2, __LINE__+4], lines(<<-EOS, __LINE__+1)
p __LINE__ # 1 p __LINE__ # 1
p __LINE__ # 2 p __LINE__ # 2
# 3 # 3
p __LINE__ # 4 p __LINE__ # 4
EOS EOS
assert_equal [1, 2, 4], lines(src)
src = <<-EOS assert_equal [__LINE__+2, __LINE__+4], lines(<<-EOS, __LINE__+1)
# 1 # 1
p __LINE__ # 2 p __LINE__ # 2
# 3 # 3
p __LINE__ # 4 p __LINE__ # 4
# 5 # 5
EOS EOS
assert_equal [2, 4], lines(src)
src = <<-EOS assert_equal [__LINE__+3, __LINE__+4, __LINE__+7, __LINE__+9], lines(<<~EOS, __LINE__+1)
1 # should be optimized out 1 # should be optimized out
2 # should be optimized out 2 # should be optimized out
p __LINE__ # 3 p __LINE__ # 3
@ -53,7 +54,6 @@ class TestISeq < Test::Unit::TestCase
8 # should be optimized out 8 # should be optimized out
9 9
EOS EOS
assert_equal [3, 4, 7, 9], lines(src)
end end
def test_unsupported_type def test_unsupported_type
@ -86,7 +86,7 @@ class TestISeq < Test::Unit::TestCase
# CDHASH was not built properly when loading from binary and # CDHASH was not built properly when loading from binary and
# was causing opt_case_dispatch to clobber its stack canary # was causing opt_case_dispatch to clobber its stack canary
# for its "leaf" instruction attribute. # for its "leaf" instruction attribute.
iseq = compile(<<~EOF) iseq = compile(<<~EOF, __LINE__+1)
case Class.new(String).new("foo") case Class.new(String).new("foo")
when "foo" when "foo"
42 42
@ -96,7 +96,7 @@ class TestISeq < Test::Unit::TestCase
end end
def test_super_with_block def test_super_with_block
iseq = compile(<<~EOF) iseq = compile(<<~EOF, __LINE__+1)
def touch(*) # :nodoc: def touch(*) # :nodoc:
foo { super } foo { super }
end end
@ -106,9 +106,9 @@ class TestISeq < Test::Unit::TestCase
end end
def test_super_with_block_hash_0 def test_super_with_block_hash_0
iseq = compile(<<~EOF) iseq = compile(<<~EOF, __LINE__+1)
# [Bug #18250] `req` specifically cause `Assertion failed: (key != 0), function hash_table_raw_insert` # [Bug #18250] `req` specifically cause `Assertion failed: (key != 0), function hash_table_raw_insert`
def touch(req, *) def touch2(req, *)
foo { super } foo { super }
end end
42 42
@ -117,8 +117,8 @@ class TestISeq < Test::Unit::TestCase
end end
def test_super_with_block_and_kwrest def test_super_with_block_and_kwrest
iseq = compile(<<~EOF) iseq = compile(<<~EOF, __LINE__+1)
def touch2(**) # :nodoc: def touch3(**) # :nodoc:
foo { super } foo { super }
end end
42 42
@ -127,7 +127,7 @@ class TestISeq < Test::Unit::TestCase
end end
def test_lambda_with_ractor_roundtrip def test_lambda_with_ractor_roundtrip
iseq = compile(<<~EOF) iseq = compile(<<~EOF, __LINE__+1)
x = 42 x = 42
y = lambda { x } y = lambda { x }
Ractor.make_shareable(y) Ractor.make_shareable(y)
@ -137,7 +137,7 @@ class TestISeq < Test::Unit::TestCase
end end
def test_super_with_anonymous_block def test_super_with_anonymous_block
iseq = compile(<<~EOF) iseq = compile(<<~EOF, __LINE__+1)
def touch3(&) # :nodoc: def touch3(&) # :nodoc:
foo { super } foo { super }
end end
@ -205,16 +205,16 @@ class TestISeq < Test::Unit::TestCase
end end
def test_line_trace def test_line_trace
iseq = compile \ iseq = compile(<<~EOF, __LINE__+1)
%q{ a = 1 a = 1
b = 2 b = 2
c = 3 c = 3
# d = 4 # d = 4
e = 5 e = 5
# f = 6 # f = 6
g = 7 g = 7
EOF
}
assert_equal([1, 2, 3, 5, 7], iseq.line_trace_all) assert_equal([1, 2, 3, 5, 7], iseq.line_trace_all)
iseq.line_trace_specify(1, true) # line 2 iseq.line_trace_specify(1, true) # line 2
iseq.line_trace_specify(3, true) # line 5 iseq.line_trace_specify(3, true) # line 5