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

ruby-changes:69885

From: Yusuke <ko1@a...>
Date: Wed, 24 Nov 2021 15:45:59 +0900 (JST)
Subject: [ruby-changes:69885] 3454a456d1 (master): test/ruby/test_iseq.rb: Use __LINE__ to make the error log easy to see

https://git.ruby-lang.org/ruby.git/commit/?id=3454a456d1

From 3454a456d1005dac799279dae42555759b741fc9 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Wed, 24 Nov 2021 15:42:00 +0900
Subject: test/ruby/test_iseq.rb: Use __LINE__ to make the error log easy to
 see

---
 test/ruby/test_iseq.rb | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 371398134e6..d106caa8408 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -10,13 +10,16 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L10
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L28
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L54
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L86
     # 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L96
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L106
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L117
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L127
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L137
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L205
   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
-- 
cgit v1.2.1


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

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