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