Fix some asserts
This commit is contained in:
parent
a7f5b46e00
commit
e6904acddd
4 changed files with 202 additions and 107 deletions
|
|
@ -42,41 +42,6 @@ function! SetUp_Test_Signs_Placed_Using_API_Are_Shown()
|
||||||
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
|
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! AssertSignGroupSingletonAtLine( group,
|
|
||||||
\ line,
|
|
||||||
\ sign_name )
|
|
||||||
|
|
||||||
let signs = sign_getplaced( '%', {
|
|
||||||
\ 'group': a:group,
|
|
||||||
\ 'line': a:line,
|
|
||||||
\ } )
|
|
||||||
|
|
||||||
call assert_equal( 1, len( signs ) )
|
|
||||||
call assert_equal( 1, len( signs[ 0 ].signs ) )
|
|
||||||
call assert_equal( a:sign_name, signs[ 0 ].signs[ 0 ].name )
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
function! AssertSignGroupEmptyAtLine( group, line )
|
|
||||||
let signs = sign_getplaced( '%', {
|
|
||||||
\ 'group': 'VimspectorBP',
|
|
||||||
\ 'line': line( '.' )
|
|
||||||
\ } )
|
|
||||||
|
|
||||||
call assert_equal( 1, len( signs ) )
|
|
||||||
call assert_equal( 0, len( signs[ 0 ].signs ) )
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
function! AssertSignGroupEmpty( group )
|
|
||||||
let signs = sign_getplaced( '%', {
|
|
||||||
\ 'group': 'VimspectorBP'
|
|
||||||
\ } )
|
|
||||||
call assert_equal( 1, len( signs ) )
|
|
||||||
call assert_equal( 0, len( signs[ 0 ].signs ) )
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
function! Test_Signs_Placed_Using_API_Are_Shown()
|
function! Test_Signs_Placed_Using_API_Are_Shown()
|
||||||
" We need a real file
|
" We need a real file
|
||||||
edit testdata/cpp/simple/simple.cpp
|
edit testdata/cpp/simple/simple.cpp
|
||||||
|
|
@ -86,62 +51,30 @@ function! Test_Signs_Placed_Using_API_Are_Shown()
|
||||||
call vimspector#ToggleBreakpoint()
|
call vimspector#ToggleBreakpoint()
|
||||||
|
|
||||||
call assert_true( exists( '*vimspector#ToggleBreakpoint' ) )
|
call assert_true( exists( '*vimspector#ToggleBreakpoint' ) )
|
||||||
call AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
||||||
\ line( '.' ),
|
\ line( '.' ),
|
||||||
\ 'vimspectorBP' )
|
\ 'vimspectorBP' )
|
||||||
|
|
||||||
" Disable breakpoint
|
" Disable breakpoint
|
||||||
call vimspector#ToggleBreakpoint()
|
call vimspector#ToggleBreakpoint()
|
||||||
call AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
\ line( '.' ),
|
\ 'VimspectorBP',
|
||||||
\ 'vimspectorBPDisabled' )
|
\ line( '.' ),
|
||||||
|
\ 'vimspectorBPDisabled' )
|
||||||
|
|
||||||
" Remove breakpoint
|
" Remove breakpoint
|
||||||
call vimspector#ToggleBreakpoint()
|
call vimspector#ToggleBreakpoint()
|
||||||
|
|
||||||
call AssertSignGroupEmptyAtLine( 'VimspectorBP', line( '.' ) )
|
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP',
|
||||||
|
\ line( '.' ) )
|
||||||
|
|
||||||
call vimspector#ClearBreakpoints()
|
call vimspector#ClearBreakpoints()
|
||||||
call AssertSignGroupEmpty( 'VimspectorBP' )
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorBP' )
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorCode' )
|
||||||
|
|
||||||
%bwipeout!
|
%bwipeout!
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! AssertCursorIsAtLineInBuffer( buffer, line, column )
|
|
||||||
call WaitForAssert( {->
|
|
||||||
\ assert_equal( a:buffer, bufname( '%' ), 'Current buffer' )
|
|
||||||
\ }, 10000 )
|
|
||||||
call WaitForAssert( {->
|
|
||||||
\ assert_equal( a:line, line( '.' ), 'Current line' )
|
|
||||||
\ }, 10000 )
|
|
||||||
call assert_equal( a:column, col( '.' ), 'Current column' )
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! AssertPCIsAtLineInBuffer( buffer, line )
|
|
||||||
let signs = sign_getplaced( a:buffer, {
|
|
||||||
\ 'group': 'VimspectorCode',
|
|
||||||
\ } )
|
|
||||||
|
|
||||||
call assert_equal( 1, len( signs ), 'Sign-buffers' )
|
|
||||||
call assert_true( len( signs[ 0 ].signs ) >= 1, 'Signs in buffer' )
|
|
||||||
|
|
||||||
let pc_index = -1
|
|
||||||
let index = 0
|
|
||||||
while index < len( signs[ 0 ].signs )
|
|
||||||
let s = signs[ 0 ].signs[ index ]
|
|
||||||
if s.name ==# 'vimspectorPC'
|
|
||||||
if pc_index >= 0
|
|
||||||
call assert_report( 'Found too many PC signs!' )
|
|
||||||
endif
|
|
||||||
let pc_index = index
|
|
||||||
endif
|
|
||||||
let index = index + 1
|
|
||||||
endwhile
|
|
||||||
call assert_true( pc_index >= 0 )
|
|
||||||
call assert_equal( a:line, signs[ 0 ].signs[ pc_index ].lnum )
|
|
||||||
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! SetUp_Test_Use_Mappings_HUMAN()
|
function! SetUp_Test_Use_Mappings_HUMAN()
|
||||||
let g:vimspector_enable_mappings = 'HUMAN'
|
let g:vimspector_enable_mappings = 'HUMAN'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
@ -151,32 +84,32 @@ function! Test_Use_Mappings_HUMAN()
|
||||||
edit simple.cpp
|
edit simple.cpp
|
||||||
call setpos( '.', [ 0, 15, 1 ] )
|
call setpos( '.', [ 0, 15, 1 ] )
|
||||||
|
|
||||||
call AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 )
|
||||||
call AssertSignGroupEmptyAtLine( 'VimspectorBP',
|
|
||||||
\ 15 )
|
|
||||||
|
|
||||||
" Add the breakpoint
|
" Add the breakpoint
|
||||||
call feedkeys( "\<F9>", 'xt' )
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
call AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
||||||
\ 15,
|
\ 15,
|
||||||
\ 'vimspectorBP' )
|
\ 'vimspectorBP' )
|
||||||
|
|
||||||
" Disable the breakpoint
|
" Disable the breakpoint
|
||||||
call feedkeys( "\<F9>", 'xt' )
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
call AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
\ 15,
|
\ 'VimspectorBP',
|
||||||
\ 'vimspectorBPDisabled' )
|
\ 15,
|
||||||
|
\ 'vimspectorBPDisabled' )
|
||||||
|
|
||||||
" Delete the breakpoint
|
" Delete the breakpoint
|
||||||
call feedkeys( "\<F9>", 'xt' )
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
call AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 )
|
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 )
|
||||||
|
|
||||||
" Add it again
|
" Add it again
|
||||||
call feedkeys( "\<F9>", 'xt' )
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
call AssertSignGroupSingletonAtLine( 'VimspectorBP',
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
\ 15,
|
\ 'VimspectorBP',
|
||||||
\ 'vimspectorBP' )
|
\ 15,
|
||||||
|
\ 'vimspectorBP' )
|
||||||
|
|
||||||
" Here we go. Start Debugging
|
" Here we go. Start Debugging
|
||||||
call feedkeys( "\<F5>", 'xt' )
|
call feedkeys( "\<F5>", 'xt' )
|
||||||
|
|
@ -185,13 +118,13 @@ function! Test_Use_Mappings_HUMAN()
|
||||||
let cur_tabnr = tabpagenr()
|
let cur_tabnr = tabpagenr()
|
||||||
call assert_equal( 5, len( gettabinfo( cur_tabnr )[ 0 ].windows ) )
|
call assert_equal( 5, len( gettabinfo( cur_tabnr )[ 0 ].windows ) )
|
||||||
|
|
||||||
call AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
||||||
|
|
||||||
" Step
|
" Step
|
||||||
call feedkeys( "\<F10>", 'xt' )
|
call feedkeys( "\<F10>", 'xt' )
|
||||||
|
|
||||||
call AssertCursorIsAtLineInBuffer( 'simple.cpp', 16, 1 )
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 16, 1 )
|
||||||
call AssertPCIsAtLineInBuffer( '%', 16 )
|
call vimspector#test#signs#AssertPCIsAtLineInBuffer( '%', 16 )
|
||||||
|
|
||||||
call vimspector#test#setup#Reset()
|
call vimspector#test#setup#Reset()
|
||||||
|
|
||||||
|
|
@ -211,11 +144,83 @@ function Test_StopAtEntry()
|
||||||
" Test stopAtEntry behaviour
|
" Test stopAtEntry behaviour
|
||||||
call feedkeys( "\<F5>", 'xt' )
|
call feedkeys( "\<F5>", 'xt' )
|
||||||
|
|
||||||
call AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
||||||
call AssertPCIsAtLineInBuffer( 'simple.cpp', 15 )
|
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'simple.cpp', 15 )
|
||||||
|
|
||||||
call vimspector#test#setup#Reset()
|
call vimspector#test#setup#Reset()
|
||||||
|
|
||||||
lcd -
|
lcd -
|
||||||
%bwipeout!
|
%bwipeout!
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SetUp_Test_DisableBreakpointWhileDebugging()
|
||||||
|
let g:vimspector_enable_mappings = 'HUMAN'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function Test_DisableBreakpointWhileDebugging()
|
||||||
|
lcd testdata/cpp/simple
|
||||||
|
edit simple.cpp
|
||||||
|
call setpos( '.', [ 0, 15, 1 ] )
|
||||||
|
|
||||||
|
" Test stopAtEntry behaviour
|
||||||
|
call feedkeys( "\<F5>", 'xt' )
|
||||||
|
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
||||||
|
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'simple.cpp', 15 )
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorBP' )
|
||||||
|
|
||||||
|
call setpos( '.', [ 0, 16, 1 ] )
|
||||||
|
|
||||||
|
" Add the breakpoint
|
||||||
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
|
call WaitForAssert( {->
|
||||||
|
\ vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
|
\ 'VimspectorCode',
|
||||||
|
\ 16,
|
||||||
|
\ 'vimspectorBP' )
|
||||||
|
\ } )
|
||||||
|
|
||||||
|
" Remove the breakpoint
|
||||||
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 16 )
|
||||||
|
|
||||||
|
" Add the breakpoint
|
||||||
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
|
\ 'VimspectorCode',
|
||||||
|
\ 16,
|
||||||
|
\ 'vimspectorBP' )
|
||||||
|
|
||||||
|
call vimspector#Reset()
|
||||||
|
call WaitForAssert( {->
|
||||||
|
\ assert_true ( pyxeval( '_vimspector_session._connection is None' ) )
|
||||||
|
\ } )
|
||||||
|
|
||||||
|
" Check breakpoint is now a user breakpoint
|
||||||
|
call setpos( '.', [ bufnr( 'simple.cpp' ), 1, 1 ] )
|
||||||
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
|
\ 'VimspectorBP',
|
||||||
|
\ 16,
|
||||||
|
\ 'vimspectorBP' )
|
||||||
|
|
||||||
|
" Disable the breakpoint
|
||||||
|
call setpos( '.', [ bufnr( 'simple.cpp' ), 16, 1 ] )
|
||||||
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
|
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
|
\ 'VimspectorBP',
|
||||||
|
\ 16,
|
||||||
|
\ 'vimspectorBPDisabled' )
|
||||||
|
|
||||||
|
" And delete it
|
||||||
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmptyAtLine(
|
||||||
|
\ 'VimspectorBP',
|
||||||
|
\ 16 )
|
||||||
|
|
||||||
|
call vimspector#ClearBreakpoints()
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorBP' )
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorCode' )
|
||||||
|
|
||||||
|
lcd -
|
||||||
|
%bwipeout!
|
||||||
|
endfunction
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,12 @@ endfunction
|
||||||
|
|
||||||
function! vimspector#test#setup#Reset() abort
|
function! vimspector#test#setup#Reset() abort
|
||||||
call vimspector#Reset()
|
call vimspector#Reset()
|
||||||
call AssertSignGroupEmpty( 'VimspectorCode' )
|
|
||||||
|
|
||||||
call vimspector#ClearBreakpoints()
|
|
||||||
call AssertSignGroupEmpty( 'VimspectorBP' )
|
|
||||||
|
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
\ assert_true( pyxeval( '_vimspector_session._connection is None' ) )
|
\ assert_true( pyxeval( '_vimspector_session._connection is None' ) )
|
||||||
\ } )
|
\ } )
|
||||||
|
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorCode' )
|
||||||
|
call vimspector#ClearBreakpoints()
|
||||||
|
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorBP' )
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
||||||
87
tests/lib/autoload/vimspector/test/signs.vim
Normal file
87
tests/lib/autoload/vimspector/test/signs.vim
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
function! vimspector#test#signs#AssertCursorIsAtLineInBuffer( buffer,
|
||||||
|
\ line,
|
||||||
|
\ column ) abort
|
||||||
|
call WaitForAssert( {->
|
||||||
|
\ assert_equal( a:buffer, bufname( '%' ), 'Current buffer' )
|
||||||
|
\ }, 10000 )
|
||||||
|
call WaitForAssert( {->
|
||||||
|
\ assert_equal( a:line, line( '.' ), 'Current line' )
|
||||||
|
\ }, 10000 )
|
||||||
|
call assert_equal( a:column, col( '.' ), 'Current column' )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#test#signs#AssertPCIsAtLineInBuffer( buffer, line ) abort
|
||||||
|
let signs = sign_getplaced( a:buffer, {
|
||||||
|
\ 'group': 'VimspectorCode',
|
||||||
|
\ } )
|
||||||
|
|
||||||
|
call assert_equal( 1, len( signs ), 'Number of buffers named ' . a:buffer )
|
||||||
|
call assert_true( len( signs[ 0 ].signs ) >= 1,
|
||||||
|
\ 'At least one VimspectorCode sign' )
|
||||||
|
|
||||||
|
let pc_index = -1
|
||||||
|
let index = 0
|
||||||
|
while index < len( signs[ 0 ].signs )
|
||||||
|
let s = signs[ 0 ].signs[ index ]
|
||||||
|
if s.name ==# 'vimspectorPC'
|
||||||
|
call assert_false( pc_index >= 0, 'Too many PC signs' )
|
||||||
|
let pc_index = index
|
||||||
|
endif
|
||||||
|
let index = index + 1
|
||||||
|
endwhile
|
||||||
|
call assert_true( pc_index >= 0 )
|
||||||
|
call assert_equal( a:line, signs[ 0 ].signs[ pc_index ].lnum )
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#test#signs#AssertSignGroupSingletonAtLine( group,
|
||||||
|
\ line,
|
||||||
|
\ sign_name )
|
||||||
|
\ abort
|
||||||
|
|
||||||
|
let signs = sign_getplaced( '%', {
|
||||||
|
\ 'group': a:group,
|
||||||
|
\ 'lnum': a:line,
|
||||||
|
\ } )
|
||||||
|
|
||||||
|
return assert_equal( 1,
|
||||||
|
\ len( signs ),
|
||||||
|
\ 'Num buffers named %' ) &&
|
||||||
|
\ assert_equal( 1,
|
||||||
|
\ len( signs[ 0 ].signs ),
|
||||||
|
\ 'Num signs in ' . a:group . ' at ' . a:line ) &&
|
||||||
|
\ assert_equal( a:sign_name,
|
||||||
|
\ signs[ 0 ].signs[ 0 ].name,
|
||||||
|
\ 'Sign in group ' . a:group . ' at ' . a:line )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! vimspector#test#signs#AssertSignGroupEmptyAtLine( group, line ) abort
|
||||||
|
let signs = sign_getplaced( '%', {
|
||||||
|
\ 'group': a:group,
|
||||||
|
\ 'lnum': line( '.' )
|
||||||
|
\ } )
|
||||||
|
|
||||||
|
return assert_equal( 1,
|
||||||
|
\ len( signs ),
|
||||||
|
\ 'Num buffers named %' ) &&
|
||||||
|
\ assert_equal( 0,
|
||||||
|
\ len( signs[ 0 ].signs ),
|
||||||
|
\ 'Num signs in ' . a:group . ' at ' . a:line )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! vimspector#test#signs#AssertSignGroupEmpty( group ) abort
|
||||||
|
let signs = sign_getplaced( '%', {
|
||||||
|
\ 'group': a:group,
|
||||||
|
\ } )
|
||||||
|
return assert_equal( 1,
|
||||||
|
\ len( signs ),
|
||||||
|
\ 'Num buffers named %' ) &&
|
||||||
|
\ assert_equal( 0,
|
||||||
|
\ len( signs[ 0 ].signs ),
|
||||||
|
\ 'Num signs in ' . a:group )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -134,8 +134,9 @@ func WaitFor(expr, ...)
|
||||||
return slept
|
return slept
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Wait for up to five seconds for "assert" to return zero. "assert" must be a
|
" Wait for up to five seconds for "assert" to return without adding to v:errors.
|
||||||
" (lambda) function containing one assert function. Example:
|
" "assert" must be a (lambda) function containing one assert function.
|
||||||
|
" Example:
|
||||||
" call WaitForAssert({-> assert_equal("dead", job_status(job)})
|
" call WaitForAssert({-> assert_equal("dead", job_status(job)})
|
||||||
"
|
"
|
||||||
" A second argument can be used to specify a different timeout in msec.
|
" A second argument can be used to specify a different timeout in msec.
|
||||||
|
|
@ -160,13 +161,15 @@ func s:WaitForCommon(expr, assert, timeout)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
while 1
|
while 1
|
||||||
|
let errors_before = len( v:errors )
|
||||||
if type(a:expr) == v:t_func
|
if type(a:expr) == v:t_func
|
||||||
let success = a:expr()
|
let success = a:expr()
|
||||||
elseif type(a:assert) == v:t_func
|
elseif type(a:assert) == v:t_func
|
||||||
let success = a:assert() == 0
|
let success = a:assert() == 0 && len( v:errors ) == errors_before
|
||||||
else
|
else
|
||||||
let success = eval(a:expr)
|
let success = eval(a:expr)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if success
|
if success
|
||||||
return slept
|
return slept
|
||||||
endif
|
endif
|
||||||
|
|
@ -174,9 +177,10 @@ func s:WaitForCommon(expr, assert, timeout)
|
||||||
if slept >= a:timeout
|
if slept >= a:timeout
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if type(a:assert) == v:t_func
|
if type(a:assert) == v:t_func
|
||||||
" Remove the error added by the assert function.
|
" Remove the errors added by the assert function.
|
||||||
call remove(v:errors, -1)
|
call remove(v:errors, -1 * len( v:errors ) - errors_before )
|
||||||
endif
|
endif
|
||||||
|
|
||||||
sleep 10m
|
sleep 10m
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue