From 5c8e14eafdbd88e25115794e29792ccf102f96a9 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 6 Mar 2011 20:05:13 -0500 Subject: [PATCH] Fix another bug; this time in get_source_text --- processor/location.rb | 41 ++++++++++++++++++++++++++++++++- processor/main.rb | 1 - test/unit/test-proc-location.rb | 39 +++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100755 test/unit/test-proc-location.rb diff --git a/processor/location.rb b/processor/location.rb index 5c39b50..527fd10 100644 --- a/processor/location.rb +++ b/processor/location.rb @@ -1,5 +1,6 @@ # Copyright (C) 2010, 2011 Rocky Bernstein require 'linecache' +require 'pathname' # For cleanpath require_relative 'msg' require_relative '../app/frame' class Trepan @@ -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 @@ -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 diff --git a/processor/main.rb b/processor/main.rb index d8524fd..1805881 100644 --- a/processor/main.rb +++ b/processor/main.rb @@ -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 diff --git a/test/unit/test-proc-location.rb b/test/unit/test-proc-location.rb new file mode 100755 index 0000000..bf02bf5 --- /dev/null +++ b/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