[前][次][番号順一覧][スレッド一覧]

ruby-changes:49470

From: nobu <ko1@a...>
Date: Thu, 4 Jan 2018 09:26:55 +0900 (JST)
Subject: [ruby-changes:49470] nobu:r61586 (trunk): test_iseq_load.rb: set location

nobu	2018-01-04 09:26:50 +0900 (Thu, 04 Jan 2018)

  New Revision: 61586

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61586

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

  Modified files:
    trunk/test/-ext-/iseq_load/test_iseq_load.rb
Index: test/-ext-/iseq_load/test_iseq_load.rb
===================================================================
--- test/-ext-/iseq_load/test_iseq_load.rb	(revision 61585)
+++ test/-ext-/iseq_load/test_iseq_load.rb	(revision 61586)
@@ -6,7 +6,8 @@ class TestIseqLoad < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L6
   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::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L17
   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::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L39
   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::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L62
 
   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::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L75
   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::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L89
         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::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/iseq_load/test_iseq_load.rb#L98
   end
 
   def test_kwarg
-    assert_iseq_roundtrip <<-'end;'
+    assert_iseq_roundtrip "#{<<~"begin;"}\n#{<<~'end;'}"
+    begin;
       def foo(kwarg: :foo)
         kwarg
       end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]