Fix some asserts

This commit is contained in:
Ben Jackson 2019-07-21 22:15:00 +01:00
commit e6904acddd
4 changed files with 202 additions and 107 deletions

View file

@ -21,13 +21,12 @@ endfunction
function! vimspector#test#setup#Reset() abort
call vimspector#Reset()
call AssertSignGroupEmpty( 'VimspectorCode' )
call vimspector#ClearBreakpoints()
call AssertSignGroupEmpty( 'VimspectorBP' )
call WaitForAssert( {->
\ assert_true( pyxeval( '_vimspector_session._connection is None' ) )
\ } )
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorCode' )
call vimspector#ClearBreakpoints()
call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorBP' )
endfunction

View 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

View file

@ -134,8 +134,9 @@ func WaitFor(expr, ...)
return slept
endfunc
" Wait for up to five seconds for "assert" to return zero. "assert" must be a
" (lambda) function containing one assert function. Example:
" Wait for up to five seconds for "assert" to return without adding to v:errors.
" "assert" must be a (lambda) function containing one assert function.
" Example:
" call WaitForAssert({-> assert_equal("dead", job_status(job)})
"
" A second argument can be used to specify a different timeout in msec.
@ -160,13 +161,15 @@ func s:WaitForCommon(expr, assert, timeout)
endif
while 1
let errors_before = len( v:errors )
if type(a:expr) == v:t_func
let success = a:expr()
elseif type(a:assert) == v:t_func
let success = a:assert() == 0
let success = a:assert() == 0 && len( v:errors ) == errors_before
else
let success = eval(a:expr)
endif
if success
return slept
endif
@ -174,9 +177,10 @@ func s:WaitForCommon(expr, assert, timeout)
if slept >= a:timeout
break
endif
if type(a:assert) == v:t_func
" Remove the error added by the assert function.
call remove(v:errors, -1)
" Remove the errors added by the assert function.
call remove(v:errors, -1 * len( v:errors ) - errors_before )
endif
sleep 10m