2015-12-12 20:19:54 -07:00
|
|
|
" 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.
|
|
|
|
"
|
2016-07-19 22:40:04 -07:00
|
|
|
" To execute only specific test functions, add a second argument. It will be
|
|
|
|
" matched against the names of the Test_ function. E.g.:
|
2018-02-03 04:11:07 -07:00
|
|
|
" ../vim -u NONE -S runtest.vim test_channel.vim open_delay
|
2016-07-19 22:40:04 -07:00
|
|
|
" The output can be found in the "messages" file.
|
|
|
|
"
|
2020-08-23 12:08:03 -07:00
|
|
|
" If the environment variable $TEST_FILTER is set then only test functions
|
|
|
|
" matching this pattern are executed. E.g. for sh/bash:
|
|
|
|
" export TEST_FILTER=Test_channel
|
|
|
|
" For csh:
|
|
|
|
" setenv TEST_FILTER Test_channel
|
|
|
|
"
|
2021-04-07 14:58:04 -07:00
|
|
|
" While working on a test you can make $TEST_NO_RETRY non-empty to not retry:
|
|
|
|
" export TEST_NO_RETRY=yes
|
|
|
|
"
|
2020-08-23 12:08:03 -07:00
|
|
|
" To ignore failure for tests that are known to fail in a certain environment,
|
|
|
|
" set $TEST_MAY_FAIL to a comma separated list of function names. E.g. for
|
|
|
|
" sh/bash:
|
|
|
|
" export TEST_MAY_FAIL=Test_channel_one,Test_channel_other
|
|
|
|
" The failure report will then not be included in the test.log file and
|
|
|
|
" "make test" will not fail.
|
|
|
|
"
|
2015-12-12 20:19:54 -07:00
|
|
|
" 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.
|
2016-09-21 09:00:50 -07:00
|
|
|
"
|
|
|
|
" When debugging a test it can be useful to add messages to v:errors:
|
2019-01-06 17:52:34 -07:00
|
|
|
" call add(v:errors, "this happened")
|
2016-09-21 09:00:50 -07:00
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
|
|
|
|
" Check that the screen size is at least 24 x 80 characters.
|
|
|
|
if &lines < 24 || &columns < 80
|
2019-08-17 15:29:13 -07:00
|
|
|
let error = 'Screen size too small! Tests require at least 24 lines with 80 characters, got ' .. &lines .. ' lines with ' .. &columns .. ' characters'
|
2015-12-12 20:19:54 -07:00
|
|
|
echoerr error
|
|
|
|
split test.log
|
|
|
|
$put =error
|
2019-06-15 17:24:38 -07:00
|
|
|
write
|
|
|
|
split messages
|
2019-08-17 15:29:13 -07:00
|
|
|
call append(line('$'), '')
|
|
|
|
call append(line('$'), 'From ' . expand('%') . ':')
|
2019-06-15 17:24:38 -07:00
|
|
|
call append(line('$'), error)
|
|
|
|
write
|
|
|
|
qa!
|
2015-12-12 20:19:54 -07:00
|
|
|
endif
|
|
|
|
|
2019-06-17 08:11:41 -07:00
|
|
|
if has('reltime')
|
2023-04-18 19:34:23 -07:00
|
|
|
let s:run_start_time = reltime()
|
|
|
|
|
|
|
|
if !filereadable('starttime')
|
|
|
|
" first test, store the overall test starting time
|
|
|
|
let s:test_start_time = localtime()
|
|
|
|
call writefile([string(s:test_start_time)], 'starttime')
|
|
|
|
else
|
|
|
|
" second or later test, read the overall test starting time
|
|
|
|
let s:test_start_time = readfile('starttime')[0]->str2nr()
|
|
|
|
endif
|
2019-06-17 08:11:41 -07:00
|
|
|
endif
|
|
|
|
|
2021-12-24 20:31:54 -07:00
|
|
|
" Always use forward slashes.
|
|
|
|
set shellslash
|
|
|
|
|
2017-01-16 04:50:43 -07:00
|
|
|
" Common with all tests on all systems.
|
|
|
|
source setup.vim
|
|
|
|
|
2018-02-02 13:44:07 -07:00
|
|
|
" For consistency run all tests with 'nocompatible' set.
|
2016-04-14 12:14:08 -07:00
|
|
|
" This also enables use of line continuation.
|
2018-02-02 13:44:07 -07:00
|
|
|
set nocp viminfo+=nviminfo
|
2016-04-14 12:14:08 -07:00
|
|
|
|
2019-08-19 19:13:55 -07:00
|
|
|
" 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.
|
|
|
|
set encoding=utf-8
|
2016-11-22 13:33:13 -07:00
|
|
|
|
2019-08-13 16:56:59 -07:00
|
|
|
" REDIR_TEST_TO_NULL has a very permissive SwapExists autocommand which is for
|
|
|
|
" the test_name.vim file itself. Replace it here with a more restrictive one,
|
|
|
|
" so we still catch mistakes.
|
|
|
|
let s:test_script_fname = expand('%')
|
|
|
|
au! SwapExists * call HandleSwapExists()
|
|
|
|
func HandleSwapExists()
|
2020-10-17 06:03:50 -07:00
|
|
|
if exists('g:ignoreSwapExists')
|
2023-07-25 05:58:09 -07:00
|
|
|
if type(g:ignoreSwapExists) == v:t_string
|
|
|
|
let v:swapchoice = g:ignoreSwapExists
|
|
|
|
endif
|
2020-10-17 06:03:50 -07:00
|
|
|
return
|
|
|
|
endif
|
2020-08-23 10:35:13 -07:00
|
|
|
" Ignore finding a swap file for the test script (the user might be
|
2019-08-13 16:56:59 -07:00
|
|
|
" editing it and do ":make test_name") and the output file.
|
2020-08-23 10:35:13 -07:00
|
|
|
" Report finding another swap file and chose 'q' to avoid getting stuck.
|
2019-08-13 16:56:59 -07:00
|
|
|
if expand('<afile>') == 'messages' || expand('<afile>') =~ s:test_script_fname
|
|
|
|
let v:swapchoice = 'e'
|
2020-08-23 10:35:13 -07:00
|
|
|
else
|
|
|
|
call assert_report('Unexpected swap file: ' .. v:swapname)
|
|
|
|
let v:swapchoice = 'q'
|
2019-08-13 16:56:59 -07:00
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
2018-02-11 09:42:18 -07:00
|
|
|
" Avoid stopping at the "hit enter" prompt
|
|
|
|
set nomore
|
|
|
|
|
2016-04-14 12:14:08 -07:00
|
|
|
" Output all messages in English.
|
|
|
|
lang mess C
|
|
|
|
|
2019-08-28 13:47:54 -07:00
|
|
|
" Nvim: append runtime from build dir, which contains the generated doc/tags.
|
2022-12-03 05:10:36 -07:00
|
|
|
let &runtimepath ..= ',' .. expand($BUILD_DIR) .. '/runtime/'
|
2019-08-28 13:47:54 -07:00
|
|
|
|
2020-08-28 18:25:34 -07:00
|
|
|
let s:t_bold = &t_md
|
|
|
|
let s:t_normal = &t_me
|
2020-07-22 20:29:02 -07:00
|
|
|
if has('win32')
|
|
|
|
" avoid prompt that is long or contains a line break
|
|
|
|
let $PROMPT = '$P$G'
|
|
|
|
endif
|
|
|
|
|
2022-08-21 18:28:32 -07:00
|
|
|
if has('mac')
|
|
|
|
" In MacOS, when starting a shell in a terminal, a bash deprecation warning
|
|
|
|
" message is displayed. This breaks the terminal test. Disable the warning
|
|
|
|
" message.
|
|
|
|
let $BASH_SILENCE_DEPRECATION_WARNING = 1
|
|
|
|
endif
|
|
|
|
|
2023-04-18 19:06:34 -07:00
|
|
|
|
2018-02-02 13:44:07 -07:00
|
|
|
" Prepare for calling test_garbagecollect_now().
|
2017-01-05 17:13:23 -07:00
|
|
|
let v:testing = 1
|
|
|
|
|
2018-02-02 13:44:07 -07:00
|
|
|
" Support function: get the alloc ID by name.
|
2018-10-15 15:26:01 -07:00
|
|
|
func GetAllocId(name)
|
2018-02-02 13:44:07 -07:00
|
|
|
exe 'split ' . s:srcdir . '/alloc.h'
|
|
|
|
let top = search('typedef enum')
|
|
|
|
if top == 0
|
|
|
|
call add(v:errors, 'typedef not found in alloc.h')
|
|
|
|
endif
|
|
|
|
let lnum = search('aid_' . a:name . ',')
|
|
|
|
if lnum == 0
|
|
|
|
call add(v:errors, 'Alloc ID ' . a:name . ' not defined')
|
|
|
|
endif
|
|
|
|
close
|
|
|
|
return lnum - top - 1
|
|
|
|
endfunc
|
|
|
|
|
2023-04-18 19:34:23 -07:00
|
|
|
if has('reltime')
|
|
|
|
let g:func_start = reltime()
|
|
|
|
endif
|
2023-04-18 19:26:54 -07:00
|
|
|
|
2023-04-18 19:06:34 -07:00
|
|
|
" Get the list of swap files in the current directory.
|
|
|
|
func s:GetSwapFileList()
|
|
|
|
let save_dir = &directory
|
|
|
|
let &directory = '.'
|
|
|
|
let files = swapfilelist()
|
|
|
|
let &directory = save_dir
|
|
|
|
|
|
|
|
" remove a match with runtest.vim
|
|
|
|
let idx = indexof(files, 'v:val =~ "runtest.vim."')
|
|
|
|
if idx >= 0
|
|
|
|
call remove(files, idx)
|
|
|
|
endif
|
|
|
|
|
|
|
|
return files
|
|
|
|
endfunc
|
|
|
|
|
2023-04-18 20:11:20 -07:00
|
|
|
" A previous (failed) test run may have left swap files behind. Delete them
|
|
|
|
" before running tests again, they might interfere.
|
|
|
|
for name in s:GetSwapFileList()
|
|
|
|
call delete(name)
|
|
|
|
endfor
|
2023-10-21 03:14:32 -07:00
|
|
|
unlet! name
|
2023-04-18 20:11:20 -07:00
|
|
|
|
|
|
|
|
2023-04-18 19:53:12 -07:00
|
|
|
" Invoked when a test takes too much time.
|
|
|
|
func TestTimeout(id)
|
|
|
|
split test.log
|
|
|
|
call append(line('$'), '')
|
|
|
|
call append(line('$'), 'Test timed out: ' .. g:testfunc)
|
|
|
|
write
|
|
|
|
call add(v:errors, 'Test timed out: ' . g:testfunc)
|
|
|
|
|
|
|
|
cquit! 42
|
|
|
|
endfunc
|
|
|
|
|
2017-06-05 20:17:54 -07:00
|
|
|
func RunTheTest(test)
|
2023-04-18 19:26:54 -07:00
|
|
|
let prefix = ''
|
2019-06-17 08:11:41 -07:00
|
|
|
if has('reltime')
|
2023-04-18 19:34:23 -07:00
|
|
|
let prefix = strftime('%M:%S', localtime() - s:test_start_time) .. ' '
|
2023-04-18 19:26:54 -07:00
|
|
|
let g:func_start = reltime()
|
2019-06-17 08:11:41 -07:00
|
|
|
endif
|
2023-04-18 19:26:54 -07:00
|
|
|
echo prefix .. 'Executing ' .. a:test
|
2018-02-03 04:11:07 -07:00
|
|
|
|
2023-04-18 19:53:12 -07:00
|
|
|
if has('timers')
|
|
|
|
" No test should take longer than 30 seconds. If it takes longer we
|
|
|
|
" assume we are stuck and need to break out.
|
|
|
|
let test_timeout_timer = timer_start(30000, 'TestTimeout')
|
|
|
|
endif
|
|
|
|
|
2018-02-11 09:39:15 -07:00
|
|
|
" Avoid stopping at the "hit enter" prompt
|
|
|
|
set nomore
|
|
|
|
|
|
|
|
" Avoid a three second wait when a message is about to be overwritten by the
|
|
|
|
" mode message.
|
|
|
|
set noshowmode
|
|
|
|
|
2018-02-03 04:11:07 -07:00
|
|
|
" Some tests wipe out buffers. To be consistent, always wipe out all
|
|
|
|
" buffers.
|
|
|
|
%bwipe!
|
|
|
|
|
2018-02-11 15:04:32 -07:00
|
|
|
" The test may change the current directory. Save and restore the
|
|
|
|
" directory after executing the test.
|
|
|
|
let save_cwd = getcwd()
|
|
|
|
|
2022-07-11 06:10:27 -07:00
|
|
|
" Align Nvim defaults to Vim.
|
|
|
|
source setup.vim
|
|
|
|
|
2016-07-11 02:01:22 -07:00
|
|
|
if exists("*SetUp")
|
2017-07-26 18:56:25 -07:00
|
|
|
try
|
|
|
|
call SetUp()
|
|
|
|
catch
|
|
|
|
call add(v:errors, 'Caught exception in SetUp() before ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
|
|
|
endtry
|
2016-07-11 02:01:22 -07:00
|
|
|
endif
|
|
|
|
|
2023-10-18 03:29:51 -07:00
|
|
|
let skipped = v:false
|
|
|
|
|
2022-11-29 18:48:10 -07:00
|
|
|
au VimLeavePre * call EarlyExit(g:testfunc)
|
2018-02-11 08:51:52 -07:00
|
|
|
if a:test =~ 'Test_nocatch_'
|
|
|
|
" Function handles errors itself. This avoids skipping commands after the
|
|
|
|
" error.
|
2022-11-17 05:21:10 -07:00
|
|
|
let g:skipped_reason = ''
|
2016-09-21 09:00:50 -07:00
|
|
|
exe 'call ' . a:test
|
2022-11-17 05:21:10 -07:00
|
|
|
if g:skipped_reason != ''
|
|
|
|
call add(s:messages, ' Skipped')
|
|
|
|
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . g:skipped_reason)
|
2023-10-18 03:29:51 -07:00
|
|
|
let skipped = v:true
|
2022-11-17 05:21:10 -07:00
|
|
|
endif
|
2018-02-11 08:51:52 -07:00
|
|
|
else
|
|
|
|
try
|
|
|
|
exe 'call ' . a:test
|
|
|
|
catch /^\cskipped/
|
|
|
|
call add(s:messages, ' Skipped')
|
|
|
|
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
|
2023-10-18 03:29:51 -07:00
|
|
|
let skipped = v:true
|
2018-02-11 08:51:52 -07:00
|
|
|
catch
|
|
|
|
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
|
|
|
endtry
|
|
|
|
endif
|
2022-11-29 18:48:10 -07:00
|
|
|
au! VimLeavePre
|
2016-07-11 02:01:22 -07:00
|
|
|
|
2023-04-18 19:52:29 -07:00
|
|
|
if a:test =~ '_terminal_'
|
|
|
|
" Terminal tests sometimes hang, give extra information
|
|
|
|
echoconsole 'After executing ' .. a:test
|
|
|
|
endif
|
|
|
|
|
2019-01-06 17:52:34 -07:00
|
|
|
" In case 'insertmode' was set and something went wrong, make sure it is
|
|
|
|
" reset to avoid trouble with anything else.
|
|
|
|
set noinsertmode
|
|
|
|
|
2016-07-11 02:01:22 -07:00
|
|
|
if exists("*TearDown")
|
2017-07-26 18:56:25 -07:00
|
|
|
try
|
|
|
|
call TearDown()
|
|
|
|
catch
|
|
|
|
call add(v:errors, 'Caught exception in TearDown() after ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
|
|
|
endtry
|
2016-07-11 02:01:22 -07:00
|
|
|
endif
|
2016-12-28 12:54:30 -07:00
|
|
|
|
2023-04-18 19:53:12 -07:00
|
|
|
if has('timers')
|
|
|
|
call timer_stop(test_timeout_timer)
|
|
|
|
endif
|
|
|
|
|
2019-08-17 15:29:13 -07:00
|
|
|
" Clear any autocommands and put back the catch-all for SwapExists.
|
2018-02-03 04:11:07 -07:00
|
|
|
au!
|
2019-08-13 16:56:59 -07:00
|
|
|
au SwapExists * call HandleSwapExists()
|
2018-02-03 04:11:07 -07:00
|
|
|
|
2018-02-03 04:09:37 -07:00
|
|
|
" Close any extra tab pages and windows and make the current one not modified.
|
|
|
|
while tabpagenr('$') > 1
|
2021-11-07 14:46:06 -07:00
|
|
|
let winid = win_getid()
|
2018-02-03 04:11:07 -07:00
|
|
|
quit!
|
2021-11-07 14:46:06 -07:00
|
|
|
if winid == win_getid()
|
|
|
|
echoerr 'Could not quit window'
|
|
|
|
break
|
|
|
|
endif
|
2018-02-03 04:09:37 -07:00
|
|
|
endwhile
|
|
|
|
|
2017-03-14 02:10:45 -07:00
|
|
|
while 1
|
|
|
|
let wincount = winnr('$')
|
|
|
|
if wincount == 1
|
|
|
|
break
|
|
|
|
endif
|
2016-12-28 12:54:30 -07:00
|
|
|
bwipe!
|
2017-03-14 02:10:45 -07:00
|
|
|
if wincount == winnr('$')
|
|
|
|
" Did not manage to close a window.
|
|
|
|
only!
|
|
|
|
break
|
|
|
|
endif
|
2016-12-28 12:54:30 -07:00
|
|
|
endwhile
|
2018-02-11 15:04:32 -07:00
|
|
|
|
|
|
|
exe 'cd ' . save_cwd
|
2020-08-23 10:22:07 -07:00
|
|
|
|
2023-04-18 19:52:29 -07:00
|
|
|
if a:test =~ '_terminal_'
|
|
|
|
" Terminal tests sometimes hang, give extra information
|
|
|
|
echoconsole 'Finished ' . a:test
|
|
|
|
endif
|
|
|
|
|
2020-08-23 10:22:07 -07:00
|
|
|
let message = 'Executed ' . a:test
|
|
|
|
if has('reltime')
|
2020-08-28 17:57:20 -07:00
|
|
|
let message ..= repeat(' ', 50 - len(message))
|
2023-04-18 19:26:54 -07:00
|
|
|
let time = reltime(g:func_start)
|
|
|
|
if reltimefloat(time) > 0.1
|
2020-08-28 18:25:34 -07:00
|
|
|
let message = s:t_bold .. message
|
2020-08-28 17:57:20 -07:00
|
|
|
endif
|
|
|
|
let message ..= ' in ' .. reltimestr(time) .. ' seconds'
|
2023-04-18 19:26:54 -07:00
|
|
|
if reltimefloat(time) > 0.1
|
2020-08-28 18:25:34 -07:00
|
|
|
let message ..= s:t_normal
|
2020-08-28 17:57:20 -07:00
|
|
|
endif
|
2020-08-23 10:22:07 -07:00
|
|
|
endif
|
|
|
|
call add(s:messages, message)
|
|
|
|
let s:done += 1
|
2023-04-18 19:06:34 -07:00
|
|
|
|
2023-04-18 20:12:33 -07:00
|
|
|
" close any split windows
|
|
|
|
while winnr('$') > 1
|
|
|
|
bwipe!
|
|
|
|
endwhile
|
|
|
|
|
2023-04-18 20:08:24 -07:00
|
|
|
" May be editing some buffer, wipe it out. Then we may end up in another
|
|
|
|
" buffer, continue until we end up in an empty no-name buffer without a swap
|
|
|
|
" file.
|
|
|
|
while bufname() != '' || execute('swapname') !~ 'No swap file'
|
2023-04-18 20:09:34 -07:00
|
|
|
let bn = bufnr()
|
|
|
|
|
|
|
|
noswapfile bwipe!
|
|
|
|
|
|
|
|
if bn == bufnr()
|
|
|
|
" avoid getting stuck in the same buffer
|
|
|
|
break
|
|
|
|
endif
|
2023-04-18 20:08:24 -07:00
|
|
|
endwhile
|
|
|
|
|
2023-10-18 03:29:51 -07:00
|
|
|
if !skipped
|
|
|
|
" Check if the test has left any swap files behind. Delete them before
|
|
|
|
" running tests again, they might interfere.
|
|
|
|
let swapfiles = s:GetSwapFileList()
|
|
|
|
if len(swapfiles) > 0
|
|
|
|
call add(s:messages, "Found swap files: " .. string(swapfiles))
|
|
|
|
for name in swapfiles
|
|
|
|
call delete(name)
|
|
|
|
endfor
|
|
|
|
endif
|
2023-04-18 19:06:34 -07:00
|
|
|
endif
|
2016-07-11 02:01:22 -07:00
|
|
|
endfunc
|
|
|
|
|
vim-patch:9.0.1679: Cleanup Tests from leftover files (#24617)
Problem: Tests may leave leftover files around
Solution: Clean up tests and remove files
There were a few failures in 'linux (huge, gcc, testgui, true, true)'
e.g. here: https://github.com/vim/vim/actions/runs/5497376153/jobs/10018060156
,----
| Error detected while processing command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[585]..function RunTheTest[54]..Test_lvimgrep_crash[16]..TestTimeout[12]..VimLeavePre Autocommands for "*"..function EarlyExit[7]..FinishTesting:
| line 70:
| E445: Other window contains changes
| E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txt
| E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txt
| E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txtmalloc(): unsorted double linked list corrupted
`----
Which is puzzling, because the Xtest_stable_xxd file should have been
long gone after test_crypt.vim is run (and definitely no longer be
staying around in test_quickfix.vim).
So try to clean up properly after a test script is run, just in case any
X<file> is still around. During testing, a found a few leftover files,
which I also fixed in the relevant test-file.
Unfortunately, the test workflow 'linux (huge, gcc, testgui, true,
true)' now seems to fail with 'E1230: Encryption: sodium_mlock()' in
test_crypt.vim. Hopefully this is only temporary.
https://github.com/vim/vim/commit/84bc00e9b52b1174888f2f696f8b628a83c49988
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-08-08 15:07:23 -07:00
|
|
|
function Delete_Xtest_Files()
|
|
|
|
for file in glob('X*', v:false, v:true)
|
|
|
|
if file ==? 'XfakeHOME'
|
|
|
|
" Clean up files created by setup.vim
|
|
|
|
call delete('XfakeHOME', 'rf')
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
" call add(v:errors, file .. " exists when it shouldn't, trying to delete it!")
|
|
|
|
call delete(file)
|
|
|
|
if !empty(glob(file, v:false, v:true))
|
|
|
|
" call add(v:errors, file .. " still exists after trying to delete it!")
|
|
|
|
if has('unix')
|
|
|
|
call system('rm -rf ' .. file)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunc
|
|
|
|
|
2020-08-23 12:08:03 -07:00
|
|
|
func AfterTheTest(func_name)
|
2017-06-05 20:17:54 -07:00
|
|
|
if len(v:errors) > 0
|
2020-08-23 12:08:03 -07:00
|
|
|
if match(s:may_fail_list, '^' .. a:func_name) >= 0
|
|
|
|
let s:fail_expected += 1
|
2022-11-29 18:48:10 -07:00
|
|
|
call add(s:errors_expected, 'Found errors in ' . g:testfunc . ':')
|
2020-08-23 12:08:03 -07:00
|
|
|
call extend(s:errors_expected, v:errors)
|
|
|
|
else
|
|
|
|
let s:fail += 1
|
2022-11-29 18:48:10 -07:00
|
|
|
call add(s:errors, 'Found errors in ' . g:testfunc . ':')
|
2020-08-23 12:08:03 -07:00
|
|
|
call extend(s:errors, v:errors)
|
|
|
|
endif
|
2017-06-05 20:17:54 -07:00
|
|
|
let v:errors = []
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
2019-06-15 17:52:27 -07:00
|
|
|
func EarlyExit(test)
|
|
|
|
" It's OK for the test we use to test the quit detection.
|
|
|
|
if a:test != 'Test_zz_quit_detected()'
|
2022-08-19 05:34:46 -07:00
|
|
|
call add(v:errors, v:errmsg)
|
2019-06-15 17:52:27 -07:00
|
|
|
call add(v:errors, 'Test caused Vim to exit: ' . a:test)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call FinishTesting()
|
|
|
|
endfunc
|
|
|
|
|
2017-06-05 20:17:54 -07:00
|
|
|
" This function can be called by a test if it wants to abort testing.
|
|
|
|
func FinishTesting()
|
2020-08-23 12:08:03 -07:00
|
|
|
call AfterTheTest('')
|
vim-patch:9.0.1679: Cleanup Tests from leftover files (#24617)
Problem: Tests may leave leftover files around
Solution: Clean up tests and remove files
There were a few failures in 'linux (huge, gcc, testgui, true, true)'
e.g. here: https://github.com/vim/vim/actions/runs/5497376153/jobs/10018060156
,----
| Error detected while processing command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[585]..function RunTheTest[54]..Test_lvimgrep_crash[16]..TestTimeout[12]..VimLeavePre Autocommands for "*"..function EarlyExit[7]..FinishTesting:
| line 70:
| E445: Other window contains changes
| E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txt
| E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txt
| E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txtmalloc(): unsorted double linked list corrupted
`----
Which is puzzling, because the Xtest_stable_xxd file should have been
long gone after test_crypt.vim is run (and definitely no longer be
staying around in test_quickfix.vim).
So try to clean up properly after a test script is run, just in case any
X<file> is still around. During testing, a found a few leftover files,
which I also fixed in the relevant test-file.
Unfortunately, the test workflow 'linux (huge, gcc, testgui, true,
true)' now seems to fail with 'E1230: Encryption: sodium_mlock()' in
test_crypt.vim. Hopefully this is only temporary.
https://github.com/vim/vim/commit/84bc00e9b52b1174888f2f696f8b628a83c49988
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-08-08 15:07:23 -07:00
|
|
|
call Delete_Xtest_Files()
|
2017-06-05 20:17:54 -07:00
|
|
|
|
|
|
|
" Don't write viminfo on exit.
|
|
|
|
set viminfo=
|
|
|
|
|
2020-08-23 12:08:03 -07:00
|
|
|
if s:fail == 0 && s:fail_expected == 0
|
2017-06-05 20:17:54 -07:00
|
|
|
" 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
|
|
|
|
|
2019-06-11 19:31:12 -07:00
|
|
|
if s:done == 0
|
2020-08-23 11:26:03 -07:00
|
|
|
if s:filtered > 0
|
|
|
|
let message = "NO tests match $TEST_FILTER: '" .. $TEST_FILTER .. "'"
|
|
|
|
else
|
|
|
|
let message = 'NO tests executed'
|
|
|
|
endif
|
2019-06-11 19:31:12 -07:00
|
|
|
else
|
2020-08-23 11:26:03 -07:00
|
|
|
if s:filtered > 0
|
|
|
|
call add(s:messages, "Filtered " .. s:filtered .. " tests with $TEST_FILTER")
|
|
|
|
endif
|
2019-06-11 19:31:12 -07:00
|
|
|
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
|
|
|
|
endif
|
2020-08-23 11:26:03 -07:00
|
|
|
if s:done > 0 && has('reltime')
|
2020-08-28 18:25:34 -07:00
|
|
|
let message = s:t_bold .. message .. repeat(' ', 40 - len(message))
|
2023-04-18 19:34:23 -07:00
|
|
|
let message ..= ' in ' .. reltimestr(reltime(s:run_start_time)) .. ' seconds'
|
2020-08-28 18:25:34 -07:00
|
|
|
let message ..= s:t_normal
|
2019-06-17 08:11:41 -07:00
|
|
|
endif
|
2017-06-05 20:17:54 -07:00
|
|
|
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
|
2020-08-23 12:08:03 -07:00
|
|
|
if s:fail_expected > 0
|
|
|
|
let message = s:fail_expected . ' FAILED (matching $TEST_MAY_FAIL):'
|
|
|
|
echo message
|
|
|
|
call add(s:messages, message)
|
|
|
|
call extend(s:messages, s:errors_expected)
|
|
|
|
endif
|
2017-06-05 20:17:54 -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!
|
|
|
|
endfunc
|
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
" Source the test script. First grab the file name, in case the script
|
2016-09-21 09:00:50 -07:00
|
|
|
" navigates away. g:testname can be used by the tests.
|
|
|
|
let g:testname = expand('%')
|
|
|
|
let s:done = 0
|
|
|
|
let s:fail = 0
|
2020-08-23 12:08:03 -07:00
|
|
|
let s:fail_expected = 0
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:errors = []
|
2020-08-23 12:08:03 -07:00
|
|
|
let s:errors_expected = []
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:messages = []
|
2016-12-10 01:02:02 -07:00
|
|
|
let s:skipped = []
|
2017-06-05 20:05:28 -07:00
|
|
|
if expand('%') =~ 'test_vimscript.vim'
|
2020-08-23 12:08:03 -07:00
|
|
|
" this test has intentional errors, don't use try/catch.
|
2016-01-10 13:31:33 -07:00
|
|
|
source %
|
2016-04-14 12:43:53 -07:00
|
|
|
else
|
|
|
|
try
|
|
|
|
source %
|
2019-08-19 20:04:15 -07:00
|
|
|
catch /^\cskipped/
|
|
|
|
call add(s:messages, ' Skipped')
|
|
|
|
call add(s:skipped, 'SKIPPED ' . expand('%') . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
|
2016-04-14 12:43:53 -07:00
|
|
|
catch
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:fail += 1
|
|
|
|
call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint)
|
2016-04-14 12:43:53 -07:00
|
|
|
endtry
|
|
|
|
endif
|
2015-12-12 20:19:54 -07:00
|
|
|
|
2023-04-19 18:17:33 -07:00
|
|
|
" Delete the .res file, it may change behavior for completion
|
|
|
|
call delete(fnamemodify(g:testname, ':r') .. '.res')
|
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
" Locate Test_ functions and execute them.
|
|
|
|
redir @q
|
2016-06-12 21:05:42 -07:00
|
|
|
silent function /^Test_
|
2015-12-12 20:19:54 -07:00
|
|
|
redir END
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
|
2015-12-12 20:19:54 -07:00
|
|
|
|
2016-07-19 22:40:04 -07:00
|
|
|
" If there is an extra argument filter the function names against it.
|
|
|
|
if argc() > 1
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:tests = filter(s:tests, 'v:val =~ argv(1)')
|
2016-07-19 22:40:04 -07:00
|
|
|
endif
|
|
|
|
|
2019-12-29 20:42:51 -07:00
|
|
|
" If the environment variable $TEST_FILTER is set then filter the function
|
|
|
|
" names against it.
|
2020-08-23 11:26:03 -07:00
|
|
|
let s:filtered = 0
|
2019-12-29 20:42:51 -07:00
|
|
|
if $TEST_FILTER != ''
|
2020-08-23 11:26:03 -07:00
|
|
|
let s:filtered = len(s:tests)
|
2019-12-29 20:42:51 -07:00
|
|
|
let s:tests = filter(s:tests, 'v:val =~ $TEST_FILTER')
|
2020-08-23 11:26:03 -07:00
|
|
|
let s:filtered -= len(s:tests)
|
2019-12-29 20:42:51 -07:00
|
|
|
endif
|
|
|
|
|
2020-08-23 12:08:03 -07:00
|
|
|
let s:may_fail_list = []
|
|
|
|
if $TEST_MAY_FAIL != ''
|
2022-11-29 18:48:10 -07:00
|
|
|
" Split the list at commas and add () to make it match g:testfunc.
|
2020-08-23 12:08:03 -07:00
|
|
|
let s:may_fail_list = split($TEST_MAY_FAIL, ',')->map({i, v -> v .. '()'})
|
|
|
|
endif
|
|
|
|
|
2016-05-24 16:53:50 -07:00
|
|
|
" Execute the tests in alphabetical order.
|
2022-11-29 18:48:10 -07:00
|
|
|
for g:testfunc in sort(s:tests)
|
2018-02-01 17:42:17 -07:00
|
|
|
" Silence, please!
|
|
|
|
set belloff=all
|
2019-06-08 04:49:32 -07:00
|
|
|
let prev_error = ''
|
|
|
|
let total_errors = []
|
2022-08-25 17:25:36 -07:00
|
|
|
let g:run_nr = 1
|
2018-02-01 17:42:17 -07:00
|
|
|
|
2021-03-23 19:28:01 -07:00
|
|
|
" A test can set g:test_is_flaky to retry running the test.
|
|
|
|
let g:test_is_flaky = 0
|
|
|
|
|
2023-04-18 19:24:31 -07:00
|
|
|
let starttime = strftime("%H:%M:%S")
|
2022-11-29 18:48:10 -07:00
|
|
|
call RunTheTest(g:testfunc)
|
2015-12-12 20:19:54 -07:00
|
|
|
|
2019-06-08 04:49:32 -07:00
|
|
|
" Repeat a flaky test. Give up when:
|
2021-04-07 14:58:04 -07:00
|
|
|
" - $TEST_NO_RETRY is not empty
|
2019-06-08 04:49:32 -07:00
|
|
|
" - it fails again with the same message
|
2020-10-20 21:03:36 -07:00
|
|
|
" - it fails five times (with a different message)
|
2019-07-07 18:37:37 -07:00
|
|
|
if len(v:errors) > 0
|
2021-04-07 14:58:04 -07:00
|
|
|
\ && $TEST_NO_RETRY == ''
|
2023-08-21 00:30:20 -07:00
|
|
|
\ && g:test_is_flaky
|
2019-06-08 04:49:32 -07:00
|
|
|
while 1
|
2023-04-18 19:18:47 -07:00
|
|
|
call add(s:messages, 'Found errors in ' .. g:testfunc .. ':')
|
2019-06-08 04:49:32 -07:00
|
|
|
call extend(s:messages, v:errors)
|
2018-02-11 09:08:40 -07:00
|
|
|
|
2023-04-18 19:24:57 -07:00
|
|
|
let endtime = strftime("%H:%M:%S")
|
|
|
|
call add(total_errors, $'Run {g:run_nr}, {starttime} - {endtime}:')
|
2019-06-08 04:49:32 -07:00
|
|
|
call extend(total_errors, v:errors)
|
2018-02-11 09:09:26 -07:00
|
|
|
|
2022-08-25 17:25:36 -07:00
|
|
|
if g:run_nr >= 5 || prev_error == v:errors[0]
|
2019-06-08 04:49:32 -07:00
|
|
|
call add(total_errors, 'Flaky test failed too often, giving up')
|
|
|
|
let v:errors = total_errors
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(s:messages, 'Flaky test failed, running it again')
|
|
|
|
|
|
|
|
" Flakiness is often caused by the system being very busy. Sleep a
|
|
|
|
" couple of seconds to have a higher chance of succeeding the second
|
|
|
|
" time.
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
let prev_error = v:errors[0]
|
|
|
|
let v:errors = []
|
2022-08-25 17:25:36 -07:00
|
|
|
let g:run_nr += 1
|
2019-06-08 04:49:32 -07:00
|
|
|
|
2023-04-18 19:24:31 -07:00
|
|
|
let starttime = strftime("%H:%M:%S")
|
2022-11-29 18:48:10 -07:00
|
|
|
call RunTheTest(g:testfunc)
|
2019-06-08 04:49:32 -07:00
|
|
|
|
|
|
|
if len(v:errors) == 0
|
|
|
|
" Test passed on rerun.
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endwhile
|
2015-12-12 20:19:54 -07:00
|
|
|
endif
|
|
|
|
|
2022-11-29 18:48:10 -07:00
|
|
|
call AfterTheTest(g:testfunc)
|
2015-12-12 20:19:54 -07:00
|
|
|
endfor
|
|
|
|
|
2017-06-05 20:17:54 -07:00
|
|
|
call FinishTesting()
|
2016-01-10 13:38:54 -07:00
|
|
|
|
2017-06-05 20:17:54 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|