Sha256: 76a60703a0ceaa754bb2673c829ca138b7e20cff9dae7dd61418c4176226a033

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'test/unit'
require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
require_relative '../../lib/thread_frame' if '1.9.2' == RUBY_VERSION
require_relative '../../lib/iseq_extra'

$global_test_line = __LINE__

class TestLibISeq < Test::Unit::TestCase

  TEST_LINE = __LINE__

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

  def test_lines
    line = __LINE__
    iseq = RubyVM::Frame::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::Frame::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::Frame.current
      assert(tf.iseq.find_iseq_with_line(line), 
             "should have found line #{line}")
    end
    tf = RubyVM::Frame.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

2 entries across 2 versions & 1 rubygems

Version Path
rb-threadframe-0.41 test/unit/test-lib-iseq.rb
rb-threadframe-0.40 test/unit/test-lib-iseq.rb