test/frame_test.rb in byebug-1.6.1 vs test/frame_test.rb in byebug-1.7.0

- old
+ new

@@ -1,78 +1,144 @@ require_relative 'test_helper' class TestFrame < TestDsl::TestCase + describe 'when byebug started at the beginning' do + before do + @tst_file = fullpath('frame') + enter 'break 23', 'cont' + end - it 'must go up' do - enter 'break 16', 'cont', 'up' - debug_file('frame') { $state.line.must_equal 12 } - end + it 'must go up' do + enter 'up' + debug_file('frame') { $state.line.must_equal 18 } + end - it 'must go up by specific number of frames' do - enter 'break 16', 'cont', 'up 2' - debug_file('frame') { $state.line.must_equal 8 } - end + it 'must go up by specific number of frames' do + enter 'up 2' + debug_file('frame') { $state.line.must_equal 13 } + end - it 'must go down' do - enter 'break 16', 'cont', 'up', 'down' - debug_file('frame') { $state.line.must_equal 16 } - end + it 'must go down' do + enter 'up', 'down' + debug_file('frame') { $state.line.must_equal 23 } + end - it 'must go down by specific number of frames' do - enter 'break 16', 'cont', 'up 3', 'down 2' - debug_file('frame') { $state.line.must_equal 12 } - end + it 'must go down by specific number of frames' do + enter 'up 3', 'down 2' + debug_file('frame') { $state.line.must_equal 18 } + end - it 'must set frame' do - enter 'break 16', 'cont', 'frame 2' - debug_file('frame') { $state.line.must_equal 8 } - end + it 'must set frame' do + enter 'frame 2' + debug_file('frame') { $state.line.must_equal 13 } + end - it 'must set frame to the first one by default' do - enter 'break 16', 'cont', 'up', 'frame' - debug_file('frame') { $state.line.must_equal 16 } - end + it 'must print current stack frame when without arguments' do + enter 'up', 'frame' + debug_file('frame') + check_output_includes /#1 FrameExample\.c\s+at #{@tst_file}:18/ + end - it 'must print current stack frame when without arguments' do - enter 'break A.d', 'cont', 'up', 'frame' - debug_file('frame') - check_output_includes /#0 A.d(e#String) at #{fullpath('frame')}:15/x - end + it 'must set frame to the first one' do + enter 'up', 'frame 0' + debug_file('frame') { $state.line.must_equal 23 } + end - it 'must set frame to the first one' do - enter 'break 16', 'cont', 'up', 'frame 0' - debug_file('frame') { $state.line.must_equal 16 } - end + it 'must set frame to the last one' do + enter 'bt', 'frame -1' + debug_file('frame') { $state.file.must_match /minitest\/unit.rb/ } + check_output_doesnt_include "at #{@tst_file}:" + end - it 'must set frame to the last one' do - enter 'break 16', 'cont', 'bt', 'frame -1' - debug_file('frame') { $state.file.must_match /minitest\/unit.rb/ } - check_output_doesnt_include "at #{fullpath('frame')}:" - end + it 'must not set frame if the frame number is too low' do + enter 'down' + debug_file('frame') { $state.line.must_equal 23 } + check_output_includes \ + "Can't navigate beyond the newest frame", interface.error_queue + end - it 'must not set frame if the frame number is too low' do - enter 'break 16', 'cont', 'down' - debug_file('frame') { $state.line.must_equal 16 } - check_output_includes \ - 'Adjusting would put us beyond the newest frame.', interface.error_queue - end + it 'must not set frame if the frame number is too high' do + enter 'up 100' + debug_file('frame') { $state.line.must_equal 23 } + check_output_includes \ + "Can't navigate beyond the oldest frame", interface.error_queue + end - it 'must not set frame if the frame number is too high' do - enter 'break 16', 'cont', 'up 100' - debug_file('frame') { $state.line.must_equal 16 } - check_output_includes \ - 'Adjusting would put us beyond the oldest frame.', interface.error_queue + describe 'fullpath' do + def short_path(fullpath) + separator = File::ALT_SEPARATOR || File::SEPARATOR + "...#{separator}" + fullpath.split(separator)[-3..-1].join(separator) + end + + describe 'when set' do + temporary_change_hash Byebug::Command.settings, :frame_fullpath, true + + it 'must display current backtrace with fullpaths' do + enter 'where' + debug_file 'frame' + check_output_includes \ + /--> #0 FrameExample\.d\(e#String\)\s+at #{@tst_file}:23/, + /#1 FrameExample\.c\s+at #{@tst_file}:18/, + /#2 FrameExample\.b\s+at #{@tst_file}:13/ + end + end + + describe 'when unset' do + temporary_change_hash Byebug::Command.settings, :frame_fullpath, false + + it 'must display current backtrace with shortpaths' do + enter 'where' + debug_file 'frame' + check_output_includes \ + /--> #0 FrameExample\.d\(e#String\)\s+at #{short_path(@tst_file)}:23/, + /#1 FrameExample\.c\s+at #{short_path(@tst_file)}:18/, + /#2 FrameExample\.b\s+at #{short_path(@tst_file)}:13/, + /#3 FrameExample\.a\s+at #{short_path(@tst_file)}:9/ + end + end + end + + describe 'callstyle' do + describe 'long' do + temporary_change_hash Byebug::Command.settings, :callstyle, :long + + it 'displays current backtrace with callstyle "long"' do + enter 'where' + debug_file 'frame' + check_output_includes \ + /--> #0 FrameExample\.d\(e#String\)\s+at #{@tst_file}:23/, + /#1 FrameExample\.c\s+at #{@tst_file}:18/, + /#2 FrameExample\.b\s+at #{@tst_file}:13/, + /#3 FrameExample\.a\s+at #{@tst_file}:9/ + end + end + + describe 'short' do + temporary_change_hash Byebug::Command.settings, :callstyle, :short + + it 'displays current backtrace with callstyle "short"' do + enter 'where' + debug_file 'frame' + check_output_includes /--> #0 d\(e\)\s+at #{@tst_file}:23/, + /#1 c\s+at #{@tst_file}:18/, + /#2 b\s+at #{@tst_file}:13/, + /#3 a\s+at #{@tst_file}:9/ + end + end + end end describe 'when byebug is started deep in the callstack' do + before { @tst_file = fullpath('frame_deep') } + it 'must print backtrace' do enter 'break 16', 'cont', 'where' debug_file 'frame_deep' check_output_includes \ - /--> #0 A.d(e#String) at #{fullpath('frame_deep')}:16/x, - /#1 A.c at #{fullpath('frame_deep')}:13/x, - /#2 A.b at #{fullpath('frame_deep')}:8/x + /--> #0 FrameDeepExample\.d\(e#String\)\s+at #{@tst_file}:16/, + /#1 FrameDeepExample\.c\s+at #{@tst_file}:13/, + /#2 FrameDeepExample\.b\s+at #{@tst_file}:8/ end it 'must go up' do enter 'break 16', 'cont', 'up' debug_file('frame_deep') { $state.line.must_equal 13 } @@ -93,75 +159,46 @@ debug_file('frame_deep') check_output_includes 'nil', '3', '2' end end - describe 'fullpath' do - def short_path(fullpath) - separator = File::ALT_SEPARATOR || File::SEPARATOR - "...#{separator}" + fullpath.split(separator)[-3..-1].join(separator) + describe 'c-frames (issue #10)' do + before do + @tst_file = fullpath('frame') + enter 'break 5', 'cont' end - describe 'when set' do - temporary_change_hash Byebug::Command.settings, :frame_fullpath, true - - it 'must display current backtrace with fullpaths' do - enter 'break 16', 'cont', 'where' - debug_file 'frame' - check_output_includes \ - /--> #0 A.d(e#String) at #{fullpath('frame')}:16/x, - /#1 A.c at #{fullpath('frame')}:12/x, - /#2 A.b at #{fullpath('frame')}:8/x - end + it 'must mark c-frames when printing the stack' do + enter 'where' + debug_file 'frame' + check_output_includes \ + /--> #0 FrameExample.initialize\(f#String\)\s+at #{@tst_file}:5/, + /ͱ-- #1 Class.new\(\*args\)\s+at #{@tst_file}:28/, + /#2 <top \(required\)>\s+at #{@tst_file}:28/ end - describe 'when unset' do - temporary_change_hash Byebug::Command.settings, :frame_fullpath, false - - it 'must display current backtrace with shortpaths' do - enter 'set nofullpath', 'break 16', 'cont', 'where' - debug_file 'frame' - check_output_includes \ - /--> #0 A.d(e#String) at #{short_path(fullpath('frame'))}:16/x, - /#1 A.c at #{short_path(fullpath('frame'))}:12/x, - /#2 A.b at #{short_path(fullpath('frame'))}:8/x - end + it 'must not navigate "up" to c-frames' do + enter 'up', 'eval local_var' + debug_file 'frame' + check_output_includes '"hola"' end - end - describe 'callstyle' do - describe 'long' do - temporary_change_hash Byebug::Command.settings, :callstyle, :long - - it 'displays current backtrace with callstyle "long"' do - enter 'break 16', 'cont', 'where' - debug_file 'frame' - check_output_includes \ - /--> #0 A.d(e#String) at #{fullpath('frame')}:16/x, - /#1 A.c at #{fullpath('frame')}:12/x , - /#2 A.b at #{fullpath('frame')}:8/x , - /#3 A.a at #{fullpath('frame')}:5/x - end + it 'must not navigate "down" to c-frames' do + enter 'up', 'down', 'eval f' + debug_file 'frame' + check_output_includes '"f"' end - describe 'short' do - temporary_change_hash Byebug::Command.settings, :callstyle, :short - - it 'displays current backtrace with callstyle "short"' do - enter 'break 16', 'cont', 'where' - debug_file 'frame' - check_output_includes /--> #0 d(e) at #{fullpath('frame')}:16/x, - /#1 c at #{fullpath('frame')}:12/x, - /#2 b at #{fullpath('frame')}:8/x, - /#3 a at #{fullpath('frame')}:5/x - end + it 'must not jump straigh to c-frames' do + enter 'frame 1' + debug_file 'frame' + check_output_includes "Can't navigate to c-frame", interface.error_queue end end describe 'Post Mortem' do it 'must work in post-mortem mode' do enter 'cont', 'frame' debug_file('post_mortem') { $state.line.must_equal 8 } end end - end