]> granicus.if.org Git - vim/commitdiff
patch 8.2.0644: insufficient testing for invalid function arguments v8.2.0644
authorBram Moolenaar <Bram@vim.org>
Sun, 26 Apr 2020 13:59:55 +0000 (15:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 26 Apr 2020 13:59:55 +0000 (15:59 +0200)
Problem:    Insufficient testing for invalid function arguments.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #5988)

18 files changed:
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
src/version.c

index e01aad3fca911b873d5269b3cb9a7557b495e795..02ed78b2e15627284b82e5c979b8ea6d93cdc55f 100644 (file)
@@ -8641,8 +8641,8 @@ setloclist({nr}, {list} [, {action} [, {what}]])          *setloclist()*
                        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
+               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
index d359f205d5d86f422819abbc8cad9702afd26313..3326e7d2971f576421456b6473f5fceabc903418 100644 (file)
@@ -37,6 +37,7 @@ func Test_setbufline_getbufline()
   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
 
index 4ba552bdbe92dd0d52ceb43bc03b9742460feca4..4a438ea7292892f4396a5afa0bbc95729e3ff071 100644 (file)
@@ -869,8 +869,10 @@ func Test_pipe_both_to_buffer()
   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
-    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")
@@ -896,6 +898,9 @@ func Run_test_pipe_from_buffer(use_name)
 
   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))
index 4a48aed91c26120691b50a6793407d7d0fc97c4e..152a2e17729f9531e65bd3117fc1a4d5cc925e81 100644 (file)
@@ -164,6 +164,7 @@ func Test_client_server()
     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:')
index 5fc502df8126f854f07d831c344970674bd615cb..ec73aeaae4809d0dcef8e369af81661fa6056398 100644 (file)
@@ -471,6 +471,7 @@ func Test_setmatches()
   endif
   eval set->setmatches()
   call assert_equal(exp, getmatches())
+  call assert_fails('let m = setmatches([], [])', 'E957:')
 endfunc
 
 func Test_empty_concatenate()
index a0807ade7af0e7e6a8b36e9b797675b64ca3f9b2..02b658554b55bfa165bfa160fa61deedee9ec4e0 100644 (file)
@@ -29,6 +29,8 @@ func Test_has()
     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,12 +1306,15 @@ endfunc
 
 " 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)
+  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,6 +1349,7 @@ func Test_balloon_show()
     call balloon_show('hi!')
     if !has('gui_running')
       call balloon_show(range(3))
+      call balloon_show([])
     endif
   endif
 endfunc
@@ -2213,6 +2219,9 @@ func Test_range()
   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()
index 03724206411fe55deeb57cda7552f25ab53df994..c1fa45e7a5fe3209de138ed396d8c7de2de1421c 100644 (file)
@@ -207,6 +207,11 @@ func Test_listener_args()
 
   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)
index cd8ae2eb5692099b55843edcca6da191ab256d1a..fca646d6a7fe9e1890080bb283c7fdb03fc6890c 100644 (file)
@@ -163,6 +163,7 @@ func Test_matchadd_error()
   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,6 +279,8 @@ func Test_matchaddpos_error()
   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,5 +337,4 @@ func Test_matchadd_other_window()
   call delete('XscriptMatchCommon')
 endfunc
 
-
 " vim: shiftwidth=2 sts=2 expandtab
index 85d54f0833b72a89b19f08141efdb76d7f330b21..4fd28287548c05af5ec014144f74386cf6a32bf5 100644 (file)
@@ -255,6 +255,7 @@ func Test_menu_info()
   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
index cfd9a35b7d32383ca747f41cafe73cad8b77b449..71a0f15ba9c11ae755b0649e03b4893cbd7d85cd 100644 (file)
@@ -1488,6 +1488,7 @@ func SetXlistTests(cchar, bnum)
              \ " {'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()
index 7e7bc07b22ad5b1e9fd2bfcee43740b3df712a56..f774153a916067b5e8a0b9ab605111e5cf885dc7 100644 (file)
@@ -259,6 +259,8 @@ func Test_get_register()
   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
 
index e25c3cede4a9844c32a6a62eff25f09b9ef53c1a..f4ce5de1181ca0e332af73c49b82c7650eb3e7f5 100644 (file)
@@ -23,4 +23,9 @@ func Test_reltime()
   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
index 549fdd16f7db9409b751c88b0193a154df19fd07..d682a1975daf914fb33798b7035585c0313c80b8 100644 (file)
@@ -2634,4 +2634,22 @@ func Test_term_and_startinsert()
   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
index 692b0c4bd01ef2427189ebeb69b0d24d90a23239..f91597ff5108e144cd8b01728d679f9054816574 100644 (file)
@@ -1204,3 +1204,28 @@ func Test_find_zerowidth_prop_sol()
   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
index 49278424545427c547ffbfe5c4921f6d453cbba8..e20bfa5f9eef30dd0685c717e955670c46797c31 100644 (file)
@@ -445,6 +445,7 @@ func Test_win_screenpos()
   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,6 +695,7 @@ func Test_relative_cursor_position_in_one_line_window()
 
   only!
   bwipe!
+  call assert_fails('call winrestview(test_null_dict())', 'E474:')
 endfunc
 
 func Test_relative_cursor_position_after_move_and_resize()
@@ -870,6 +872,10 @@ func Test_winnr()
   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,6 +896,7 @@ func Test_winrestview()
   call assert_equal(view, winsaveview())
 
   bwipe!
+  call assert_fails('call winrestview(test_null_dict())', 'E474:')
 endfunc
 
 func Test_win_splitmove()
@@ -920,6 +927,7 @@ func Test_win_splitmove()
   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:')
index 9c92faeea5f6718d88b959cf93b09f0f7ca1729d..20465ae74b8b84e078f8007abef6635bfc98f1f0 100644 (file)
@@ -91,6 +91,10 @@ func Test_win_getid()
   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,4 +134,8 @@ func Test_winlayout()
   let w2 = win_getid()
   call assert_equal(['leaf', w2], 2->winlayout())
   tabclose
+
+  call assert_equal([], winlayout(-1))
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 497fa0bc7f4fe8fd3277f934b39c2dce642984fe..58e438c891e483f448acc5e5f7c0321f89b8ed32 100644 (file)
@@ -207,6 +207,12 @@ func Test_saveas()
   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,6 +251,12 @@ func Test_write_errors()
   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
index e78fc73390debc3561808a0c0bd2bf645485d79d..8c4cc71b20559004a791154e87d418db99669d30 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    644,
 /**/
     643,
 /**/