Sha256: 0492662cb0cc11dee340554c660cff338ac1af4421b0b6d9732b6bb377d25def

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

require 'test/unit'
require_relative '../../ext/thread_frame'
require_relative '../../lib/thread_frame'

$global_test_line = __LINE__

class TestLibISeq < Test::Unit::TestCase

  TEST_LINE = __LINE__

  def test_sha1
    iseq1 = RubyVM::ThreadFrame::current.iseq
    iseq2 = RubyVM::ThreadFrame::current.iseq
    assert_equal(iseq1.sha1, iseq2.sha1, 
                 "SHA1 for same threadframe should match")
  end

  def test_lines
    line = __LINE__
    iseq = RubyVM::ThreadFrame::current.iseq
    assert_equal((line-1..__LINE__+2).to_a, iseq.lines,
                 "lines of test_lines() don't match")
  end

  def test_locate_line
    line = __LINE__
    iseq = RubyVM::ThreadFrame::current.iseq
    assert iseq.locate_line(line)
    assert_nil iseq.locate_line(line - 2)
  end

  def test_iseq_with_line
    # FIXME: We get a more stringent test if we test of offset.
    # It is lame how little we can do here.
    line = __LINE__
    def find_line(line) # :nodoc
      tf = RubyVM::ThreadFrame.current
      assert(tf.iseq.find_iseq_with_line(line), 
             "should have found line #{line}")
    end
    tf = RubyVM::ThreadFrame.current
    find_line(line+2)
    # line2 = nil
    # 1.times do 
    #   line2 = __LINE__
    # end
    # find_line(line2)
    # find_line(TEST_LINE)
    # find_line($global_test_line)
  end

end

# We want to double-check we didn't mess up any pointers somewhere.
at_exit { GC.start  }

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rb-threadframe-0.39 test/unit/test-lib-iseq.rb
rb-threadframe-0.38 test/unit/test-lib-iseq.rb
rb-threadframe-0.37 test/unit/test-lib-iseq.rb
rb-threadframe-0.36 test/unit/test-lib-iseq.rb
rb-threadframe-0.35 test/unit/test-lib-iseq.rb
rb-threadframe-0.34 test/unit/test-lib-iseq.rb