vimspector/tests/temporary_breakpoints.test.vim
Ben Jackson 80985148e7 Add "run to cursor" support
We add a 'temporary' option to line breakpionts and try and clear any
temporary breakpionts on the line we end up stopping on. This might not
be art, but _probably_ works in almost all cases that matter.

it's a bit hacky the way we have to push the reason around, but we don't
know where we stopped until we actually get the stack trace response and
SetCurrentFrame

Move temporary breakpionts to match server response

Also delete any existing ones when adding a new one and add tests for
run-to-cursor.

Only continue after we successfully set the breakpoints. This makes it
work in go
2020-10-23 22:53:04 +01:00

200 lines
6.4 KiB
VimL

function! SetUp()
call vimspector#test#setup#SetUpWithMappings( v:none )
endfunction
function! ClearDown()
call vimspector#test#setup#ClearDown()
endfunction
function s:Start()
call vimspector#SetLineBreakpoint( 'moo.py', 13 )
call vimspector#Launch()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 1, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 1 )
call vimspector#Continue()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 13, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 13 )
endfunction
function Test_Run_To_Cursor_Simple()
" Run to a position that will certainly be executed
lcd ../support/test/python/multiple_files
call vimspector#SetLineBreakpoint( 'moo.py', 13 )
call s:Start()
call cursor( 8, 27 )
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 8, 27 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 8 )
\ } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 9, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 9 )
" Check there is no breakpoint set on line 8
call WaitForAssert( {->
\ vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 8 )
\ } )
call vimspector#test#setup#Reset()
lcd -
%bwipe!
endfunction
function Test_Run_To_Cursor_On_NonBreaking_Line()
" Run to a position that will certainly be executed, but is not a real line
lcd ../support/test/python/multiple_files
call vimspector#SetLineBreakpoint( 'moo.py', 13 )
call s:Start()
call cursor( 7, 1 )
" Interestingly, debugpy moves the breakpoint to the previous line, which is
" kinda annoying
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 6, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 6 )
\ } )
call vimspector#StepOver()
" It's a loop, so we go up a line
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 5, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 5 )
" Check there is no breakpoint set on lines 7 and 6:
" 7 - where we put the 'temporary' breakpoint
" 6 - where it got placed
"
" FIXME: This is broken, we don't _know_ that the breakpoint that was hit was
" the temporary one, and there's no way to know.
"
" I wonder if the relocated breakpoint can be matched with the _original_
" breakpoint
call WaitForAssert( {->
\ vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 7 )
\ } )
call WaitForAssert( {->
\ vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 6 )
\ } )
call vimspector#test#setup#Reset()
lcd -
%bwipe!
endfunction
function Test_Run_To_Cursor_Different_File()
" Run into a different file
" Run to a position that will certainly be executed, but is not a real line
lcd ../support/test/python/multiple_files
call vimspector#SetLineBreakpoint( 'moo.py', 13 )
call s:Start()
edit cow.py
call cursor( 2, 1 )
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'cow.py', 2, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'cow.py', 2 )
\ } )
bu moo.py
call cursor( 9, 12 )
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 9, 12 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 9 )
\ } )
call vimspector#test#setup#Reset()
lcd -
%bwipe!
endfunction
function Test_Run_To_Cursor_Hit_Another_Breakpoint()
" Run to cursor, but hit a non-temporary breakpoint
lcd ../support/test/python/multiple_files
call vimspector#SetLineBreakpoint( 'moo.py', 13 )
call s:Start()
call vimspector#SetLineBreakpoint( 'moo.py', 5 )
call cursor( 6, 1 )
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 5, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 5 )
\ } )
" The temporary breakpoint is still there
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorCode',
\ 6,
\ 'vimspectorBP',
\ 9 )
call vimspector#ClearLineBreakpoint( 'moo.py', 5 )
call cursor( 8, 1 )
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 8, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 8 )
\ } )
call WaitForAssert( {->
\ vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 6 )
\ } )
call vimspector#test#setup#Reset()
lcd -
%bwipe!
endfunction
function! Test_InvalidBreakpoint()
" Run to cursor, but hit a non-temporary breakpoint
lcd ../support/test/python/multiple_files
call vimspector#SetLineBreakpoint( 'moo.py', 13 )
call s:Start()
call vimspector#SetLineBreakpoint( 'moo.py', 9 )
edit .vimspector.json
call cursor( 1, 1 )
call vimspector#RunToCursor()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 9, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 9 )
\ } )
call vimspector#test#setup#Reset()
lcd -
%bwipe!
endfunction
function! Test_StartDebuggingWithRunToCursor()
lcd ../support/test/python/multiple_files
edit moo.py
call cursor( 9, 1 )
call vimspector#RunToCursor()
" Stop on entry is still hit
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 1, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 1 )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorCode',
\ 9,
\ 'vimspectorBP',
\ 9 )
call vimspector#Continue()
" Runs to cursor
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 9, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 9 )
call vimspector#StepOver()
" And claers the temp breakpoint
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'moo.py', 8, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'moo.py', 8 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 9 )
\ } )
lcd -
endfunction