diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-19 12:06:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 12:06:45 +0800 |
commit | c218109744e5aec702b10d4a8bf233b758dacc79 (patch) | |
tree | 91b3cff369f70f248bb06a15b6d32db77006391b /test | |
parent | dd8781128f4b93d402bab281d11b85f2c45b987e (diff) | |
parent | 1c12f844ad6db504e1435b5e4b633eb87b932180 (diff) | |
download | rneovim-c218109744e5aec702b10d4a8bf233b758dacc79.tar.gz rneovim-c218109744e5aec702b10d4a8bf233b758dacc79.tar.bz2 rneovim-c218109744e5aec702b10d4a8bf233b758dacc79.zip |
Merge pull request #23191 from zeertzjq/vim-9.0.1007
vim-patch:9.0.{0369,0372,0426,0514,0545,0560,0561,1005,1007,1008,1009,1010,1012,1020,1021,1034}
Diffstat (limited to 'test')
-rw-r--r-- | test/old/testdir/Makefile | 11 | ||||
-rw-r--r-- | test/old/testdir/runtest.vim | 121 | ||||
-rw-r--r-- | test/old/testdir/shared.vim | 6 | ||||
-rw-r--r-- | test/old/testdir/test_autocmd.vim | 2 | ||||
-rw-r--r-- | test/old/testdir/test_swap.vim | 13 | ||||
-rw-r--r-- | test/old/testdir/test_syntax.vim | 2 | ||||
-rw-r--r-- | test/old/testdir/test_vimscript.vim | 6 | ||||
-rw-r--r-- | test/old/testdir/test_window_cmd.vim | 10 |
8 files changed, 146 insertions, 25 deletions
diff --git a/test/old/testdir/Makefile b/test/old/testdir/Makefile index 9511b311e6..b5ca6a17b0 100644 --- a/test/old/testdir/Makefile +++ b/test/old/testdir/Makefile @@ -70,6 +70,7 @@ report: then echo TEST FAILURE; exit 1; \ else echo ALL DONE; \ fi" + @rm -f starttime test1.out: $(NVIM_PRG) @@ -86,10 +87,13 @@ fixff: -$(NVIM_PRG) $(NO_INITS) -u unix.vim "+argdo set ff=dos|upd" +q \ dotest.in +# File to delete when testing starts +CLEANUP_FILES = test.log messages starttime + # Execute an individual new style test, e.g.: # make test_largefile $(NEW_TESTS): - rm -f $@.res test.log messages + rm -f $@.res $(CLEANUP_FILES) @MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile $@.res @cat messages @if test -f test.log; then \ @@ -108,9 +112,8 @@ CLEAN_FILES := *.out \ *.rej \ *.orig \ *.tlog \ - test.log \ test_result.log \ - messages \ + $(CLEANUP_FILES) \ $(RM_ON_RUN) \ $(RM_ON_START) \ valgrind.* \ @@ -132,7 +135,7 @@ test1.out: .gdbinit test1.in nolog: @echo "[OLDTEST-PREP] Removing test.log and messages" - @rm -f test.log messages + @rm -f test_result.log $(CLEANUP_FILES) # New style of tests uses Vim script with assert calls. These are easier diff --git a/test/old/testdir/runtest.vim b/test/old/testdir/runtest.vim index 3c5699af73..5ee9c9fa71 100644 --- a/test/old/testdir/runtest.vim +++ b/test/old/testdir/runtest.vim @@ -61,7 +61,16 @@ if &lines < 24 || &columns < 80 endif if has('reltime') - let s:start_time = reltime() + 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 endif " Always use forward slashes. @@ -121,6 +130,7 @@ if has('mac') let $BASH_SILENCE_DEPRECATION_WARNING = 1 endif + " Prepare for calling test_garbagecollect_now(). let v:testing = 1 @@ -139,10 +149,57 @@ func GetAllocId(name) return lnum - top - 1 endfunc +if has('reltime') + let g:func_start = reltime() +endif + +" 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 + +" 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 +unlet name + + +" 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 + func RunTheTest(test) - echo 'Executing ' . a:test + let prefix = '' if has('reltime') - let func_start = reltime() + let prefix = strftime('%M:%S', localtime() - s:test_start_time) .. ' ' + let g:func_start = reltime() + endif + echo prefix .. 'Executing ' .. a:test + + 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 " Avoid stopping at the "hit enter" prompt @@ -193,6 +250,11 @@ func RunTheTest(test) endif au! VimLeavePre + if a:test =~ '_terminal_' + " Terminal tests sometimes hang, give extra information + echoconsole 'After executing ' .. a:test + endif + " In case 'insertmode' was set and something went wrong, make sure it is " reset to avoid trouble with anything else. set noinsertmode @@ -205,6 +267,10 @@ func RunTheTest(test) endtry endif + if has('timers') + call timer_stop(test_timeout_timer) + endif + " Clear any autocommands and put back the catch-all for SwapExists. au! au SwapExists * call HandleSwapExists() @@ -234,20 +300,54 @@ func RunTheTest(test) exe 'cd ' . save_cwd + if a:test =~ '_terminal_' + " Terminal tests sometimes hang, give extra information + echoconsole 'Finished ' . a:test + endif + let message = 'Executed ' . a:test if has('reltime') let message ..= repeat(' ', 50 - len(message)) - let time = reltime(func_start) - if has('float') && reltimefloat(time) > 0.1 + let time = reltime(g:func_start) + if reltimefloat(time) > 0.1 let message = s:t_bold .. message endif let message ..= ' in ' .. reltimestr(time) .. ' seconds' - if has('float') && reltimefloat(time) > 0.1 + if reltimefloat(time) > 0.1 let message ..= s:t_normal endif endif call add(s:messages, message) let s:done += 1 + + " close any split windows + while winnr('$') > 1 + bwipe! + endwhile + + " 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' + let bn = bufnr() + + noswapfile bwipe! + + if bn == bufnr() + " avoid getting stuck in the same buffer + break + endif + endwhile + + " 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 endfunc func AfterTheTest(func_name) @@ -314,7 +414,7 @@ func FinishTesting() endif if s:done > 0 && has('reltime') let message = s:t_bold .. message .. repeat(' ', 40 - len(message)) - let message ..= ' in ' .. reltimestr(reltime(s:start_time)) .. ' seconds' + let message ..= ' in ' .. reltimestr(reltime(s:run_start_time)) .. ' seconds' let message ..= s:t_normal endif echo message @@ -434,6 +534,7 @@ for g:testfunc in sort(s:tests) " A test can set g:test_is_flaky to retry running the test. let g:test_is_flaky = 0 + let starttime = strftime("%H:%M:%S") call RunTheTest(g:testfunc) " Repeat a flaky test. Give up when: @@ -445,10 +546,11 @@ for g:testfunc in sort(s:tests) \ && (index(s:flaky_tests, g:testfunc) >= 0 \ || g:test_is_flaky) while 1 - call add(s:messages, 'Found errors in ' . g:testfunc . ':') + call add(s:messages, 'Found errors in ' .. g:testfunc .. ':') call extend(s:messages, v:errors) - call add(total_errors, 'Run ' . g:run_nr . ':') + let endtime = strftime("%H:%M:%S") + call add(total_errors, $'Run {g:run_nr}, {starttime} - {endtime}:') call extend(total_errors, v:errors) if g:run_nr >= 5 || prev_error == v:errors[0] @@ -468,6 +570,7 @@ for g:testfunc in sort(s:tests) let v:errors = [] let g:run_nr += 1 + let starttime = strftime("%H:%M:%S") call RunTheTest(g:testfunc) if len(v:errors) == 0 diff --git a/test/old/testdir/shared.vim b/test/old/testdir/shared.vim index 33f6d9a2d0..35ff434d40 100644 --- a/test/old/testdir/shared.vim +++ b/test/old/testdir/shared.vim @@ -110,16 +110,16 @@ func RunServer(cmd, testfunc, args) try let g:currentJob = RunCommand(pycmd) - " Wait for up to 2 seconds for the port number to be there. + " Wait for some time for the port number to be there. let port = GetPort() if port == 0 - call assert_false(1, "Can't start " . a:cmd) + call assert_report(strftime("%H:%M:%S") .. " Can't start " .. a:cmd) return endif call call(function(a:testfunc), [port]) catch - call assert_false(1, 'Caught exception: "' . v:exception . '" in ' . v:throwpoint) + call assert_report('Caught exception: "' . v:exception . '" in ' . v:throwpoint) finally call s:kill_server(a:cmd) endtry diff --git a/test/old/testdir/test_autocmd.vim b/test/old/testdir/test_autocmd.vim index f91792e36e..decfec4763 100644 --- a/test/old/testdir/test_autocmd.vim +++ b/test/old/testdir/test_autocmd.vim @@ -3156,7 +3156,7 @@ func Test_autocmd_FileReadCmd() \ 'v:cmdarg = ++ff=mac', \ 'v:cmdarg = ++enc=utf-8'], getline(1, '$')) - close! + bwipe! augroup FileReadCmdTest au! augroup END diff --git a/test/old/testdir/test_swap.vim b/test/old/testdir/test_swap.vim index 4241f4fd69..fac1893e4c 100644 --- a/test/old/testdir/test_swap.vim +++ b/test/old/testdir/test_swap.vim @@ -115,8 +115,19 @@ func Test_swapinfo() w let fname = s:swapname() call assert_match('Xswapinfo', fname) - let info = fname->swapinfo() + " Check the tail appears in the list from swapfilelist(). The path depends + " on the system. + let tail = fnamemodify(fname, ":t")->fnameescape() + let nr = 0 + for name in swapfilelist() + if name =~ tail .. '$' + let nr += 1 + endif + endfor + call assert_equal(1, nr, 'not found in ' .. string(swapfilelist())) + + let info = fname->swapinfo() let ver = printf('VIM %d.%d', v:version / 100, v:version % 100) call assert_equal(ver, info.version) diff --git a/test/old/testdir/test_syntax.vim b/test/old/testdir/test_syntax.vim index 886c23efa7..c9ad4bb857 100644 --- a/test/old/testdir/test_syntax.vim +++ b/test/old/testdir/test_syntax.vim @@ -460,7 +460,7 @@ func Test_invalid_name() endfunc func Test_ownsyntax() - new Xfoo + new XfooOwnSyntax call setline(1, '#define FOO') syntax on set filetype=c diff --git a/test/old/testdir/test_vimscript.vim b/test/old/testdir/test_vimscript.vim index 81ccee9f13..055a2bd2f2 100644 --- a/test/old/testdir/test_vimscript.vim +++ b/test/old/testdir/test_vimscript.vim @@ -5983,6 +5983,9 @@ endfunc " interrupt right before a catch is invoked in a script func Test_ignore_catch_after_intr_1() + " for unknown reasons this test sometimes fails on MS-Windows. + let g:test_is_flaky = 1 + XpathINIT let lines =<< trim [CODE] try @@ -6021,6 +6024,9 @@ endfunc " interrupt right before a catch is invoked inside a function. func Test_ignore_catch_after_intr_2() + " for unknown reasons this test sometimes fails on MS-Windows. + let g:test_is_flaky = 1 + XpathINIT func F() try diff --git a/test/old/testdir/test_window_cmd.vim b/test/old/testdir/test_window_cmd.vim index 34614832a9..88135199fe 100644 --- a/test/old/testdir/test_window_cmd.vim +++ b/test/old/testdir/test_window_cmd.vim @@ -119,10 +119,9 @@ endfunc " Test the ":wincmd ^" and "<C-W>^" commands. func Test_window_split_edit_alternate() - " Test for failure when the alternate buffer/file no longer exists. edit Xfoo | %bw - call assert_fails(':wincmd ^', 'E23') + call assert_fails(':wincmd ^', 'E23:') " Test for the expected behavior when we have two named buffers. edit Xfoo | edit Xbar @@ -152,12 +151,11 @@ endfunc " Test the ":[count]wincmd ^" and "[count]<C-W>^" commands. func Test_window_split_edit_bufnr() - %bwipeout let l:nr = bufnr('%') + 1 - call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92') - call assert_fails(':' . l:nr . 'wincmd ^', 'E16') - call assert_fails(':0wincmd ^', 'E16') + call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92:') + call assert_fails(':' . l:nr . 'wincmd ^', 'E16:') + call assert_fails(':0wincmd ^', 'E16:') edit Xfoo | edit Xbar | edit Xbaz let l:foo_nr = bufnr('Xfoo') |