test_iseq_load.rb: set location

* test/-ext-/iseq_load/test_iseq_load.rb (assert_iseq_roundtrip):
  set path and line number from callers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-01-04 00:26:50 +00:00
Родитель 778d202804
Коммит aee02268bd
1 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

@ -6,7 +6,8 @@ class TestIseqLoad < Test::Unit::TestCase
ISeq = RubyVM::InstructionSequence
def test_bug8543
assert_iseq_roundtrip <<-'end;'
assert_iseq_roundtrip "#{<<~"begin;"}\n#{<<~'end;'}"
begin;
puts "tralivali"
def funct(a, b)
a**b
@ -16,7 +17,8 @@ class TestIseqLoad < Test::Unit::TestCase
end
def test_case_when
assert_iseq_roundtrip <<-'end;'
assert_iseq_roundtrip "#{<<~"begin;"}\n#{<<~'end;'}"
begin;
def user_mask(target)
target.each_char.inject(0) do |mask, chr|
case chr
@ -37,15 +39,21 @@ class TestIseqLoad < Test::Unit::TestCase
end
def test_splatsplat
assert_iseq_roundtrip('def splatsplat(**); end')
assert_iseq_roundtrip("#{<<-"begin;"}\n#{<<-'end;'}")
begin;
def splatsplat(**); end
end;
end
def test_hidden
assert_iseq_roundtrip('def x(a, (b, *c), d: false); end')
assert_iseq_roundtrip("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
def x(a, (b, *c), d: false); end
end;
end
def assert_iseq_roundtrip(src)
a = ISeq.compile(src).to_a
def assert_iseq_roundtrip(src, line=caller_locations(1,1)[0].lineno+1)
a = ISeq.compile(src, __FILE__, __FILE__, line).to_a
b = ISeq.iseq_load(a).to_a
warn diff(a, b) if a != b
assert_equal a, b
@ -54,10 +62,11 @@ class TestIseqLoad < Test::Unit::TestCase
def test_next_in_block_in_block
@next_broke = false
src = <<-'end;'
src, line = "#{<<~"begin;"}#{<<~'end;'}", __LINE__+2
begin;
3.times { 3.times { next; @next_broke = true } }
end;
a = ISeq.compile(src).to_a
a = ISeq.compile(src, __FILE__, __FILE__, line).to_a
iseq = ISeq.iseq_load(a)
iseq.eval
assert_equal false, @next_broke
@ -66,7 +75,8 @@ class TestIseqLoad < Test::Unit::TestCase
end
def test_break_ensure
src = <<-'end;'
src, line = "#{<<~"begin;"}#{<<~'end;'}", __LINE__+2
begin;
def test_break_ensure_def_method
bad = true
while true
@ -79,7 +89,7 @@ class TestIseqLoad < Test::Unit::TestCase
bad
end
end;
a = ISeq.compile(src).to_a
a = ISeq.compile(src, __FILE__, __FILE__, line).to_a
iseq = ISeq.iseq_load(a)
iseq.eval
assert_equal false, test_break_ensure_def_method
@ -88,7 +98,8 @@ class TestIseqLoad < Test::Unit::TestCase
end
def test_kwarg
assert_iseq_roundtrip <<-'end;'
assert_iseq_roundtrip "#{<<~"begin;"}\n#{<<~'end;'}"
begin;
def foo(kwarg: :foo)
kwarg
end