Sha256: cea457ed1c6727653609c64d7aa0a1ba5e31cb19b2978fa5ded3b57ea373cbda

Contents?: true

Size: 1.91 KB

Versions: 22

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
require File.expand_path("helper", File.dirname(__FILE__))

# Test of Debugger.debug_load in C extension ruby_debug.so
class TestDebugLoad < Test::Unit::TestCase

  self.test_order = :defined

  class << self
    def at_line(file, line)
      @@at_line = [File.basename(file), line]
    end
  end

  class Debugger::Context
    def at_line(file, line)
      TestDebugLoad::at_line(file, line)
    end
  end

  def test_debug_load
    src_dir = File.dirname(__FILE__)
    prog_script = File.join(src_dir, 'example', 'gcd.rb')

    # Without stopping
    bt = Debugger.debug_load(prog_script, false)
    assert_equal(nil, bt)
    assert(Debugger.started?)
    Debugger.stop

    # With stopping
    bt = Debugger.debug_load(prog_script, true)
    assert_equal(nil, bt)
    assert_equal(['gcd.rb', 4], @@at_line)
    assert(Debugger.started?)
    Debugger.stop

    # Test that we get a proper backtrace on a script that raises 'abc'
    prog_script = File.join(src_dir, 'example', 'raise.rb')
    bt = Debugger.debug_load(prog_script, false)
    assert_equal('abc', bt.to_s)
    assert(Debugger.started?)
    Debugger.stop
  ensure
    Debugger.stop if Debugger.started?
  end

  module MyBootsnap
    def load_iseq(path)
      iseq = RubyVM::InstructionSequence.compile_file(path)

      Debugger.unset_iseq_flags(iseq)
      iseq
    end
  end

  def test_bootsnap
    @@at_line = nil
    src_dir = File.dirname(__FILE__)
    prog_script = File.join(src_dir, 'example', 'bootsnap', 'bootsnap.rb')

    class << RubyVM::InstructionSequence
      prepend MyBootsnap
    end
    bt = Debugger.debug_load(prog_script, true)
    assert_equal(nil, bt)
    assert_not_nil(@@at_line)
    if RUBY_VERSION >= '2.5' && RUBY_VERSION < '2.6'
      assert_equal(['debase.rb', 101], @@at_line)
    end

    assert(Debugger.started?)
    Debugger.stop

    class << RubyVM::InstructionSequence; self end.class_eval { undef_method :load_iseq }

  end
end

Version data entries

22 entries across 12 versions & 3 rubygems

Version Path
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/debase-0.2.5.beta1/test/test_load.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/debase-0.2.5.beta1/test/test_load.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/debase-0.2.4.1/test/test_load.rb
debase-0.2.5.beta1 test/test_load.rb
debase-0.2.4.1 test/test_load.rb
debase-0.2.4 test/test_load.rb