Merge pull request #21270 from zeertzjq/vim-8.2.1420

vim-patch:8.2.{1420,1440}: test 49 is old style
This commit is contained in:
zeertzjq 2022-12-03 15:09:46 +08:00 committed by GitHub
commit 8f1ef36875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 593 additions and 1571 deletions

View File

@ -20,17 +20,11 @@ and for testing plugins.
Vim can be tested after building it, usually with "make test".
The tests are located in the directory "src/testdir".
There are several types of tests added over time:
test33.in oldest, don't add any of these
test_something.in old style tests
test_something.vim new style tests
*new-style-testing*
New tests should be added as new style tests. These use functions such as
|assert_equal()| to keep the test commands and the expected result in one
place.
*old-style-testing*
In some cases an old style test needs to be used.
New tests should be added as new style tests. The test scripts are named
test_<feature>.vim (replace <feature> with the feature under test). These use
functions such as |assert_equal()| to keep the test commands and the expected
result in one place.
Find more information in the file src/testdir/README.txt.

View File

@ -0,0 +1 @@
# Tests may depend on the existence of this file.

View File

@ -13,22 +13,12 @@ export SHELL := sh
export NVIM_PRG := $(NVIM_PRG)
export TMPDIR := $(abspath Xtest-tmpdir)
SCRIPTS_DEFAULT =
ifneq ($(OS),Windows_NT)
SCRIPTS_DEFAULTS := $(SCRIPTS_DEFAULT) \
test49.out \
endif
ifeq ($(OS),Windows_NT)
FIXFF = fixff
else
FIXFF =
endif
SCRIPTS ?= $(SCRIPTS_DEFAULT)
# Tests using runtest.vim.
NEW_TESTS_ALOT := test_alot_utf8 test_alot test_alot_latin
NEW_TESTS_IN_ALOT := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' $(addsuffix .vim,$(NEW_TESTS_ALOT)))
@ -65,11 +55,7 @@ else
endif
endif
ifdef TESTNUM
SCRIPTS := test$(TESTNUM).out
endif
nongui: nolog $(FIXFF) $(SCRIPTS) newtests report
nongui: nolog $(FIXFF) newtests report
.gdbinit:
@echo "[OLDTEST-PREP] Setting up .gdbinit"
@ -87,8 +73,6 @@ report:
test1.out: $(NVIM_PRG)
$(SCRIPTS): $(NVIM_PRG) test1.out
NO_PLUGINS = --noplugin --headless
# In vim, if the -u command line option is specified, compatible is turned on
# and viminfo is not read. Unlike vim, neovim reads viminfo and requires the
@ -146,17 +130,6 @@ test1.out: .gdbinit test1.in
@rm -f wrongtermsize
@rm -rf X* viminfo
%.out: %.in .gdbinit
@echo "[OLDESTTEST] Running" $*
@rm -rf $*.failed test.ok $(RM_ON_RUN)
@mkdir -p $(TMPDIR)
@cp $*.ok test.ok
@/bin/sh runnvim.sh --oldesttest $(ROOT) $(NVIM_PRG) $* $(RUN_VIM) $*.in
@rm -rf X* test.ok viminfo
# Explicit dependencies.
test49.out: test49.vim
nolog:
@echo "[OLDTEST-PREP] Removing test.log and messages"
@rm -f test.log messages

View File

@ -1,31 +0,0 @@
This is a test of the script language.
If after adding a new test, the test output doesn't appear properly in
test49.failed, try to add one or more "G"s at the line ending in "test.out"
STARTTEST
:se nomore
:lang mess C
:so test49.vim
:" Go back to this file and append the results from register r.
:buf test49.in
G"rp:/^Results/,$w! test.out
:"
:" make valgrind happy
:redir => funclist
:silent func
:redir END
:for line in split(funclist, "\n")
: let name = matchstr(line, 'function \zs[A-Z]\w*\ze(')
: if name != ''
: exe "delfunc " . name
: endif
:endfor
:for v in keys(g:)
: silent! exe "unlet " . v
:endfor
:unlet v
:qa!
ENDTEST
Results of test49.vim:

View File

@ -1,12 +0,0 @@
Results of test49.vim:
*** Test 82: OK (8454401)
*** Test 83: OK (2835)
*** Test 84: OK (934782101)
*** Test 85: OK (198689)
--- Test 86: No Crash for vimgrep on BufUnload
*** Test 86: OK (0)
--- Test 88: All tests were run with throwing exceptions on error.
The $VIMNOERRTHROW control is not configured.
--- Test 88: All tests were run with throwing exceptions on interrupt.
The $VIMNOINTTHROW control is not configured.
*** Test 88: OK (50443995)

File diff suppressed because it is too large Load Diff

View File

@ -1145,7 +1145,6 @@ func Test_breakpt_endif_intr()
let caught_intr = 0
debuggreedy
call feedkeys(":call F()\<CR>quit\<CR>", "xt")
call F()
catch /^Vim:Interrupt$/
call assert_match('\.F, line 4', v:throwpoint)
let caught_intr = 1
@ -1176,7 +1175,6 @@ func Test_breakpt_else_intr()
let caught_intr = 0
debuggreedy
call feedkeys(":call F()\<CR>quit\<CR>", "xt")
call F()
catch /^Vim:Interrupt$/
call assert_match('\.F, line 4', v:throwpoint)
let caught_intr = 1
@ -1205,7 +1203,6 @@ func Test_breakpt_endwhile_intr()
let caught_intr = 0
debuggreedy
call feedkeys(":call F()\<CR>quit\<CR>", "xt")
call F()
catch /^Vim:Interrupt$/
call assert_match('\.F, line 4', v:throwpoint)
let caught_intr = 1
@ -1217,38 +1214,24 @@ func Test_breakpt_endwhile_intr()
delfunc F
endfunc
" Test for setting a breakpoint on an :endtry where an exception is pending to
" be processed and then quit the script. This should generate an interrupt and
" the thrown exception should be ignored.
func Test_breakpt_endtry_intr()
func F()
try
let g:Xpath ..= 'a'
throw "abc"
endtry
invalid_command
" Test for setting a breakpoint on a script local function
func Test_breakpt_scriptlocal_func()
let g:Xpath = ''
func s:G()
let g:Xpath ..= 'a'
endfunc
let g:Xpath = ''
breakadd func 4 F
try
let caught_intr = 0
let caught_abc = 0
debuggreedy
call feedkeys(":call F()\<CR>quit\<CR>", "xt")
call F()
catch /abc/
let caught_abc = 1
catch /^Vim:Interrupt$/
call assert_match('\.F, line 4', v:throwpoint)
let caught_intr = 1
endtry
let funcname = expand("<SID>") .. "G"
exe "breakadd func 1 " .. funcname
debuggreedy
redir => output
call feedkeys(":call " .. funcname .. "()\<CR>c\<CR>", "xt")
redir END
0debuggreedy
call assert_equal(1, caught_intr)
call assert_equal(0, caught_abc)
call assert_match('Breakpoint in "' .. funcname .. '" line 1', output)
call assert_equal('a', g:Xpath)
breakdel *
delfunc F
exe "delfunc " .. funcname
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -5328,6 +5328,29 @@ func Test_lhelpgrep_from_help_window()
new | only!
endfunc
" Test for the crash fixed by 7.3.715
func Test_setloclist_crash()
%bw!
let g:BufNum = bufnr()
augroup QF_Test
au!
au BufUnload * call setloclist(0, [{'bufnr':g:BufNum, 'lnum':1, 'col':1, 'text': 'tango down'}])
augroup END
try
lvimgrep /.*/ *.mak
catch /E926:/
endtry
call assert_equal('tango down', getloclist(0, {'items' : 0}).items[0].text)
call assert_equal(1, getloclist(0, {'size' : 0}).size)
augroup QF_Test
au!
augroup END
unlet g:BufNum
%bw!
endfunc
" Test for adding an invalid entry with the quickfix window open and making
" sure that the window contents are not changed
func Test_add_invalid_entry_with_qf_window()

View File

@ -1,5 +1,6 @@
" Test various aspects of the Vim script language.
" Most of this was formerly in test49.
" Most of this was formerly in test49.vim (developed by Servatius Brandt
" <Servatius.Brandt@fujitsu-siemens.com>)
source check.vim
source shared.vim
@ -5878,15 +5879,63 @@ func Test_discard_exception_after_error_1()
call RunInNewVim(test, verify)
endfunc
" TODO: Not able inject an interrupt after throwing an exception
func Disable_Test_discard_exception_after_error_2()
let test =<< trim [CODE]
" interrupt the code before the endtry is invoked
func Test_discard_exception_after_error_2()
XpathINIT
let lines =<< trim [CODE]
try
Xpath 'a'
try
Xpath 'b'
throw "arrgh"
call interrupt() " FIXME: throw is not interrupted here
call assert_report('should not get here')
endtry " interrupt here
call assert_report('should not get here')
catch /arrgh/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
[CODE]
call writefile(lines, 'Xscript')
breakadd file 7 Xscript
try
let caught_intr = 0
debuggreedy
call feedkeys(":source Xscript\<CR>quit\<CR>", "xt")
catch /^Vim:Interrupt$/
call assert_match('Xscript, line 7', v:throwpoint)
let caught_intr = 1
endtry
0debuggreedy
call assert_equal(1, caught_intr)
call assert_equal('ab', g:Xpath)
breakdel *
call delete('Xscript')
endfunc
"-------------------------------------------------------------------------------
" Test 82: Ignoring :catch clauses after an error or interrupt {{{1
"
" When an exception is thrown and an error or interrupt occurs before
" the matching :catch clause is reached, the exception is discarded
" and the :catch clause is ignored (also for the error or interrupt
" exception being thrown then).
"-------------------------------------------------------------------------------
func Test_ignore_catch_after_error_1()
let test =<< trim [CODE]
try
try
Xpath 'a'
throw "arrgh"
call assert_report('should not get here')
if 1
call assert_report('should not get here')
" error after :throw: missing :endif
catch /.*/
call assert_report('should not get here')
catch /.*/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
@ -5896,7 +5945,503 @@ func Disable_Test_discard_exception_after_error_2()
call assert_report('should not get here')
[CODE]
let verify =<< trim [CODE]
call assert_equal('ab', g:Xpath)
call assert_equal('a', g:Xpath)
[CODE]
call RunInNewVim(test, verify)
endfunc
func Test_ignore_catch_after_error_2()
let test =<< trim [CODE]
func E()
try
try
Xpath 'a'
throw "arrgh"
call assert_report('should not get here')
if 1
call assert_report('should not get here')
" error after :throw: missing :endif
catch /.*/
call assert_report('should not get here')
catch /.*/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
catch /arrgh/
call assert_report('should not get here')
endtry
endfunc
call E()
call assert_report('should not get here')
[CODE]
let verify =<< trim [CODE]
call assert_equal('a', g:Xpath)
[CODE]
call RunInNewVim(test, verify)
endfunc
" interrupt right before a catch is invoked in a script
func Test_ignore_catch_after_intr_1()
XpathINIT
let lines =<< trim [CODE]
try
try
Xpath 'a'
throw "arrgh"
call assert_report('should not get here')
catch /.*/ " interrupt here
call assert_report('should not get here')
catch /.*/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
catch /arrgh/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
[CODE]
call writefile(lines, 'Xscript')
breakadd file 6 Xscript
try
let caught_intr = 0
debuggreedy
call feedkeys(":source Xscript\<CR>quit\<CR>", "xt")
catch /^Vim:Interrupt$/
call assert_match('Xscript, line 6', v:throwpoint)
let caught_intr = 1
endtry
0debuggreedy
call assert_equal(1, caught_intr)
call assert_equal('a', g:Xpath)
breakdel *
call delete('Xscript')
endfunc
" interrupt right before a catch is invoked inside a function.
func Test_ignore_catch_after_intr_2()
XpathINIT
func F()
try
try
Xpath 'a'
throw "arrgh"
call assert_report('should not get here')
catch /.*/ " interrupt here
call assert_report('should not get here')
catch /.*/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
catch /arrgh/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
endfunc
breakadd func 6 F
try
let caught_intr = 0
debuggreedy
call feedkeys(":call F()\<CR>quit\<CR>", "xt")
catch /^Vim:Interrupt$/
call assert_match('\.F, line 6', v:throwpoint)
let caught_intr = 1
endtry
0debuggreedy
call assert_equal(1, caught_intr)
call assert_equal('a', g:Xpath)
breakdel *
delfunc F
endfunc
"-------------------------------------------------------------------------------
" Test 83: Executing :finally clauses after an error or interrupt {{{1
"
" When an exception is thrown and an error or interrupt occurs before
" the :finally of the innermost :try is reached, the exception is
" discarded and the :finally clause is executed.
"-------------------------------------------------------------------------------
func Test_finally_after_error()
let test =<< trim [CODE]
try
Xpath 'a'
try
Xpath 'b'
throw "arrgh"
call assert_report('should not get here')
if 1
call assert_report('should not get here')
" error after :throw: missing :endif
finally
Xpath 'c'
endtry
call assert_report('should not get here')
catch /arrgh/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
[CODE]
let verify =<< trim [CODE]
call assert_equal('abc', g:Xpath)
[CODE]
call RunInNewVim(test, verify)
endfunc
" interrupt the code right before the finally is invoked
func Test_finally_after_intr()
XpathINIT
let lines =<< trim [CODE]
try
Xpath 'a'
try
Xpath 'b'
throw "arrgh"
call assert_report('should not get here')
finally " interrupt here
Xpath 'c'
endtry
call assert_report('should not get here')
catch /arrgh/
call assert_report('should not get here')
endtry
call assert_report('should not get here')
[CODE]
call writefile(lines, 'Xscript')
breakadd file 7 Xscript
try
let caught_intr = 0
debuggreedy
call feedkeys(":source Xscript\<CR>quit\<CR>", "xt")
catch /^Vim:Interrupt$/
call assert_match('Xscript, line 7', v:throwpoint)
let caught_intr = 1
endtry
0debuggreedy
call assert_equal(1, caught_intr)
call assert_equal('abc', g:Xpath)
breakdel *
call delete('Xscript')
endfunc
"-------------------------------------------------------------------------------
" Test 84: Exceptions in autocommand sequences. {{{1
"
" When an exception occurs in a sequence of autocommands for
" a specific event, the rest of the sequence is not executed. The
" command that triggered the autocommand execution aborts, and the
" exception is propagated to the caller.
"
" For the FuncUndefined event under a function call expression or
" :call command, the function is not executed, even when it has
" been defined by the autocommands before the exception occurred.
"-------------------------------------------------------------------------------
func Test_autocmd_exception()
let test =<< trim [CODE]
func INT()
call interrupt()
endfunc
aug TMP
autocmd!
autocmd User x1 Xpath 'a'
autocmd User x1 throw "x1"
autocmd User x1 call assert_report('should not get here')
autocmd User x2 Xpath 'b'
autocmd User x2 asdf
autocmd User x2 call assert_report('should not get here')
autocmd User x3 Xpath 'c'
autocmd User x3 call INT()
autocmd User x3 call assert_report('should not get here')
autocmd FuncUndefined U1 func U1()
autocmd FuncUndefined U1 call assert_report('should not get here')
autocmd FuncUndefined U1 endfunc
autocmd FuncUndefined U1 Xpath 'd'
autocmd FuncUndefined U1 throw "U1"
autocmd FuncUndefined U1 call assert_report('should not get here')
autocmd FuncUndefined U2 func U2()
autocmd FuncUndefined U2 call assert_report('should not get here')
autocmd FuncUndefined U2 endfunc
autocmd FuncUndefined U2 Xpath 'e'
autocmd FuncUndefined U2 ASDF
autocmd FuncUndefined U2 call assert_report('should not get here')
autocmd FuncUndefined U3 func U3()
autocmd FuncUndefined U3 call assert_report('should not get here')
autocmd FuncUndefined U3 endfunc
autocmd FuncUndefined U3 Xpath 'f'
autocmd FuncUndefined U3 call INT()
autocmd FuncUndefined U3 call assert_report('should not get here')
aug END
try
try
Xpath 'g'
doautocmd User x1
catch /x1/
Xpath 'h'
endtry
while 1
try
Xpath 'i'
doautocmd User x2
catch /asdf/
Xpath 'j'
finally
Xpath 'k'
break
endtry
endwhile
while 1
try
Xpath 'l'
doautocmd User x3
catch /Vim:Interrupt/
Xpath 'm'
finally
Xpath 'n'
" ... but break loop for caught interrupt exception,
" or discard interrupt and break loop if $VIMNOINTTHROW
break
endtry
endwhile
if exists("*U1") | delfunction U1 | endif
if exists("*U2") | delfunction U2 | endif
if exists("*U3") | delfunction U3 | endif
try
Xpath 'o'
call U1()
catch /U1/
Xpath 'p'
endtry
while 1
try
Xpath 'q'
call U2()
catch /ASDF/
Xpath 'r'
finally
Xpath 's'
" ... but break loop for caught error exception,
" or discard error and break loop if $VIMNOERRTHROW
break
endtry
endwhile
while 1
try
Xpath 't'
call U3()
catch /Vim:Interrupt/
Xpath 'u'
finally
Xpath 'v'
" ... but break loop for caught interrupt exception,
" or discard interrupt and break loop if $VIMNOINTTHROW
break
endtry
endwhile
catch /.*/
call assert_report('should not get here')
endtry
Xpath 'w'
[CODE]
let verify =<< trim [CODE]
call assert_equal('gahibjklcmnodpqerstfuvw', g:Xpath)
[CODE]
call RunInNewVim(test, verify)
endfunc
"-------------------------------------------------------------------------------
" Test 85: Error exceptions in autocommands for I/O command events {{{1
"
" When an I/O command is inside :try/:endtry, autocommands to be
" executed after it should be skipped on an error (exception) in the
" command itself or in autocommands to be executed before the command.
" In the latter case, the I/O command should not be executed either.
" Example 1: BufWritePre, :write, BufWritePost
" Example 2: FileReadPre, :read, FileReadPost.
"-------------------------------------------------------------------------------
func Test_autocmd_error_io_exception()
let test =<< trim [CODE]
" Remove the autocommands for the events specified as arguments in all used
" autogroups.
func Delete_autocommands(...)
let augfile = tempname()
while 1
try
exec "redir >" . augfile
aug
redir END
exec "edit" augfile
g/^$/d
norm G$
let wrap = "w"
while search('\%( \|^\)\@<=.\{-}\%( \)\@=', wrap) > 0
let wrap = "W"
exec "norm y/ \n"
let argno = 1
while argno <= a:0
exec "au!" escape(@", " ") a:{argno}
let argno = argno + 1
endwhile
endwhile
catch /.*/
finally
bwipeout!
call delete(augfile)
break
endtry
endwhile
endfunc
call Delete_autocommands("BufWritePre", "BufWritePost")
while 1
try
try
let post = 0
aug TMP
au! BufWritePost * let post = 1
aug END
write /n/o/n/e/x/i/s/t/e/n/t
catch /^Vim(write):/
Xpath 'a'
call assert_match("E212: Can't open file for writing", v:exception)
finally
Xpath 'b'
call assert_equal(0, post)
au! TMP
aug! TMP
endtry
catch /.*/
call assert_report('should not get here')
finally
Xpath 'c'
break
endtry
endwhile
while 1
try
try
let post = 0
aug TMP
au! BufWritePre * asdf
au! BufWritePost * let post = 1
aug END
let tmpfile = tempname()
exec "write" tmpfile
catch /^Vim\((write)\)\=:/
Xpath 'd'
call assert_match('E492: Not an editor command', v:exception)
finally
Xpath 'e'
if filereadable(tmpfile)
call assert_report('should not get here')
endif
call assert_equal(0, post)
au! TMP
aug! TMP
endtry
catch /.*/
call assert_report('should not get here')
finally
Xpath 'f'
break
endtry
endwhile
call delete(tmpfile)
call Delete_autocommands("BufWritePre", "BufWritePost",
\ "BufReadPre", "BufReadPost", "FileReadPre", "FileReadPost")
while 1
try
try
let post = 0
aug TMP
au! FileReadPost * let post = 1
aug END
let caught = 0
read /n/o/n/e/x/i/s/t/e/n/t
catch /^Vim(read):/
Xpath 'g'
call assert_match("E484: Can't open file", v:exception)
finally
Xpath 'h'
call assert_equal(0, post)
au! TMP
aug! TMP
endtry
catch /.*/
call assert_report('should not get here')
finally
Xpath 'i'
break
endtry
endwhile
while 1
try
let infile = tempname()
let tmpfile = tempname()
call writefile(["XYZ"], infile)
exec "edit" tmpfile
try
Xpath 'j'
try
let post = 0
aug TMP
au! FileReadPre * asdf
au! FileReadPost * let post = 1
aug END
exec "0read" infile
catch /^Vim\((read)\)\=:/
Xpath 'k'
call assert_match('E492: Not an editor command', v:exception)
finally
Xpath 'l'
if getline("1") == "XYZ"
call assert_report('should not get here')
endif
call assert_equal(0, post)
au! TMP
aug! TMP
endtry
finally
Xpath 'm'
bwipeout!
endtry
catch /.*/
call assert_report('should not get here')
finally
Xpath 'n'
break
endtry
endwhile
call delete(infile)
call delete(tmpfile)
[CODE]
let verify =<< trim [CODE]
call assert_equal('abcdefghijklmn', g:Xpath)
[CODE]
call RunInNewVim(test, verify)
endfunc