To: vim_dev@googlegroups.com Subject: Patch 8.2.0522 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0522 Problem: Several errors are not tested for. Solution: Add tests. (Yegappan Lakshmanan, closes #5892) Files: src/testdir/test_autocmd.vim, src/testdir/test_clientserver.vim, src/testdir/test_digraph.vim, src/testdir/test_expand.vim, src/testdir/test_expr.vim, src/testdir/test_functions.vim, src/testdir/test_gui.vim, src/testdir/test_highlight.vim, src/testdir/test_ins_complete.vim, src/testdir/test_lambda.vim, src/testdir/test_listdict.vim, src/testdir/test_normal.vim, src/testdir/test_options.vim, src/testdir/test_preview.vim, src/testdir/test_user_func.vim, src/testdir/test_vim9_func.vim, src/testdir/test_vim9_script.vim, src/testdir/test_viminfo.vim, src/testdir/test_vimscript.vim, src/testdir/test_window_cmd.vim *** ../vim-8.2.0521/src/testdir/test_autocmd.vim 2020-03-29 16:06:25.477382704 +0200 --- src/testdir/test_autocmd.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 2483,2486 **** --- 2483,2510 ---- 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 *** ../vim-8.2.0521/src/testdir/test_clientserver.vim 2020-04-04 14:00:34.197098267 +0200 --- src/testdir/test_clientserver.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 2,7 **** --- 2,12 ---- source check.vim CheckFeature job + + if !has('clientserver') + call assert_fails('call remote_startserver("local")', 'E942:') + endif + CheckFeature clientserver source shared.vim *************** *** 161,166 **** --- 166,172 ---- 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 *** ../vim-8.2.0521/src/testdir/test_digraph.vim 2020-03-02 20:54:19.323757498 +0100 --- src/testdir/test_digraph.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 210,215 **** --- 210,217 ---- 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,478 **** --- 477,491 ---- 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 *** ../vim-8.2.0521/src/testdir/test_expand.vim 2020-04-04 14:00:34.197098267 +0200 --- src/testdir/test_expand.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 131,136 **** --- 131,137 ---- 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 *** ../vim-8.2.0521/src/testdir/test_expr.vim 2020-03-25 22:23:41.898363595 +0100 --- src/testdir/test_expr.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 502,507 **** --- 502,508 ---- 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() *** ../vim-8.2.0521/src/testdir/test_functions.vim 2020-04-04 14:00:34.197098267 +0200 --- src/testdir/test_functions.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 1966,1971 **** --- 1966,1972 ---- 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))) *** ../vim-8.2.0521/src/testdir/test_gui.vim 2020-03-25 22:23:41.898363595 +0100 --- src/testdir/test_gui.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 388,393 **** --- 388,398 ---- 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,407 **** --- 407,414 ---- 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,473 **** --- 475,481 ---- endfunc func Test_set_guifontwide() + call assert_fails('set guifontwide=*', 'E533:') let skipped = '' if !g:x11_based_gui *************** *** 785,790 **** --- 793,799 ---- " 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() *** ../vim-8.2.0521/src/testdir/test_highlight.vim 2020-02-02 13:47:02.688673781 +0100 --- src/testdir/test_highlight.vim 2020-04-06 21:28:44.505704082 +0200 *************** *** 689,698 **** endfunc " Do this test last, sometimes restoring the columns doesn't work ! function 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 --- 689,716 ---- endfunc " Do this test last, sometimes restoring the columns doesn't work ! 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 ! 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 *** ../vim-8.2.0521/src/testdir/test_ins_complete.vim 2020-03-15 14:19:19.394376259 +0100 --- src/testdir/test_ins_complete.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 465,467 **** --- 465,487 ---- 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 *** ../vim-8.2.0521/src/testdir/test_lambda.vim 2020-03-28 21:38:02.128802283 +0100 --- src/testdir/test_lambda.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 311,314 **** --- 311,330 ---- 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 *** ../vim-8.2.0521/src/testdir/test_listdict.vim 2020-03-25 22:23:41.898363595 +0100 --- src/testdir/test_listdict.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 633,638 **** --- 633,639 ---- 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() *** ../vim-8.2.0521/src/testdir/test_normal.vim 2020-03-30 19:30:07.133542905 +0200 --- src/testdir/test_normal.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 364,369 **** --- 364,370 ---- " clean up unmap ,, set opfunc= + call assert_fails('normal Vg@', 'E774:') bw! unlet! g:opt endfunc *** ../vim-8.2.0521/src/testdir/test_options.vim 2020-04-04 14:00:34.197098267 +0200 --- src/testdir/test_options.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 195,200 **** --- 195,201 ---- new call feedkeys("i\\", 'xt') bwipe! + call assert_fails('set complete=ix', 'E535:') set complete& endfun *************** *** 381,386 **** --- 382,391 ---- 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() *** ../vim-8.2.0521/src/testdir/test_preview.vim 2019-12-01 15:08:40.000000000 +0100 --- src/testdir/test_preview.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 13,15 **** --- 13,62 ---- 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 *** ../vim-8.2.0521/src/testdir/test_user_func.vim 2020-03-18 19:32:22.514363313 +0100 --- src/testdir/test_user_func.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 169,171 **** --- 169,178 ---- 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 *** ../vim-8.2.0521/src/testdir/test_vim9_func.vim 2020-04-05 22:14:50.626952071 +0200 --- src/testdir/test_vim9_func.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 168,177 **** --- 168,179 ---- 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,440 **** --- 438,465 ---- 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 *** ../vim-8.2.0521/src/testdir/test_vim9_script.vim 2020-04-05 17:07:59.414556253 +0200 --- src/testdir/test_vim9_script.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 259,265 **** call CheckDefFailure(['5tab echo 3'], 'E16:') enddef - def Test_try_catch() let l = [] try --- 259,264 ---- *************** *** 959,965 **** assert_true(caught, 'should have caught an exception') enddef - " Keep this last, it messes up highlighting. def Test_substitute_cmd() new --- 958,963 ---- *** ../vim-8.2.0521/src/testdir/test_viminfo.vim 2020-04-04 14:00:34.197098267 +0200 --- src/testdir/test_viminfo.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 815,817 **** --- 815,838 ---- 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 *** ../vim-8.2.0521/src/testdir/test_vimscript.vim 2020-03-20 18:20:47.080975621 +0100 --- src/testdir/test_vimscript.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 1998,2003 **** --- 1998,2006 ---- 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,2049 **** --- 2047,2061 ---- @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,2070 **** --- 2063,2093 ---- " 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" *** ../vim-8.2.0521/src/testdir/test_window_cmd.vim 2020-03-25 22:23:41.898363595 +0100 --- src/testdir/test_window_cmd.vim 2020-04-06 21:28:44.509704066 +0200 *************** *** 203,245 **** %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 --- 203,208 ---- *** ../vim-8.2.0521/src/version.c 2020-04-06 21:12:38.809322010 +0200 --- src/version.c 2020-04-06 21:30:37.613266559 +0200 *************** *** 740,741 **** --- 740,743 ---- { /* Add new patch number below this line */ + /**/ + 522, /**/ -- Why don't cannibals eat clowns? Because they taste funny. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///