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 }