Patch 8.2.0644
Problem: Insufficient testing for invalid function arguments.
Solution: Add more tests. (Yegappan Lakshmanan, closes #5988)
Files: runtime/doc/eval.txt, src/testdir/test_bufline.vim,
src/testdir/test_channel.vim, src/testdir/test_clientserver.vim,
src/testdir/test_expr.vim, src/testdir/test_functions.vim,
src/testdir/test_listener.vim, src/testdir/test_match.vim,
src/testdir/test_menu.vim, src/testdir/test_quickfix.vim,
src/testdir/test_registers.vim, src/testdir/test_reltime.vim,
src/testdir/test_terminal.vim, src/testdir/test_textprop.vim,
src/testdir/test_window_cmd.vim, src/testdir/test_window_id.vim,
src/testdir/test_writefile.vim
*** ../vim-8.2.0643/runtime/doc/eval.txt 2020-04-13 19:04:02.053594029 +0200
--- runtime/doc/eval.txt 2020-04-26 15:47:03.476872723 +0200
***************
*** 8628,8635 ****
GetLoclist()->setloclist(winnr)
setmatches({list} [, {win}]) *setmatches()*
! Restores a list of matches saved by |getmatches() for the
! current window|. Returns 0 if successful, otherwise -1. All
current matches are cleared before the list is restored. See
example for |getmatches()|.
If {win} is specified, use the window with this number or
--- 8641,8648 ----
GetLoclist()->setloclist(winnr)
setmatches({list} [, {win}]) *setmatches()*
! Restores a list of matches saved by |getmatches()| for the
! current window. Returns 0 if successful, otherwise -1. All
current matches are cleared before the list is restored. See
example for |getmatches()|.
If {win} is specified, use the window with this number or
*** ../vim-8.2.0643/src/testdir/test_bufline.vim 2020-04-21 22:19:26.055486850 +0200
--- src/testdir/test_bufline.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 37,42 ****
--- 37,43 ----
call assert_equal(['d'], getbufline(b, 4))
call assert_equal(['e'], getbufline(b, 5))
call assert_equal([], getbufline(b, 6))
+ call assert_equal([], getbufline(b, 2, 1))
exe "bwipe! " . b
endfunc
*** ../vim-8.2.0643/src/testdir/test_channel.vim 2020-04-25 15:24:40.551354115 +0200
--- src/testdir/test_channel.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 869,876 ****
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'buffer', 'out_name': 'pipe-err', 'err_io': 'out'})
call assert_equal("run", job_status(job))
try
- let handle = job_getchannel(job)
call ch_sendraw(handle, "echo line one\n")
call ch_sendraw(handle, "echoerr line two\n")
call ch_sendraw(handle, "double this\n")
--- 869,878 ----
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'buffer', 'out_name': 'pipe-err', 'err_io': 'out'})
call assert_equal("run", job_status(job))
+ let handle = job_getchannel(job)
+ call assert_equal(bufnr('pipe-err'), ch_getbufnr(handle, 'out'))
+ call assert_equal(bufnr('pipe-err'), ch_getbufnr(handle, 'err'))
try
call ch_sendraw(handle, "echo line one\n")
call ch_sendraw(handle, "echoerr line two\n")
call ch_sendraw(handle, "double this\n")
***************
*** 896,901 ****
--- 898,906 ----
let job = job_start(s:python . " test_channel_pipe.py", options)
call assert_equal("run", job_status(job))
+ if has('unix') && !a:use_name
+ call assert_equal(bufnr('%'), ch_getbufnr(job, 'in'))
+ endif
try
let handle = job_getchannel(job)
call assert_equal('one', ch_read(handle))
*** ../vim-8.2.0643/src/testdir/test_clientserver.vim 2020-04-08 22:56:23.470398582 +0200
--- src/testdir/test_clientserver.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 164,169 ****
--- 164,170 ----
endif
endtry
+ call assert_fails('call remote_startserver([])', 'E730:')
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:')
*** ../vim-8.2.0643/src/testdir/test_expr.vim 2020-04-25 15:24:40.551354115 +0200
--- src/testdir/test_expr.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 471,476 ****
--- 471,477 ----
endif
eval set->setmatches()
call assert_equal(exp, getmatches())
+ call assert_fails('let m = setmatches([], [])', 'E957:')
endfunc
func Test_empty_concatenate()
*** ../vim-8.2.0643/src/testdir/test_functions.vim 2020-04-25 15:24:40.551354115 +0200
--- src/testdir/test_functions.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 29,34 ****
--- 29,36 ----
call assert_equal(0, and(has('ttyout'), 0))
call assert_equal(1, has('multi_byte_encoding'))
endif
+ call assert_equal(1, has('vcon', 1))
+ call assert_equal(1, has('mouse_gpm_enabled', 1))
call assert_equal(0, has('nonexistent'))
call assert_equal(0, has('nonexistent', 1))
***************
*** 1304,1315 ****
" Test for the inputdialog() function
func Test_inputdialog()
! CheckNotGui
!
! call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt')
! call assert_equal('xx', v)
! call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt')
! call assert_equal('yy', v)
endfunc
" Test for inputlist()
--- 1306,1320 ----
" Test for the inputdialog() function
func Test_inputdialog()
! if has('gui_running')
! call assert_fails('let v=inputdialog([], "xx")', 'E730:')
! call assert_fails('let v=inputdialog("Q", [])', 'E730:')
! else
! call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt')
! call assert_equal('xx', v)
! call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt')
! call assert_equal('yy', v)
! endif
endfunc
" Test for inputlist()
***************
*** 1344,1349 ****
--- 1349,1355 ----
call balloon_show('hi!')
if !has('gui_running')
call balloon_show(range(3))
+ call balloon_show([])
endif
endif
endfunc
***************
*** 2213,2218 ****
--- 2219,2227 ----
call assert_fails('let x=range(2, 8, 0)', 'E726:')
call assert_fails('let x=range(3, 1)', 'E727:')
call assert_fails('let x=range(1, 3, -2)', 'E727:')
+ call assert_fails('let x=range([])', 'E745:')
+ call assert_fails('let x=range(1, [])', 'E745:')
+ call assert_fails('let x=range(1, 4, [])', 'E745:')
endfunc
func Test_echoraw()
*** ../vim-8.2.0643/src/testdir/test_listener.vim 2020-03-25 21:13:42.356409331 +0100
--- src/testdir/test_listener.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 207,212 ****
--- 207,217 ----
call listener_remove(id)
bwipe!
+
+ " Invalid arguments
+ call assert_fails('call listener_add([])', 'E921:')
+ call assert_fails('call listener_add("s:StoreListArgs", [])', 'E158:')
+ call assert_fails('call listener_flush([])', 'E158:')
endfunc
func s:StoreBufList(buf, start, end, added, list)
*** ../vim-8.2.0643/src/testdir/test_match.vim 2020-04-08 21:50:18.872619665 +0200
--- src/testdir/test_match.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 163,168 ****
--- 163,169 ----
call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:')
call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:')
call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:')
+ call assert_fails("call matchadd('Error', 'XXX', [], 0)", 'E745:')
endfunc
func Test_matchaddpos()
***************
*** 278,283 ****
--- 279,286 ----
call assert_fails("call matchaddpos('Error', [1], 1, 5, {'window':12345})", 'E957:')
" Why doesn't the following error have an error code E...?
call assert_fails("call matchaddpos('Error', [{}])", 'E290:')
+ call assert_equal(-1, matchaddpos('Error', test_null_list()))
+ call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:')
endfunc
func OtherWindowCommon()
***************
*** 334,338 ****
call delete('XscriptMatchCommon')
endfunc
-
" vim: shiftwidth=2 sts=2 expandtab
--- 337,340 ----
*** ../vim-8.2.0643/src/testdir/test_menu.vim 2020-03-29 20:08:41.147942551 +0200
--- src/testdir/test_menu.vim 2020-04-26 15:47:03.476872723 +0200
***************
*** 255,260 ****
--- 255,261 ----
nmenu Test.abc <Nop>
call assert_equal('<Nop>', menu_info('Test.abc').rhs)
call assert_fails('call menu_info([])', 'E730:')
+ call assert_fails('call menu_info("", [])', 'E730:')
nunmenu Test
" Test for defining menus in different modes
*** ../vim-8.2.0643/src/testdir/test_quickfix.vim 2020-04-25 15:24:40.551354115 +0200
--- src/testdir/test_quickfix.vim 2020-04-26 15:47:03.480872711 +0200
***************
*** 1488,1493 ****
--- 1488,1494 ----
\ " {'bufnr':999, 'lnum':5}])", 'E92:')
call g:Xsetlist([[1, 2,3]])
call assert_equal(0, len(g:Xgetlist()))
+ call assert_fails('call g:Xsetlist([], [])', 'E928:')
endfunc
func Test_setqflist()
*** ../vim-8.2.0643/src/testdir/test_registers.vim 2020-03-25 22:23:41.898363595 +0100
--- src/testdir/test_registers.vim 2020-04-26 15:47:03.480872711 +0200
***************
*** 259,264 ****
--- 259,266 ----
call feedkeys(":\<C-R>r\<Esc>", 'xt')
call assert_equal("a\rb\r", histget(':', -1))
+ call assert_fails('let r = getreg("=", [])', 'E745:')
+ call assert_fails('let r = getreg("=", 1, [])', 'E745:')
enew!
endfunc
*** ../vim-8.2.0643/src/testdir/test_reltime.vim 2019-09-04 22:15:31.000000000 +0200
--- src/testdir/test_reltime.vim 2020-04-26 15:47:03.480872711 +0200
***************
*** 23,26 ****
--- 23,31 ----
call assert_true(reltimestr(differs) != '0.0')
call assert_true(reltimefloat(differs) < 0.1)
call assert_true(reltimefloat(differs) > 0.0)
+
+ call assert_equal(0, reltime({}))
+ call assert_equal(0, reltime({}, {}))
endfunc
+
+ " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0643/src/testdir/test_terminal.vim 2020-04-19 18:13:14.542129938 +0200
--- src/testdir/test_terminal.vim 2020-04-26 15:47:03.480872711 +0200
***************
*** 2634,2637 ****
--- 2634,2655 ----
call delete('XTest_startinsert')
endfunc
+ " Test for passing invalid arguments to terminal functions
+ func Test_term_func_invalid_arg()
+ call assert_fails('let b = term_getaltscreen([])', 'E745:')
+ call assert_fails('let p = term_getansicolors([])', 'E745:')
+ call assert_fails('let a = term_getattr(1, [])', 'E730:')
+ call assert_fails('let c = term_getcursor([])', 'E745:')
+ call assert_fails('let l = term_getline([], 1)', 'E745:')
+ call assert_fails('let l = term_getscrolled([])', 'E745:')
+ call assert_fails('let s = term_getsize([])', 'E745:')
+ call assert_fails('let s = term_getstatus([])', 'E745:')
+ call assert_fails('let s = term_scrape([], 1)', 'E745:')
+ call assert_fails('call term_sendkeys([], "a")', 'E745:')
+ call assert_fails('call term_setansicolors([], [])', 'E745:')
+ call assert_fails('call term_setapi([], "")', 'E745:')
+ call assert_fails('call term_setrestore([], "")', 'E745:')
+ call assert_fails('call term_setkill([], "")', 'E745:')
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0643/src/testdir/test_textprop.vim 2020-03-13 21:36:32.880494461 +0100
--- src/testdir/test_textprop.vim 2020-04-26 15:47:03.480872711 +0200
***************
*** 1204,1206 ****
--- 1204,1231 ----
bwipe!
call prop_type_delete('test')
endfunc
+
+ " Test for passing invalid arguments to prop_xxx() functions
+ func Test_prop_func_invalid_args()
+ call assert_fails('call prop_clear(1, 2, [])', 'E715:')
+ call assert_fails('call prop_clear(-1, 2)', 'E16:')
+ call assert_fails('call prop_find(test_null_dict())', 'E474:')
+ call assert_fails('call prop_find({"bufnr" : []})', 'E158:')
+ call assert_fails('call prop_find({})', 'E968:')
+ call assert_fails('call prop_find({}, "x")', 'E474:')
+ call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
+ call assert_fails('call prop_list(1, [])', 'E715:')
+ call assert_fails('call prop_list(-1 , {})', 'E16:')
+ call assert_fails('call prop_remove([])', 'E474:')
+ call assert_fails('call prop_remove({}, -2)', 'E16:')
+ call assert_fails('call prop_remove({})', 'E968:')
+ call assert_fails('call prop_type_add([], {})', 'E474:')
+ call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
+ call assert_fails("call prop_type_delete([])", 'E474:')
+ call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
+ call assert_fails("call prop_type_get([])", 'E474:')
+ call assert_fails("call prop_type_get('', [])", 'E474:')
+ call assert_fails("call prop_type_list([])", 'E715:')
+ endfunc
+
+ " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0643/src/testdir/test_window_cmd.vim 2020-04-21 22:19:26.059486839 +0200
--- src/testdir/test_window_cmd.vim 2020-04-26 15:47:03.480872711 +0200
***************
*** 445,450 ****
--- 445,451 ----
call assert_equal([1, 32], win_screenpos(2))
call assert_equal([12, 1], win_screenpos(3))
call assert_equal([0, 0], win_screenpos(4))
+ call assert_fails('let l = win_screenpos([])', 'E745:')
only
endfunc
***************
*** 694,699 ****
--- 695,701 ----
only!
bwipe!
+ call assert_fails('call winrestview(test_null_dict())', 'E474:')
endfunc
func Test_relative_cursor_position_after_move_and_resize()
***************
*** 870,875 ****
--- 872,881 ----
call assert_fails("echo winnr('ll')", 'E15:')
call assert_fails("echo winnr('5')", 'E15:')
call assert_equal(4, winnr('0h'))
+ call assert_fails("let w = winnr([])", 'E730:')
+ call assert_equal('unknown', win_gettype(-1))
+ call assert_equal(-1, winheight(-1))
+ call assert_equal(-1, winwidth(-1))
tabnew
call assert_equal(8, tabpagewinnr(1, 'j'))
***************
*** 890,895 ****
--- 896,902 ----
call assert_equal(view, winsaveview())
bwipe!
+ call assert_fails('call winrestview(test_null_dict())', 'E474:')
endfunc
func Test_win_splitmove()
***************
*** 920,925 ****
--- 927,933 ----
call assert_equal(bufname(winbufnr(2)), 'b')
call assert_equal(bufname(winbufnr(3)), 'a')
call assert_equal(bufname(winbufnr(4)), 'd')
+ call assert_fails('call win_splitmove(winnr(), winnr("k"), test_null_dict())', 'E474:')
only | bd
call assert_fails('call win_splitmove(winnr(), 123)', 'E957:')
*** ../vim-8.2.0643/src/testdir/test_window_id.vim 2019-12-01 15:10:54.000000000 +0100
--- src/testdir/test_window_id.vim 2020-04-26 15:50:07.012403225 +0200
***************
*** 91,96 ****
--- 91,100 ----
split
call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
+ call assert_fails('let w = win_getid([])', 'E745:')
+ call assert_equal(0, win_getid(-1))
+ call assert_equal(-1, win_getid(1, -1))
+
only!
endfunc
***************
*** 130,133 ****
--- 134,141 ----
let w2 = win_getid()
call assert_equal(['leaf', w2], 2->winlayout())
tabclose
+
+ call assert_equal([], winlayout(-1))
endfunc
+
+ " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0643/src/testdir/test_writefile.vim 2020-03-19 13:08:41.502917820 +0100
--- src/testdir/test_writefile.vim 2020-04-26 15:47:25.612815544 +0200
***************
*** 207,212 ****
--- 207,218 ----
close!
enew | only
call delete('Xfile')
+
+ call writefile(test_null_list(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call writefile(test_null_blob(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call assert_fails('call writefile([], "")', 'E482:')
endfunc
func Test_write_errors()
***************
*** 245,250 ****
--- 251,262 ----
close
call delete('Xfile')
+
+ call writefile(test_null_list(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call writefile(test_null_blob(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call assert_fails('call writefile([], "")', 'E482:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0643/src/version.c 2020-04-26 14:47:41.616752488 +0200
--- src/version.c 2020-04-26 15:52:05.204105340 +0200
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 644,
/**/
--
hundred-and-one symptoms of being an internet addict:
22. You've already visited all the links at Yahoo and you're halfway through
Lycos.
/// Bram Moolenaar -- Br...@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 ///