patch 8.2.0644: insufficient testing for invalid function arguments

Problem:    Insufficient testing for invalid function arguments.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #5988)
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index e01aad3..02ed78b 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -8641,8 +8641,8 @@
 			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
diff --git a/src/testdir/test_bufline.vim b/src/testdir/test_bufline.vim
index d359f20..3326e7d 100644
--- a/src/testdir/test_bufline.vim
+++ b/src/testdir/test_bufline.vim
@@ -37,6 +37,7 @@
   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
 
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 4ba552b..4a438ea 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -869,8 +869,10 @@
   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 @@
 
   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))
diff --git a/src/testdir/test_clientserver.vim b/src/testdir/test_clientserver.vim
index 4a48aed..152a2e1 100644
--- a/src/testdir/test_clientserver.vim
+++ b/src/testdir/test_clientserver.vim
@@ -164,6 +164,7 @@
     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:')
diff --git a/src/testdir/test_expr.vim b/src/testdir/test_expr.vim
index 5fc502d..ec73aea 100644
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -471,6 +471,7 @@
   endif
   eval set->setmatches()
   call assert_equal(exp, getmatches())
+  call assert_fails('let m = setmatches([], [])', 'E957:')
 endfunc
 
 func Test_empty_concatenate()
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index a0807ad..02b6585 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -29,6 +29,8 @@
     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 @@
 
 " 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 @@
     call balloon_show('hi!')
     if !has('gui_running')
       call balloon_show(range(3))
+      call balloon_show([])
     endif
   endif
 endfunc
@@ -2213,6 +2219,9 @@
   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()
diff --git a/src/testdir/test_listener.vim b/src/testdir/test_listener.vim
index 0372420..c1fa45e 100644
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -207,6 +207,11 @@
 
   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)
diff --git a/src/testdir/test_match.vim b/src/testdir/test_match.vim
index cd8ae2e..fca646d 100644
--- a/src/testdir/test_match.vim
+++ b/src/testdir/test_match.vim
@@ -163,6 +163,7 @@
   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 @@
   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 @@
   call delete('XscriptMatchCommon')
 endfunc
 
-
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_menu.vim b/src/testdir/test_menu.vim
index 85d54f0..4fd2828 100644
--- a/src/testdir/test_menu.vim
+++ b/src/testdir/test_menu.vim
@@ -255,6 +255,7 @@
   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
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index cfd9a35..71a0f15 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -1488,6 +1488,7 @@
 	      \ " {'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()
diff --git a/src/testdir/test_registers.vim b/src/testdir/test_registers.vim
index 7e7bc07..f774153 100644
--- a/src/testdir/test_registers.vim
+++ b/src/testdir/test_registers.vim
@@ -259,6 +259,8 @@
   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
 
diff --git a/src/testdir/test_reltime.vim b/src/testdir/test_reltime.vim
index e25c3ce..f4ce5de 100644
--- a/src/testdir/test_reltime.vim
+++ b/src/testdir/test_reltime.vim
@@ -23,4 +23,9 @@
   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
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 549fdd1..d682a19 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -2634,4 +2634,22 @@
   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
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 692b0c4..f91597f 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -1204,3 +1204,28 @@
   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
diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim
index 4927842..e20bfa5 100644
--- a/src/testdir/test_window_cmd.vim
+++ b/src/testdir/test_window_cmd.vim
@@ -445,6 +445,7 @@
   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 @@
 
   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 @@
   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 @@
   call assert_equal(view, winsaveview())
 
   bwipe!
+  call assert_fails('call winrestview(test_null_dict())', 'E474:')
 endfunc
 
 func Test_win_splitmove()
@@ -920,6 +927,7 @@
   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:')
diff --git a/src/testdir/test_window_id.vim b/src/testdir/test_window_id.vim
index 9c92fae..20465ae 100644
--- a/src/testdir/test_window_id.vim
+++ b/src/testdir/test_window_id.vim
@@ -91,6 +91,10 @@
   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 @@
   let w2 = win_getid()
   call assert_equal(['leaf', w2], 2->winlayout())
   tabclose
+
+  call assert_equal([], winlayout(-1))
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_writefile.vim b/src/testdir/test_writefile.vim
index 497fa0b..58e438c 100644
--- a/src/testdir/test_writefile.vim
+++ b/src/testdir/test_writefile.vim
@@ -207,6 +207,12 @@
   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 @@
   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
diff --git a/src/version.c b/src/version.c
index e78fc73..8c4cc71 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    644,
+/**/
     643,
 /**/
     642,