Skip to content

Commit

Permalink
Fix another bug; this time in get_source_text
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Mar 7, 2011
1 parent 75f37d4 commit 5c8e14e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
41 changes: 40 additions & 1 deletion processor/location.rb
@@ -1,5 +1,6 @@
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
require 'linecache'
require 'pathname' # For cleanpath
require_relative 'msg'
require_relative '../app/frame'
class Trepan
Expand Down Expand Up @@ -28,7 +29,7 @@ def canonic_file(filename)
def current_source_text
opts = {:reload_on_change => @reload_on_change}
junk1, junk2, text, found_line =
loc_and_text(nil, frame, frame.source_location[0],
loc_and_text('', frame, frame.source_location[0],
frame.source_container, opts)
text
end
Expand Down Expand Up @@ -169,3 +170,41 @@ def source_location_info(source_container, line_no, frame)

end
end

if __FILE__ == $0 && caller.size == 0 && ARGV.size > 0
# Demo it.
puts "++++++++++++HAY!"
puts caller.size
puts caller
require 'thread_frame'
require_relative 'frame'
require_relative '../app/mock'
require_relative 'main' # Have to include before defining CmdProcessor!
# FIXME
class Trepan::CmdProcessor
def errmsg(msg)
puts msg
end
def print_location
puts "#{@frame.source_container} #{frame.source_location[0]}"
end
end

proc = Trepan::CmdProcessor.new(Trepan::MockCore.new())
proc.instance_variable_set('@settings', {})
proc.frame_initialize
proc.frame_setup(RubyVM::ThreadFrame.current)
proc.frame_initialize

proc.location_initialize
puts proc.canonic_file(__FILE__)
proc.instance_variable_set('@settings', {:basename => true})
puts proc.canonic_file(__FILE__)
puts proc.current_source_text
xx = eval <<-END
proc.frame_initialize
proc.frame_setup(RubyVM::ThreadFrame.current)
proc.location_initialize
proc.current_source_text
END
end
1 change: 0 additions & 1 deletion processor/main.rb
Expand Up @@ -3,7 +3,6 @@
# command class and debugger command objects are pulled in from here.

require 'set'
require 'pathname' # For cleanpath

%w(default breakpoint display eventbuf eval load_cmds location frame hook msg
running validate).each do
Expand Down
39 changes: 39 additions & 0 deletions test/unit/test-proc-location.rb
@@ -0,0 +1,39 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'thread_frame'
require_relative '../../processor/main' # Have to include before frame!
# FIXME
require_relative '../../processor/frame'
require_relative '../../app/mock'

$errors = []
$msgs = []

# Test Debugger:CmdProcessor Location portion
class TestProcLocation < Test::Unit::TestCase

def setup
$errors = []
$msgs = []
@proc = Trepan::CmdProcessor.new(Trepan::MockCore.new())
@proc.instance_variable_set('@settings', {:basename => true})
@proc.frame_index = 0
@proc.frame_initialize
@proc.location_initialize
class << @proc
def errmsg(msg)
$errors << msg
end
end
end

def test_it
assert_equal File.basename(__FILE__), @proc.canonic_file(__FILE__)
eval <<-EOE
@proc.frame_initialize
@proc.frame_setup(RubyVM::ThreadFrame.current)
@proc.location_initialize
assert @proc.current_source_text
EOE
end
end

0 comments on commit 5c8e14e

Please sign in to comment.