More: Import latest YCM test framework changes
This commit is contained in:
parent
d711d655aa
commit
f6eccf1314
1 changed files with 74 additions and 57 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
"
|
"
|
||||||
" To execute only specific test functions, add a second argument. It will be
|
" To execute only specific test functions, add a second argument. It will be
|
||||||
" matched against the names of the Test_ funtion. E.g.:
|
" matched against the names of the Test_ funtion. E.g.:
|
||||||
" ../vim -u NONE -S runtest.vim test_channel.vim open_delay
|
" ../vim -Nu NONE vimrc -S lib/run_test.vim test_channel.vim open_delay
|
||||||
" The output can be found in the "messages" file.
|
" The output can be found in the "messages" file.
|
||||||
"
|
"
|
||||||
" The test script may contain anything, only functions that start with
|
" The test script may contain anything, only functions that start with
|
||||||
|
|
@ -27,7 +27,15 @@
|
||||||
"
|
"
|
||||||
" When debugging a test it can be useful to add messages to v:errors:
|
" When debugging a test it can be useful to add messages to v:errors:
|
||||||
" call add(v:errors, "this happened")
|
" call add(v:errors, "this happened")
|
||||||
|
"
|
||||||
|
" But for real debug logging:
|
||||||
|
" call ch_log( ",,,message..." )
|
||||||
|
" Then view it in 'debuglog'
|
||||||
|
|
||||||
|
" Let a test take up to 1 minute
|
||||||
|
let s:single_test_timeout = 60000
|
||||||
|
|
||||||
|
" Restrict the runtimepath to the exact minimum needed for testing
|
||||||
set rtp=$PWD/lib,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
|
set rtp=$PWD/lib,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
|
||||||
if has('packages')
|
if has('packages')
|
||||||
let &packpath = &rtp
|
let &packpath = &rtp
|
||||||
|
|
@ -37,7 +45,7 @@ call ch_logfile( 'debuglog', 'w' )
|
||||||
|
|
||||||
" For consistency run all tests with 'nocompatible' set.
|
" For consistency run all tests with 'nocompatible' set.
|
||||||
" This also enables use of line continuation.
|
" This also enables use of line continuation.
|
||||||
set nocp viminfo+=nviminfo
|
set nocp
|
||||||
|
|
||||||
" Use utf-8 by default, instead of whatever the system default happens to be.
|
" Use utf-8 by default, instead of whatever the system default happens to be.
|
||||||
" Individual tests can overrule this at the top of the file.
|
" Individual tests can overrule this at the top of the file.
|
||||||
|
|
@ -47,11 +55,23 @@ set encoding=utf-8
|
||||||
set nomore
|
set nomore
|
||||||
|
|
||||||
" Output all messages in English.
|
" Output all messages in English.
|
||||||
lang mess C
|
lang messages C
|
||||||
|
|
||||||
" Always use forward slashes.
|
" Always use forward slashes.
|
||||||
set shellslash
|
set shellslash
|
||||||
|
|
||||||
|
func s:TestFailed()
|
||||||
|
let log = readfile( expand( '~/.vimspector.log' ) )
|
||||||
|
let logfile = s:testid_filesafe . '_vimspector.log.testlog'
|
||||||
|
call writefile( log, logfile, 's' )
|
||||||
|
call add( s:messages, 'Wrote log for failed test: ' . logfile )
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func! Abort( timer_id )
|
||||||
|
call assert_report( 'Test timed out!!!' )
|
||||||
|
qa!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func RunTheTest(test)
|
func RunTheTest(test)
|
||||||
echo 'Executing ' . a:test
|
echo 'Executing ' . a:test
|
||||||
|
|
||||||
|
|
@ -107,20 +127,15 @@ func RunTheTest(test)
|
||||||
|
|
||||||
call add(s:messages, 'Executing ' . a:test)
|
call add(s:messages, 'Executing ' . a:test)
|
||||||
let s:done += 1
|
let s:done += 1
|
||||||
|
let timer = timer_start( s:single_test_timeout, funcref( 'Abort' ) )
|
||||||
|
|
||||||
if a:test =~ 'Test_nocatch_'
|
|
||||||
" Function handles errors itself. This avoids skipping commands after the
|
|
||||||
" error.
|
|
||||||
exe 'call ' . a:test
|
|
||||||
else
|
|
||||||
try
|
try
|
||||||
let s:test = a:test
|
let s:test = a:test
|
||||||
let s:testid = g:testpath . ':' . a:test
|
let s:testid = g:testpath . ':' . a:test
|
||||||
let test_filesafe = substitute( a:test, ')', '_', 'g' )
|
|
||||||
let test_filesafe = substitute( test_filesafe, '(', '_', 'g' )
|
let test_filesafe = substitute( a:test, '[)(,:]', '_', 'g' )
|
||||||
let test_filesafe = substitute( test_filesafe, ',', '_', 'g' )
|
|
||||||
let test_filesafe = substitute( test_filesafe, ':', '_', 'g' )
|
|
||||||
let s:testid_filesafe = g:testpath . '_' . test_filesafe
|
let s:testid_filesafe = g:testpath . '_' . test_filesafe
|
||||||
|
|
||||||
au VimLeavePre * call EarlyExit(s:test)
|
au VimLeavePre * call EarlyExit(s:test)
|
||||||
exe 'call ' . a:test
|
exe 'call ' . a:test
|
||||||
au! VimLeavePre
|
au! VimLeavePre
|
||||||
|
|
@ -139,8 +154,11 @@ func RunTheTest(test)
|
||||||
\ . g:testpath
|
\ . g:testpath
|
||||||
\ . ':'
|
\ . ':'
|
||||||
\ . v:throwpoint)
|
\ . v:throwpoint)
|
||||||
|
|
||||||
|
call s:TestFailed()
|
||||||
endtry
|
endtry
|
||||||
endif
|
|
||||||
|
call timer_stop( timer )
|
||||||
|
|
||||||
" In case 'insertmode' was set and something went wrong, make sure it is
|
" In case 'insertmode' was set and something went wrong, make sure it is
|
||||||
" reset to avoid trouble with anything else.
|
" reset to avoid trouble with anything else.
|
||||||
|
|
@ -203,23 +221,16 @@ endfunc
|
||||||
func AfterTheTest()
|
func AfterTheTest()
|
||||||
if len(v:errors) > 0
|
if len(v:errors) > 0
|
||||||
let s:fail += 1
|
let s:fail += 1
|
||||||
|
call s:TestFailed()
|
||||||
call add(s:errors, 'Found errors in ' . s:testid . ':')
|
call add(s:errors, 'Found errors in ' . s:testid . ':')
|
||||||
call extend(s:errors, v:errors)
|
call extend(s:errors, v:errors)
|
||||||
let v:errors = []
|
let v:errors = []
|
||||||
|
|
||||||
let log = readfile( expand( '~/.vimspector.log' ) )
|
|
||||||
let logfile = s:testid_filesafe . '.vimspector.log'
|
|
||||||
call writefile( log, logfile, 's' )
|
|
||||||
call add( s:messages, 'Wrote log for failed test: ' . logfile )
|
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func EarlyExit(test)
|
func EarlyExit(test)
|
||||||
" It's OK for the test we use to test the quit detection.
|
" It's OK for the test we use to test the quit detection.
|
||||||
if a:test != 'Test_zz_quit_detected()'
|
|
||||||
call add(v:errors, 'Test caused Vim to exit: ' . a:test)
|
call add(v:errors, 'Test caused Vim to exit: ' . a:test)
|
||||||
endif
|
|
||||||
|
|
||||||
call FinishTesting()
|
call FinishTesting()
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|
@ -232,17 +243,19 @@ func FinishTesting()
|
||||||
|
|
||||||
if s:fail == 0
|
if s:fail == 0
|
||||||
" Success, create the .res file so that make knows it's done.
|
" Success, create the .res file so that make knows it's done.
|
||||||
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
|
call writefile( [], g:testname . '.res', 's' )
|
||||||
write
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if len(s:errors) > 0
|
if len(s:errors) > 0
|
||||||
" Append errors to test.log
|
" Append errors to test.log
|
||||||
split test.log
|
let l = []
|
||||||
call append(line('$'), '')
|
if filereadable( 'test.log' )
|
||||||
call append(line('$'), 'From ' . g:testpath . ':')
|
let l = readfile( 'test.log' )
|
||||||
call append(line('$'), s:errors)
|
endif
|
||||||
write
|
call writefile( l->extend( [ '', 'From ' . g:testpath . ':' ] )
|
||||||
|
\ ->extend( s:errors ),
|
||||||
|
\ 'test.log',
|
||||||
|
\ 's' )
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:done == 0
|
if s:done == 0
|
||||||
|
|
@ -263,11 +276,14 @@ func FinishTesting()
|
||||||
call extend(s:messages, s:skipped)
|
call extend(s:messages, s:skipped)
|
||||||
|
|
||||||
" Append messages to the file "messages"
|
" Append messages to the file "messages"
|
||||||
split messages
|
let l = []
|
||||||
call append(line('$'), '')
|
if filereadable( 'messages' )
|
||||||
call append(line('$'), 'From ' . g:testpath . ':')
|
let l = readfile( 'messages' )
|
||||||
call append(line('$'), s:messages)
|
endif
|
||||||
write
|
call writefile( l->extend( [ '', 'From ' . g:testpath . ':' ] )
|
||||||
|
\ ->extend( s:messages ),
|
||||||
|
\ 'messages',
|
||||||
|
\ 's' )
|
||||||
|
|
||||||
if s:fail > 0
|
if s:fail > 0
|
||||||
cquit!
|
cquit!
|
||||||
|
|
@ -316,6 +332,7 @@ endif
|
||||||
for s:test in sort(s:tests)
|
for s:test in sort(s:tests)
|
||||||
" Silence, please!
|
" Silence, please!
|
||||||
set belloff=all
|
set belloff=all
|
||||||
|
|
||||||
call RunTheTest(s:test)
|
call RunTheTest(s:test)
|
||||||
call AfterTheTest()
|
call AfterTheTest()
|
||||||
endfor
|
endfor
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue