From aee02268bde1f2ec13eec74fe0843cf174824107 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 4 Jan 2018 00:26:50 +0000 Subject: 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 --- test/-ext-/iseq_load/test_iseq_load.rb | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'test/-ext-/iseq_load/test_iseq_load.rb') diff --git a/test/-ext-/iseq_load/test_iseq_load.rb b/test/-ext-/iseq_load/test_iseq_load.rb index 87b28fa56a..97ba3fec66 100644 --- a/test/-ext-/iseq_load/test_iseq_load.rb +++ b/test/-ext-/iseq_load/test_iseq_load.rb @@ -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 -- cgit v1.2.3