neovim/src/nvim/testdir/runtest.vim

184 lines
4.8 KiB
VimL
Raw Normal View History

" This script is sourced while editing the .vim file with the tests.
" When the script is successful the .res file will be created.
" Errors are appended to the test.log file.
"
" To execute only specific test functions, add a second argument. It will be
" matched against the names of the Test_ function. E.g.:
" ../vim -u NONE -S runtest.vim test_channel.vim open_delay
" The output can be found in the "messages" file.
"
" The test script may contain anything, only functions that start with
" "Test_" are special. These will be invoked and should contain assert
" functions. See test_assert.vim for an example.
"
" It is possible to source other files that contain "Test_" functions. This
" can speed up testing, since Vim does not need to restart. But be careful
" that the tests do not interfere with each other.
"
" If an error cannot be detected properly with an assert function add the
" error to the v:errors list:
" call add(v:errors, 'test foo failed: Cannot find xyz')
"
" If preparation for each Test_ function is needed, define a SetUp function.
" It will be called before each Test_ function.
"
" If cleanup after each Test_ function is needed, define a TearDown function.
" It will be called after each Test_ function.
"
" When debugging a test it can be useful to add messages to v:errors:
" call add(v:errors, "this happened")
" Check that the screen size is at least 24 x 80 characters.
if &lines < 24 || &columns < 80
let error = 'Screen size too small! Tests require at least 24 lines with 80 characters'
echoerr error
split test.log
$put =error
w
cquit
endif
" This also enables use of line continuation.
set viminfo+=nviminfo
" Use utf-8 or latin1 be default, instead of whatever the system default
" happens to be. Individual tests can overrule this at the top of the file.
if has('multi_byte')
set encoding=utf-8
else
set encoding=latin1
endif
" Avoid stopping at the "hit enter" prompt
set nomore
" Output all messages in English.
lang mess C
" Always use forward slashes.
set shellslash
" Make sure $HOME does not get read or written.
let $HOME = '/does/not/exist'
2016-12-06 12:56:42 -07:00
" Align with vim defaults.
set directory^=.
set nohidden
function RunTheTest(test)
echo 'Executing ' . a:test
if exists("*SetUp")
call SetUp()
endif
call add(s:messages, 'Executing ' . a:test)
let s:done += 1
try
exe 'call ' . a:test
vim-patch:0 completion-related patches #5745 #5829 vim-patch:8.0.0058 Problem: Positioning of the popup menu is not good. Solution: Position it better. (Hirohito Higashi) https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8 vim-patch:8.0.0099 Problem: Popup menu always appears above the cursor when it is in the lower half of the screen. (Matt Gardner) Solution: Compute the available space better. (Hirohito Higashi, closes vim/vim#1241) https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806 vim-patch:8.0.0127 Problem: Cancelling completion still inserts text when formatting is done for 'textwidth'. (lacygoill) Solution: Don't format when CTRL-E was typed. (Hirohito Higashi, closes vim/vim#1312) https://github.com/vim/vim/commit/73fd4988866c3adc15b5d093efdf5e8cf70d093d vim-patch:7.4.2188 Problem: Completion does not work properly with some plugins. Solution: Revert the part related to typing CTRL-E. (closes vim/vim#972) https://github.com/vim/vim/commit/c9fb77c69244870a97384152f20845665c19fe39 vim-patch:7.4.2146 Problem: Not enough testing for popup menu. CTRL-E does not always work properly. Solution: Add more tests. When using CTRL-E check if the popup menu is visible. (Christian Brabandt) https://github.com/vim/vim/commit/472472898ab71ac80a86fedc37f8eb91461788dd vim-patch:7.4.2147 Problem: test_alot fails. Solution: Close window. https://github.com/vim/vim/commit/abb71fbd399772d467aaa7b34b958b0f975c7e65 vim-patch:7.4.2149 Problem: If a test leaves a window open a following test may fail. Solution: Always close extra windows after running a test. https://github.com/vim/vim/commit/7cba71d7e3576639679b6a3aedeeb1ac07f7f2f5 vim-patch:7.4.2321 Problem: When a test is commented out we forget about it. Solution: Let a test throw an exception with "Skipped" and list skipped test functions. (Christian Brabandt) https://github.com/vim/vim/commit/dac1947bb366ef43cd6da95acc730554e76d8b84 vim-patch:7.4.2331 Problem: Using CTRL-X CTRL-V to complete a command line from Insert mode does not work after entering an expression on the command line. Solution: Don't use "ccline" when not actually using a command line. (test by Hirohito Higashi) https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249 vim-patch:8.0.0008 Problem: Popup complete test is disabled. Solution: Enable the test and change the assert. (Hirohito Higashi) https://github.com/vim/vim/commit/9e02cfa226b2577ec867b544a1a450a428a19880 vim-patch:8.0.0047 Problem: Crash when using the preview window from an unnamed buffer. (lifepillar) Solution: Do not clear the wrong buffer. (closes vim/vim#1200) https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0 vim-patch:8.0.0053 Problem: No test for what 8.0.0047 fixes. Solution: Add a test. (Hirohito Higashi) https://github.com/vim/vim/commit/60ef3e81f4a54d9f7ee617d57021f0811ec8ada5
2016-12-10 01:02:02 -07:00
catch /^\cskipped/
call add(s:messages, ' Skipped')
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
catch
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
endtry
if exists("*TearDown")
call TearDown()
endif
endfunc
" Source the test script. First grab the file name, in case the script
" navigates away. g:testname can be used by the tests.
let g:testname = expand('%')
let s:done = 0
let s:fail = 0
let s:errors = []
let s:messages = []
vim-patch:0 completion-related patches #5745 #5829 vim-patch:8.0.0058 Problem: Positioning of the popup menu is not good. Solution: Position it better. (Hirohito Higashi) https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8 vim-patch:8.0.0099 Problem: Popup menu always appears above the cursor when it is in the lower half of the screen. (Matt Gardner) Solution: Compute the available space better. (Hirohito Higashi, closes vim/vim#1241) https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806 vim-patch:8.0.0127 Problem: Cancelling completion still inserts text when formatting is done for 'textwidth'. (lacygoill) Solution: Don't format when CTRL-E was typed. (Hirohito Higashi, closes vim/vim#1312) https://github.com/vim/vim/commit/73fd4988866c3adc15b5d093efdf5e8cf70d093d vim-patch:7.4.2188 Problem: Completion does not work properly with some plugins. Solution: Revert the part related to typing CTRL-E. (closes vim/vim#972) https://github.com/vim/vim/commit/c9fb77c69244870a97384152f20845665c19fe39 vim-patch:7.4.2146 Problem: Not enough testing for popup menu. CTRL-E does not always work properly. Solution: Add more tests. When using CTRL-E check if the popup menu is visible. (Christian Brabandt) https://github.com/vim/vim/commit/472472898ab71ac80a86fedc37f8eb91461788dd vim-patch:7.4.2147 Problem: test_alot fails. Solution: Close window. https://github.com/vim/vim/commit/abb71fbd399772d467aaa7b34b958b0f975c7e65 vim-patch:7.4.2149 Problem: If a test leaves a window open a following test may fail. Solution: Always close extra windows after running a test. https://github.com/vim/vim/commit/7cba71d7e3576639679b6a3aedeeb1ac07f7f2f5 vim-patch:7.4.2321 Problem: When a test is commented out we forget about it. Solution: Let a test throw an exception with "Skipped" and list skipped test functions. (Christian Brabandt) https://github.com/vim/vim/commit/dac1947bb366ef43cd6da95acc730554e76d8b84 vim-patch:7.4.2331 Problem: Using CTRL-X CTRL-V to complete a command line from Insert mode does not work after entering an expression on the command line. Solution: Don't use "ccline" when not actually using a command line. (test by Hirohito Higashi) https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249 vim-patch:8.0.0008 Problem: Popup complete test is disabled. Solution: Enable the test and change the assert. (Hirohito Higashi) https://github.com/vim/vim/commit/9e02cfa226b2577ec867b544a1a450a428a19880 vim-patch:8.0.0047 Problem: Crash when using the preview window from an unnamed buffer. (lifepillar) Solution: Do not clear the wrong buffer. (closes vim/vim#1200) https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0 vim-patch:8.0.0053 Problem: No test for what 8.0.0047 fixes. Solution: Add a test. (Hirohito Higashi) https://github.com/vim/vim/commit/60ef3e81f4a54d9f7ee617d57021f0811ec8ada5
2016-12-10 01:02:02 -07:00
let s:skipped = []
if expand('%') =~ 'test_viml.vim'
" this test has intentional s:errors, don't use try/catch.
source %
else
try
source %
catch
let s:fail += 1
call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint)
endtry
endif
" Names of flaky tests.
let s:flaky = []
" Locate Test_ functions and execute them.
set nomore
redir @q
silent function /^Test_
redir END
let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
" If there is an extra argument filter the function names against it.
if argc() > 1
let s:tests = filter(s:tests, 'v:val =~ argv(1)')
endif
" Execute the tests in alphabetical order.
for s:test in sort(s:tests)
call RunTheTest(s:test)
2016-09-23 11:39:10 -07:00
if len(v:errors) > 0 && index(s:flaky, s:test) >= 0
call add(s:messages, 'Flaky test failed, running it again')
let v:errors = []
call RunTheTest(s:test)
endif
if len(v:errors) > 0
let s:fail += 1
call add(s:errors, 'Found errors in ' . s:test . ':')
call extend(s:errors, v:errors)
let v:errors = []
endif
endfor
" Don't write viminfo on exit.
set viminfo=
if s:fail == 0
" Success, create the .res file so that make knows it's done.
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
write
endif
if len(s:errors) > 0
" Append errors to test.log
split test.log
call append(line('$'), '')
call append(line('$'), 'From ' . g:testname . ':')
call append(line('$'), s:errors)
write
endif
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests': ' test')
echo message
call add(s:messages, message)
if s:fail > 0
let message = s:fail . ' FAILED'
echo message
call add(s:messages, message)
call extend(s:messages, s:errors)
endif
vim-patch:0 completion-related patches #5745 #5829 vim-patch:8.0.0058 Problem: Positioning of the popup menu is not good. Solution: Position it better. (Hirohito Higashi) https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8 vim-patch:8.0.0099 Problem: Popup menu always appears above the cursor when it is in the lower half of the screen. (Matt Gardner) Solution: Compute the available space better. (Hirohito Higashi, closes vim/vim#1241) https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806 vim-patch:8.0.0127 Problem: Cancelling completion still inserts text when formatting is done for 'textwidth'. (lacygoill) Solution: Don't format when CTRL-E was typed. (Hirohito Higashi, closes vim/vim#1312) https://github.com/vim/vim/commit/73fd4988866c3adc15b5d093efdf5e8cf70d093d vim-patch:7.4.2188 Problem: Completion does not work properly with some plugins. Solution: Revert the part related to typing CTRL-E. (closes vim/vim#972) https://github.com/vim/vim/commit/c9fb77c69244870a97384152f20845665c19fe39 vim-patch:7.4.2146 Problem: Not enough testing for popup menu. CTRL-E does not always work properly. Solution: Add more tests. When using CTRL-E check if the popup menu is visible. (Christian Brabandt) https://github.com/vim/vim/commit/472472898ab71ac80a86fedc37f8eb91461788dd vim-patch:7.4.2147 Problem: test_alot fails. Solution: Close window. https://github.com/vim/vim/commit/abb71fbd399772d467aaa7b34b958b0f975c7e65 vim-patch:7.4.2149 Problem: If a test leaves a window open a following test may fail. Solution: Always close extra windows after running a test. https://github.com/vim/vim/commit/7cba71d7e3576639679b6a3aedeeb1ac07f7f2f5 vim-patch:7.4.2321 Problem: When a test is commented out we forget about it. Solution: Let a test throw an exception with "Skipped" and list skipped test functions. (Christian Brabandt) https://github.com/vim/vim/commit/dac1947bb366ef43cd6da95acc730554e76d8b84 vim-patch:7.4.2331 Problem: Using CTRL-X CTRL-V to complete a command line from Insert mode does not work after entering an expression on the command line. Solution: Don't use "ccline" when not actually using a command line. (test by Hirohito Higashi) https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249 vim-patch:8.0.0008 Problem: Popup complete test is disabled. Solution: Enable the test and change the assert. (Hirohito Higashi) https://github.com/vim/vim/commit/9e02cfa226b2577ec867b544a1a450a428a19880 vim-patch:8.0.0047 Problem: Crash when using the preview window from an unnamed buffer. (lifepillar) Solution: Do not clear the wrong buffer. (closes vim/vim#1200) https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0 vim-patch:8.0.0053 Problem: No test for what 8.0.0047 fixes. Solution: Add a test. (Hirohito Higashi) https://github.com/vim/vim/commit/60ef3e81f4a54d9f7ee617d57021f0811ec8ada5
2016-12-10 01:02:02 -07:00
" Add SKIPPED messages
call extend(s:messages, s:skipped)
" Append messages to the file "messages"
split messages
call append(line('$'), '')
call append(line('$'), 'From ' . g:testname . ':')
call append(line('$'), s:messages)
write
qall!