summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-05-05 21:25:22 +0200
committerBram Moolenaar <Bram@vim.org>2020-05-05 21:25:22 +0200
commit015f4267f4a28627c1872042078a95be7e06c4dc (patch)
tree85ad516a7aea34258e90585eb2f21ced022811a7 /src
parentf9ab52e155dc13f59b654d754041fe78e17b9074 (diff)
downloadvim-git-015f4267f4a28627c1872042078a95be7e06c4dc.tar.gz
patch 8.2.0699: Vim9: not all errors testedv8.2.0699
Problem: Vim9: not all errors tested. Solution: Add test for deleted function. Bail out on first error.
Diffstat (limited to 'src')
-rw-r--r--src/testdir/test_vim9_expr.vim34
-rw-r--r--src/testdir/test_vim9_func.vim17
-rw-r--r--src/testdir/vim9.vim16
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c7
5 files changed, 50 insertions, 26 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index ef5c00ccd..68eb40d2e 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -759,11 +759,11 @@ def Test_expr7_list()
assert_equal(g:list_mixed, [1, 'b', false])
assert_equal('b', g:list_mixed[1])
- call CheckDefExecFailure("let x = g:anint[3]", 'E714:')
+ call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:')
- call CheckDefExecFailure("let x = g:list_mixed['xx']", 'E39:')
+ call CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E39:')
call CheckDefFailure(["let x = g:list_mixed[0"], 'E111:')
- call CheckDefExecFailure("let x = g:list_empty[3]", 'E684:')
+ call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
enddef
def Test_expr7_lambda()
@@ -792,8 +792,8 @@ def Test_expr7_dict()
call CheckDefFailure(["let x = #"], 'E1015:')
call CheckDefFailure(["let x += 1"], 'E1020:')
call CheckDefFailure(["let x = x + 1"], 'E1001:')
- call CheckDefExecFailure("let x = g:anint.member", 'E715:')
- call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
+ call CheckDefExecFailure(["let x = g:anint.member"], 'E715:')
+ call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:')
enddef
def Test_expr_member()
@@ -899,8 +899,8 @@ func Test_expr7_fails()
call CheckDefFailure(["let x = -'xx'"], "E1030:")
call CheckDefFailure(["let x = +'xx'"], "E1030:")
call CheckDefFailure(["let x = -0z12"], "E974:")
- call CheckDefExecFailure("let x = -[8]", "E39:")
- call CheckDefExecFailure("let x = -{'a': 1}", "E39:")
+ call CheckDefExecFailure(["let x = -[8]"], "E39:")
+ call CheckDefExecFailure(["let x = -{'a': 1}"], "E39:")
call CheckDefFailure(["let x = @"], "E1002:")
call CheckDefFailure(["let x = @<"], "E354:")
@@ -914,23 +914,23 @@ func Test_expr7_fails()
call CheckDefFailure(["let x = &notexist"], 'E113:')
call CheckDefFailure(["&grepprg = [343]"], 'E1013:')
- call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
- call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
+ call CheckDefExecFailure(["echo s:doesnt_exist"], 'E121:')
+ call CheckDefExecFailure(["echo g:doesnt_exist"], 'E121:')
call CheckDefFailure(["echo a:somevar"], 'E1075:')
call CheckDefFailure(["echo l:somevar"], 'E1075:')
call CheckDefFailure(["echo x:somevar"], 'E1075:')
- call CheckDefExecFailure("let x = +g:astring", 'E1030:')
- call CheckDefExecFailure("let x = +g:ablob", 'E974:')
- call CheckDefExecFailure("let x = +g:alist", 'E745:')
- call CheckDefExecFailure("let x = +g:adict", 'E728:')
+ call CheckDefExecFailure(["let x = +g:astring"], 'E1030:')
+ call CheckDefExecFailure(["let x = +g:ablob"], 'E974:')
+ call CheckDefExecFailure(["let x = +g:alist"], 'E745:')
+ call CheckDefExecFailure(["let x = +g:adict"], 'E728:')
call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:')
- call CheckDefExecFailure("[1, 2->len()", 'E492:')
- call CheckDefExecFailure("#{a: 1->len()", 'E488:')
- call CheckDefExecFailure("{'a': 1->len()", 'E492:')
+ call CheckDefExecFailure(["[1, 2->len()"], 'E492:')
+ call CheckDefExecFailure(["#{a: 1->len()"], 'E488:')
+ call CheckDefExecFailure(["{'a': 1->len()"], 'E492:')
endfunc
let g:Funcrefs = [function('add')]
@@ -986,7 +986,7 @@ func Test_expr_fails()
call CheckDefFailure(["let x = '1'is2"], 'E488:')
call CheckDefFailure(["let x = '1'isnot2"], 'E488:')
- call CheckDefExecFailure("CallMe ('yes')", 'E492:')
+ call CheckDefExecFailure(["CallMe ('yes')"], 'E492:')
call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:')
call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 840c22048..49dc2f2f2 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -642,6 +642,23 @@ func Test_E1056_1059()
call assert_equal(1, caught_1059)
endfunc
+func DelMe()
+ echo 'DelMe'
+endfunc
+
+def Test_deleted_function()
+ CheckDefExecFailure([
+ 'let RefMe: func = function("g:DelMe")',
+ 'delfunc g:DelMe',
+ 'echo RefMe()'], 'E117:')
+enddef
+
+def Test_unknown_function()
+ CheckDefExecFailure([
+ 'let Ref: func = function("NotExist")',
+ 'delfunc g:NotExist'], 'E700:')
+enddef
+
def RefFunc(Ref: func(string): string): string
return Ref('more')
enddef
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim
index 0e0cd1e1f..0c16576c6 100644
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -7,6 +7,14 @@ func CheckDefFailure(lines, error)
call delete('Xdef')
endfunc
+" Check that "lines" inside ":def" results in an "error" message when executed.
+func CheckDefExecFailure(lines, error)
+ call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
+ so Xdef
+ call assert_fails('call Func()', a:error, a:lines)
+ call delete('Xdef')
+endfunc
+
def CheckScriptFailure(lines: list<string>, error: string)
writefile(lines, 'Xdef')
assert_fails('so Xdef', error, lines)
@@ -18,11 +26,3 @@ def CheckScriptSuccess(lines: list<string>)
so Xdef
delete('Xdef')
enddef
-
-" Check that "line" inside ":def" results in an "error" message when executed.
-func CheckDefExecFailure(line, error)
- call writefile(['def! Func()', a:line, 'enddef'], 'Xdef')
- so Xdef
- call assert_fails('call Func()', a:error, a:line)
- call delete('Xdef')
-endfunc
diff --git a/src/version.c b/src/version.c
index 213a41d28..61681882b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 699,
+/**/
698,
/**/
697,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 386b8491f..27ad04b44 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -432,6 +432,7 @@ call_bfunc(int func_idx, int argcount, ectx_T *ectx)
{
typval_T argvars[MAX_FUNC_ARGS];
int idx;
+ int called_emsg_before = called_emsg;
if (call_prepare(argcount, argvars, ectx) == FAIL)
return FAIL;
@@ -442,6 +443,9 @@ call_bfunc(int func_idx, int argcount, ectx_T *ectx)
// Clear the arguments.
for (idx = 0; idx < argcount; ++idx)
clear_tv(&argvars[idx]);
+
+ if (called_emsg != called_emsg_before)
+ return FAIL;
return OK;
}
@@ -549,7 +553,8 @@ call_partial(typval_T *tv, int argcount, ectx_T *ectx)
if (name == NULL || call_by_name(name, argcount, ectx, NULL) == FAIL)
{
if (called_emsg == called_emsg_before)
- semsg(_(e_unknownfunc), name);
+ semsg(_(e_unknownfunc),
+ name == NULL ? (char_u *)"[unknown]" : name);
return FAIL;
}
return OK;