test and doc updates for conditional breakpoints

use a better description of hit condition and describe the options dict.
This commit is contained in:
Ben Jackson 2020-04-26 11:14:44 +01:00
commit 77dc400077
5 changed files with 218 additions and 9 deletions

View file

@ -295,3 +295,158 @@ function! Test_Insert_Code_Above_Breakpoint()
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 26 )
endfunction
function! SetUp_Test_Conditional_Line_Breakpoint()
let g:vimspector_enable_mappings = 'HUMAN'
endfunction
function! Test_Conditional_Line_Breakpoint()
lcd testdata/cpp/simple
edit simple.cpp
call setpos( '.', [ 0, 16, 1 ] )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 16, 1 )
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 16 )
" Add the conditional breakpoint
call feedkeys( "\\\<F9>argc==0\<CR>\<CR>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 16,
\ 'vimspectorBPCond' )
" Disable the breakpoint
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBPDisabled' )
" Delete the breakpoint
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 16 )
" Add breakpoint using API:
" - on line 16 condition which doesn't match
" - then an unconditional one on line 9, unconditional
" - then on line 17, condition which matches
call vimspector#ToggleBreakpoint( { 'condition': 'argc == 0' } )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBPCond' )
call setpos( '.', [ 0, 9, 1 ] )
call vimspector#ToggleBreakpoint()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 9,
\ 'vimspectorBP' )
call setpos( '.', [ 0, 17, 1 ] )
call vimspector#ToggleBreakpoint( { 'condition': 'argc == 1' } )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 17,
\ 'vimspectorBPCond' )
call setpos( '.', [ 0, 1, 1 ] )
" Start debugging
call vimspector#Continue()
" break on main
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
" Ignore non-matching on line 16, break on line 9
call vimspector#Continue()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 9, 1 )
" Condition matches on line 17
call vimspector#Continue()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 17, 1 )
call vimspector#test#setup#Reset()
lcd -
%bwipeout!
endfunction
function! SetUp_Test_Conditional_Line_Breakpoint_Hit()
let g:vimspector_enable_mappings = 'HUMAN'
endfunction
function! Test_Conditional_Line_Breakpoint_Hit()
let fn = '../support/test/python/simple_python/main.py'
exe 'edit' fn
call setpos( '.', [ 0, 14, 1 ] )
" Add the conditional breakpoint (3 times)
call feedkeys( "\\\<F9>\<CR>3\<CR>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 14,
\ 'vimspectorBPCond' )
call vimspector#LaunchWithSettings( { 'configuration': 'run' } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 14, 1 )
" difficult to check if we really did run 3 times, so just use the watch
" window (also, tests the watch window!)
call vimspector#AddWatch( 'i' )
call WaitForAssert( {->
\ assert_equal( [ ' - Result: 2' ],
\ getbufline( 'vimspector.Watches', '$' ) )
\ } )
call vimspector#test#setup#Reset()
%bwipeout!
endfunction
function! Test_Function_Breakpoint()
lcd testdata/cpp/simple
edit simple.cpp
call vimspector#AddFunctionBreakpoint( 'foo' )
call vimspector#Launch()
" break on main
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
call vimspector#Continue()
" break on func
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 9, 1 )
call vimspector#test#setup#Reset()
%bwipeout!
endfunction
function! Test_Function_Breakpoint_Condition()
lcd testdata/cpp/simple
edit simple.cpp
call vimspector#AddFunctionBreakpoint( 'foo', { 'condition': '1' } )
call vimspector#Launch()
" break on main
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
call vimspector#Continue()
" break on func
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 9, 1 )
call vimspector#test#setup#Reset()
%bwipeout!
endfunction
" Can't find an adapter that supports conditional function breakpoints which are
" probably pretty niche anyway
"
" function! Test_Function_Breakpoint_Condition_False()
" lcd testdata/cpp/simple
" edit simple.cpp
"
" call vimspector#AddFunctionBreakpoint( 'foo', { 'condition': '0' } )
" call setpos( '.', [ 0, 17, 1 ] )
" call vimspector#ToggleBreakpoint()
" call vimspector#Launch()
" " break on main
" call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
" call vimspector#Continue()
"
" " doesn't break in func, break on line 17
" call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 17, 1 )
" call vimspector#test#setup#Reset()
" %bwipeout!
" throw "xfail cpptools doesn't seem to honour conditions on function bps"
" endfunction

View file

@ -32,11 +32,12 @@
" call ch_log( ",,,message..." )
" Then view it in 'debuglog'
" Let a test take up to 1 minute
" Let a test take up to 1 minute, unless debugging
let s:single_test_timeout = 60000
" Restrict the runtimepath to the exact minimum needed for testing
set runtimepath=$PWD/lib,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
let &rtp = getcwd() . '/lib'
set runtimepath+=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
if has('packages')
let &packpath = &runtimepath
endif
@ -70,6 +71,10 @@ func s:TestFailed()
endfunc
func! Abort( timer_id )
if exists( '&debugfunc' ) && &debugfunc != ''
return
endif
call assert_report( 'Test timed out!!!' )
qa!
endfunc
@ -152,6 +157,26 @@ func RunTheTest(test)
\ 'SKIPPED ' . a:test
\ . ': '
\ . substitute(v:exception, '^\S*\s\+', '', ''))
catch /^\cxfail/
if len( v:errors ) == 0
call add(v:errors,
\ 'Expected failure but no error in ' . a:test
\ . ': '
\ . v:exception
\ . ' @ '
\ . g:testpath
\ . ':'
\ . v:throwpoint)
call s:TestFailed()
else
let v:errors = []
call add(s:messages, ' XFAIL' )
call add(s:skipped,
\ 'XFAIL ' . a:test
\ . ': '
\ . substitute(v:exception, '^\S*\s\+', '', ''))
endif
catch
call add(v:errors,
\ 'Caught exception in ' . a:test