0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 8.2.0522: several errors are not tested for

Problem:    Several errors are not tested for.
Solution:   Add tests. (Yegappan Lakshmanan, closes #5892)
This commit is contained in:
Bram Moolenaar
2020-04-06 21:35:05 +02:00
parent 15352dc6ec
commit ee4e0c1e9a
21 changed files with 243 additions and 41 deletions

View File

@@ -2483,4 +2483,28 @@ func Test_autocmd_FileReadCmd()
delfunc ReadFileCmd
endfunc
" Test for passing invalid arguments to autocmd
func Test_autocmd_invalid_args()
" Additional character after * for event
call assert_fails('autocmd *a Xfile set ff=unix', 'E215:')
augroup Test
augroup END
" Invalid autocmd event
call assert_fails('autocmd Bufabc Xfile set ft=vim', 'E216:')
" Invalid autocmd event in a autocmd group
call assert_fails('autocmd Test Bufabc Xfile set ft=vim', 'E216:')
augroup! Test
" Execute all autocmds
call assert_fails('doautocmd * BufEnter', 'E217:')
call assert_fails('augroup! x1a2b3', 'E367:')
call assert_fails('autocmd BufNew <buffer=999> pwd', 'E680:')
endfunc
" Test for deep nesting of autocmds
func Test_autocmd_deep_nesting()
autocmd BufEnter Xfile doautocmd BufEnter Xfile
call assert_fails('doautocmd BufEnter Xfile', 'E218:')
autocmd! BufEnter Xfile
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -2,6 +2,11 @@
source check.vim
CheckFeature job
if !has('clientserver')
call assert_fails('call remote_startserver("local")', 'E942:')
endif
CheckFeature clientserver
source shared.vim
@@ -161,6 +166,7 @@ func Test_client_server()
call assert_fails("let x = remote_peek([])", 'E730:')
call assert_fails("let x = remote_read('vim10')", 'E277:')
call assert_fails("call server2client('abc', 'xyz')", 'E258:')
endfunc
" Uncomment this line to get a debugging log

View File

@@ -210,6 +210,8 @@ func Test_digraphs()
call Put_Dig("00")
call Put_Dig("el")
call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.')))
call assert_fails('exe "digraph a\<Esc> 100"', 'E104:')
call assert_fails('exe "digraph \<Esc>a 100"', 'E104:')
bw!
endfunc
@@ -475,4 +477,15 @@ func Test_show_digraph_cp1251()
bwipe!
endfunc
" Test for error in a keymap file
func Test_loadkeymap_error()
if !has('keymap')
return
endif
call assert_fails('loadkeymap', 'E105:')
call writefile(['loadkeymap', 'a'], 'Xkeymap')
call assert_fails('source Xkeymap', 'E791:')
call delete('Xkeymap')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -131,6 +131,7 @@ func Test_expand_filename_multicmd()
call assert_equal(4, winnr('$'))
call assert_equal('foo!', bufname(winbufnr(1)))
call assert_equal('foo', bufname(winbufnr(2)))
call assert_fails('e %:s/.*//', 'E500:')
%bwipe!
endfunc

View File

@@ -502,6 +502,7 @@ func Test_funcref()
call assert_fails('echo funcref("{")', 'E475:')
let OneByRef = funcref("One", repeat(["foo"], 20))
call assert_fails('let OneByRef = funcref("One", repeat(["foo"], 21))', 'E118:')
call assert_fails('echo function("min") =~ function("min")', 'E694:')
endfunc
func Test_setmatches()

View File

@@ -1966,6 +1966,7 @@ func Test_range()
execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>"
" complete_info()
execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>\<C-r>=[complete_info(range(5)), ''][1]\<CR>"
call assert_fails('call complete(1, ["a"])', 'E785:')
" copy()
call assert_equal([1, 2, 3], copy(range(1, 3)))

View File

@@ -388,6 +388,11 @@ func Test_set_guifont()
call assert_equal('Monospace 10', getfontname())
endif
if has('win32')
" Invalid font names are accepted in GTK GUI
call assert_fails('set guifont=xa1bc23d7f', 'E596:')
endif
if has('xfontset')
let &guifontset = guifontset_saved
endif
@@ -402,6 +407,8 @@ func Test_set_guifontset()
CheckFeature xfontset
let skipped = ''
call assert_fails('set guifontset=*', 'E597:')
let ctype_saved = v:ctype
" First, since XCreateFontSet(3) is very sensitive to locale, fonts must
@@ -468,6 +475,7 @@ func Test_set_guifontset()
endfunc
func Test_set_guifontwide()
call assert_fails('set guifontwide=*', 'E533:')
let skipped = ''
if !g:x11_based_gui
@@ -785,6 +793,7 @@ func Test_set_term()
" It's enough to check the current value since setting 'term' to anything
" other than builtin_gui makes no sense at all.
call assert_equal('builtin_gui', &term)
call assert_fails('set term=xterm', 'E530:')
endfunc
func Test_windowid_variable()

View File

@@ -689,10 +689,28 @@ func Test_1_highlight_Normalgroup_exists()
endfunc
" Do this test last, sometimes restoring the columns doesn't work
function Test_z_no_space_before_xxx()
func Test_z_no_space_before_xxx()
let l:org_columns = &columns
set columns=17
let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
let &columns = l:org_columns
endfunction
endfunc
" Test for :highlight command errors
func Test_highlight_cmd_errors()
if has('gui_running')
" This test doesn't fail in the MS-Windows console version.
call assert_fails('hi Xcomment ctermfg=fg', 'E419:')
call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
endif
" Try using a very long terminal code. Define a dummy terminal code for this
" test.
let &t_fo = "\<Esc>1;"
let c = repeat("t_fo,", 100) . "t_fo"
call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
let &t_fo = ""
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -465,3 +465,23 @@ func Test_ins_compl_tag_sft()
set tags&
%bwipe!
endfunc
" Test for 'completefunc' deleting text
func Test_completefunc_error()
new
func CompleteFunc(findstart, base)
if a:findstart == 1
normal dd
return col('.') - 1
endif
return ['a', 'b']
endfunc
set completefunc=CompleteFunc
call setline(1, ['', 'abcd', ''])
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E840:')
set completefunc&
delfunc CompleteFunc
close!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -311,4 +311,20 @@ func Test_lambda_error()
call assert_fails('ec{@{->{d->()()', 'E15')
endfunc
func Test_closure_error()
let l =<< trim END
func F1() closure
return 1
endfunc
END
call writefile(l, 'Xscript')
let caught_932 = 0
try
source Xscript
catch /E932:/
let caught_932 = 1
endtry
call assert_equal(1, caught_932)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -633,6 +633,7 @@ func Test_reverse_sort_uniq()
endif
call assert_fails('call reverse("")', 'E899:')
call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:')
endfunc
" splitting a string to a List using split()

View File

@@ -364,6 +364,7 @@ func Test_normal09a_operatorfunc()
" clean up
unmap <buffer> ,,
set opfunc=
call assert_fails('normal Vg@', 'E774:')
bw!
unlet! g:opt
endfunc

View File

@@ -195,6 +195,7 @@ func Test_complete()
new
call feedkeys("i\<C-N>\<Esc>", 'xt')
bwipe!
call assert_fails('set complete=ix', 'E535:')
set complete&
endfun
@@ -381,6 +382,10 @@ func Test_set_ttytype()
set ttytype&
call assert_equal(&ttytype, &term)
if has('gui') && !has('gui_running')
call assert_fails('set term=gui', 'E531:')
endif
endfunc
func Test_set_all()

View File

@@ -13,3 +13,50 @@ func Test_Psearch()
call assert_equal(wincount, winnr('$'))
bwipe
endfunc
func Test_window_preview()
CheckFeature quickfix
" Open a preview window
pedit Xa
call assert_equal(2, winnr('$'))
call assert_equal(0, &previewwindow)
" Go to the preview window
wincmd P
call assert_equal(1, &previewwindow)
" Close preview window
wincmd z
call assert_equal(1, winnr('$'))
call assert_equal(0, &previewwindow)
call assert_fails('wincmd P', 'E441:')
endfunc
func Test_window_preview_from_help()
CheckFeature quickfix
filetype on
call writefile(['/* some C code */'], 'Xpreview.c')
help
pedit Xpreview.c
wincmd P
call assert_equal(1, &previewwindow)
call assert_equal('c', &filetype)
wincmd z
filetype off
close
call delete('Xpreview.c')
endfunc
func Test_multiple_preview_windows()
new
set previewwindow
new
call assert_fails('set previewwindow', 'E590:')
%bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -169,3 +169,10 @@ endfunc
func Test_failed_call_in_try()
try | call UnknownFunc() | catch | endtry
endfunc
" Test for listing user-defined functions
func Test_function_list()
call assert_fails("function Xabc", 'E123:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -168,10 +168,12 @@ def Test_return_type_wrong()
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
enddef
def Test_arg_type_wrong()
CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>')
CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')
enddef
def Test_vim9script_call()
@@ -436,5 +438,28 @@ def Test_func_return_type()
CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1013: type mismatch, expected string but got number')
enddef
" When using CheckScriptFailure() for the below test, E1010 is generated instead
" of E1056.
func Test_E1056_1059()
let caught_1056 = 0
try
def F():
return 1
enddef
catch /E1056:/
let caught_1056 = 1
endtry
call assert_equal(1, caught_1056)
let caught_1059 = 0
try
def F5(items : list)
echo 'a'
enddef
catch /E1059:/
let caught_1059 = 1
endtry
call assert_equal(1, caught_1059)
endfunc
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@@ -259,7 +259,6 @@ def Test_cmd_modifier()
call CheckDefFailure(['5tab echo 3'], 'E16:')
enddef
def Test_try_catch()
let l = []
try
@@ -959,7 +958,6 @@ def Test_interrupt_loop()
assert_true(caught, 'should have caught an exception')
enddef
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new

View File

@@ -815,3 +815,24 @@ func XTest_viminfo_marks_merge()
call test_settime(0)
let &viminfo=save_viminfo
endfunc
" Test for errors in setting 'viminfo'
func Test_viminfo_option_error()
" Missing number
call assert_fails('set viminfo=\"', 'E526:')
for c in split("'/:<@s", '\zs')
call assert_fails('set viminfo=' .. c, 'E526:')
endfor
" Missing comma
call assert_fails('set viminfo=%10!', 'E527:')
call assert_fails('set viminfo=!%10', 'E527:')
call assert_fails('set viminfo=h%10', 'E527:')
call assert_fails('set viminfo=c%10', 'E527:')
call assert_fails('set viminfo=:10%10', 'E527:')
" Missing ' setting
call assert_fails('set viminfo=%10', 'E528:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1998,6 +1998,9 @@ func Test_missing_end()
endtry
call assert_equal(1, caught_e733)
" Using endfunc with :if
call assert_fails('exe "if 1 | endfunc | endif"', 'E193:')
" Missing 'in' in a :for statement
call assert_fails('for i range(1) | endfor', 'E690:')
endfunc
@@ -2044,6 +2047,15 @@ func Test_deep_nest()
@a
let @a = ''
endfunc
" Deep nesting of function ... endfunction
func Test5()
let @a = join(repeat(['function X()'], 51), "\n")
let @a ..= "\necho v:true\n"
let @a ..= join(repeat(['endfunction'], 51), "\n")
@a
let @a = ''
endfunc
[SCRIPT]
call writefile(lines, 'Xscript')
@@ -2051,20 +2063,31 @@ func Test_deep_nest()
" Deep nesting of if ... endif
call term_sendkeys(buf, ":call Test1()\n")
call term_wait(buf)
call WaitForAssert({-> assert_match('^E579:', term_getline(buf, 5))})
" Deep nesting of for ... endfor
call term_sendkeys(buf, ":call Test2()\n")
call term_wait(buf)
call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
" Deep nesting of while ... endwhile
call term_sendkeys(buf, ":call Test3()\n")
call term_wait(buf)
call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
" Deep nesting of try ... endtry
call term_sendkeys(buf, ":call Test4()\n")
call term_wait(buf)
call WaitForAssert({-> assert_match('^E601:', term_getline(buf, 5))})
" Deep nesting of function ... endfunction
call term_sendkeys(buf, ":call Test5()\n")
call term_wait(buf)
call WaitForAssert({-> assert_match('^E1058:', term_getline(buf, 4))})
call term_sendkeys(buf, "\<C-C>\n")
call term_wait(buf)
"let l = ''
"for i in range(1, 6)
" let l ..= term_getline(buf, i) . "\n"

View File

@@ -203,43 +203,6 @@ func Test_window_split_no_room()
%bw!
endfunc
func Test_window_preview()
CheckFeature quickfix
" Open a preview window
pedit Xa
call assert_equal(2, winnr('$'))
call assert_equal(0, &previewwindow)
" Go to the preview window
wincmd P
call assert_equal(1, &previewwindow)
" Close preview window
wincmd z
call assert_equal(1, winnr('$'))
call assert_equal(0, &previewwindow)
call assert_fails('wincmd P', 'E441:')
endfunc
func Test_window_preview_from_help()
CheckFeature quickfix
filetype on
call writefile(['/* some C code */'], 'Xpreview.c')
help
pedit Xpreview.c
wincmd P
call assert_equal(1, &previewwindow)
call assert_equal('c', &filetype)
wincmd z
filetype off
close
call delete('Xpreview.c')
endfunc
func Test_window_exchange()
e Xa

View File

@@ -738,6 +738,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
522,
/**/
521,
/**/