# HG changeset patch # User Bram Moolenaar # Date 1586202331 -7200 # Node ID 2c4d9ca337693b3bf82249e3f38bebf7213ad637 # Parent db6b095f4073a620053cc438dbf4f47835988c36 patch 8.2.0522: several errors are not tested for Commit: https://github.com/vim/vim/commit/ee4e0c1e9a81cb5d96e0060203a9033c2f28588e Author: Bram Moolenaar Date: Mon Apr 6 21:35:05 2020 +0200 patch 8.2.0522: several errors are not tested for Problem: Several errors are not tested for. Solution: Add tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5892) diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -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 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 diff --git a/src/testdir/test_clientserver.vim b/src/testdir/test_clientserver.vim --- a/src/testdir/test_clientserver.vim +++ b/src/testdir/test_clientserver.vim @@ -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 diff --git a/src/testdir/test_digraph.vim b/src/testdir/test_digraph.vim --- a/src/testdir/test_digraph.vim +++ b/src/testdir/test_digraph.vim @@ -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\ 100"', 'E104:') + call assert_fails('exe "digraph \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 diff --git a/src/testdir/test_expand.vim b/src/testdir/test_expand.vim --- a/src/testdir/test_expand.vim +++ b/src/testdir/test_expand.vim @@ -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 diff --git a/src/testdir/test_expr.vim b/src/testdir/test_expr.vim --- a/src/testdir/test_expr.vim +++ b/src/testdir/test_expr.vim @@ -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() diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -1966,6 +1966,7 @@ func Test_range() execute "normal! a\=[complete(col('.'), range(10)), ''][1]\" " complete_info() execute "normal! a\=[complete(col('.'), range(10)), ''][1]\\=[complete_info(range(5)), ''][1]\" + call assert_fails('call complete(1, ["a"])', 'E785:') " copy() call assert_equal([1, 2, 3], copy(range(1, 3))) diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim --- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -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() diff --git a/src/testdir/test_highlight.vim b/src/testdir/test_highlight.vim --- a/src/testdir/test_highlight.vim +++ b/src/testdir/test_highlight.vim @@ -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 = "\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 diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -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\\"', 'E840:') + set completefunc& + delfunc CompleteFunc + close! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_lambda.vim b/src/testdir/test_lambda.vim --- a/src/testdir/test_lambda.vim +++ b/src/testdir/test_lambda.vim @@ -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 diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim --- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -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() diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim --- a/src/testdir/test_normal.vim +++ b/src/testdir/test_normal.vim @@ -364,6 +364,7 @@ func Test_normal09a_operatorfunc() " clean up unmap ,, set opfunc= + call assert_fails('normal Vg@', 'E774:') bw! unlet! g:opt endfunc diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -195,6 +195,7 @@ func Test_complete() new call feedkeys("i\\", '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() diff --git a/src/testdir/test_preview.vim b/src/testdir/test_preview.vim --- a/src/testdir/test_preview.vim +++ b/src/testdir/test_preview.vim @@ -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 diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim --- a/src/testdir/test_user_func.vim +++ b/src/testdir/test_user_func.vim @@ -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 diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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 ') + 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 diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -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 diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim --- a/src/testdir/test_viminfo.vim +++ b/src/testdir/test_viminfo.vim @@ -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 diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim --- a/src/testdir/test_vimscript.vim +++ b/src/testdir/test_vimscript.vim @@ -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, "\\n") + call term_wait(buf) + "let l = '' "for i in range(1, 6) " let l ..= term_getline(buf, i) . "\n" diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim --- a/src/testdir/test_window_cmd.vim +++ b/src/testdir/test_window_cmd.vim @@ -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 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 522, +/**/ 521, /**/ 520,