Sha256: 6ec08bbd323c3623e9d6bc1494a88a7342d602e6ea4429f31bef38c5b527c90a

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require 'test/unit'

class TestISeqBrkpt < Test::Unit::TestCase

  def setup
    @original_compile_option = RubyVM::InstructionSequence.compile_option
    RubyVM::InstructionSequence.compile_option = {
      :trace_instruction => false,
      :specialized_instruction => false
    }
  end

  def teardown
    set_trace_func(nil)
    RubyVM::InstructionSequence.compile_option = @original_compile_option
  end

  def test_iseq_brkpt
    iseq = RubyVM::InstructionSequence.compile('x=1; y=2')
    assert iseq
    assert_equal(nil, iseq.brkpts)
    assert_equal(true, iseq.brkpt_alloc)
    assert_equal([], iseq.brkpts)
    assert_equal(false, iseq.brkpt_alloc)
    
    assert_equal(true, iseq.brkpt_set(0))
    assert_equal(1,    iseq.brkpts.size)
    assert_equal(true, iseq.brkpt_get(0), 'Offset 0 should be set')
    assert_equal(true, iseq.brkpt_unset(0),'Offset 0 should be unset')
    assert_equal(false, iseq.brkpt_get(0), 'Offset 0 should be unset now')
    assert_equal(true, iseq.brkpt_unset(0), 
                 'Offset 0 should be unset again')
    assert_raises TypeError do iseq.brkpt_get(100) end
    assert_equal(true, iseq.brkpt_dealloc)
    assert_equal(false, iseq.brkpt_dealloc)
    assert_equal(true, iseq.brkpt_unset(0),
                 'Offset 0 should be unset even when deallocated')

    assert_raises TypeError do iseq.brkpt_set('a') end

    iseq.brkpt_set(2)    
    iseq.brkpt_set(4)    
    events = []
    eval <<-EOF.gsub(/^.*?: /, "")
     1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass|
     2:   events << [event, lineno, mid, klass]
     3: })
     4: iseq.eval
     5: set_trace_func(nil)
    EOF
    # puts iseq.disassemble
    brkpt_events = events.select{|item| item[0] == 'brkpt'}
    assert_equal(2, brkpt_events.size, 
                 "Expecting to see 2 brkpts in #{events}.inspect")
    assert_equal(true, iseq.brkpt_dealloc)
  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.39 test/ruby/test_brkpt.rb
rb-threadframe-0.37 test/ruby/test_brkpt.rb