summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-20 21:14:15 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-20 21:14:15 +0000
commit397a87ac1c9857eb0d5ec3add69e3b9ab6b0c77c (patch)
tree63860de699019af670a438af1145ff9bda9e795c /src
parentefd73ae5d2a533670f562b6df5be2ffeb091185d (diff)
downloadvim-git-397a87ac1c9857eb0d5ec3add69e3b9ab6b0c77c.tar.gz
patch 8.2.4602: Vim9: not enough test coverage for executing :def functionv8.2.4602
Problem: Vim9: not enough test coverage for executing :def function. Solution: Add a few more tests. Fix uncovered problem. Remove dead code.
Diffstat (limited to 'src')
-rw-r--r--src/proto/vim9instr.pro4
-rw-r--r--src/testdir/test_vim9_expr.vim23
-rw-r--r--src/testdir/test_vim9_script.vim35
-rw-r--r--src/version.c2
-rw-r--r--src/vim9.h4
-rw-r--r--src/vim9compile.c4
-rw-r--r--src/vim9execute.c30
-rw-r--r--src/vim9instr.c32
8 files changed, 82 insertions, 52 deletions
diff --git a/src/proto/vim9instr.pro b/src/proto/vim9instr.pro
index be41d7c04..8da559745 100644
--- a/src/proto/vim9instr.pro
+++ b/src/proto/vim9instr.pro
@@ -19,8 +19,8 @@ int generate_PUSHBOOL(cctx_T *cctx, varnumber_T number);
int generate_PUSHSPEC(cctx_T *cctx, varnumber_T number);
int generate_PUSHF(cctx_T *cctx, float_T fnumber);
int generate_PUSHS(cctx_T *cctx, char_u **str);
-int generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel);
-int generate_PUSHJOB(cctx_T *cctx, job_T *job);
+int generate_PUSHCHANNEL(cctx_T *cctx);
+int generate_PUSHJOB(cctx_T *cctx);
int generate_PUSHBLOB(cctx_T *cctx, blob_T *blob);
int generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type);
int generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type);
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 02ea54ada..dcce616de 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -3312,6 +3312,29 @@ def Test_expr8_call_global()
v9.CheckDefAndScriptFailure(lines, 'E117: Unknown function: ExistingGlobal')
enddef
+def Test_expr8_autoload_var()
+ var auto_lines =<< trim END
+ let autofile#var = 'found'
+ END
+ mkdir('Xruntime/autoload', 'p')
+ writefile(auto_lines, 'Xruntime/autoload/autofile.vim')
+ var save_rtp = &rtp
+ &rtp = getcwd() .. '/Xruntime,' .. &rtp
+
+ var lines =<< trim END
+ assert_equal('found', autofile#var)
+ END
+ v9.CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
+ echo autofile#other
+ END
+ v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: autofile#other')
+
+ &rtp = save_rtp
+ delete('Xruntime', 'rf')
+enddef
+
def Test_expr8_call_autoload()
var auto_lines =<< trim END
def g:some#func(): string
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 3e4e9a4ec..b1b63d2d6 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1246,6 +1246,37 @@ def Test_cexpr_vimscript()
assert_equal(19, getqflist()[0].lnum)
END
v9.CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ def CexprFail()
+ au QuickfixCmdPre * echo g:doesnotexist
+ cexpr 'File otherFile line 99'
+ g:didContinue = 'yes'
+ enddef
+ CexprFail()
+ g:didContinue = 'also'
+ END
+ g:didContinue = 'no'
+ v9.CheckScriptFailure(lines, 'E121: Undefined variable: g:doesnotexist')
+ assert_equal('no', g:didContinue)
+ au! QuickfixCmdPre
+
+ lines =<< trim END
+ vim9script
+ def CexprFail()
+ cexpr g:aNumber
+ g:didContinue = 'yes'
+ enddef
+ CexprFail()
+ g:didContinue = 'also'
+ END
+ g:aNumber = 123
+ g:didContinue = 'no'
+ v9.CheckScriptFailure(lines, 'E777: String or List expected')
+ assert_equal('no', g:didContinue)
+ unlet g:didContinue
+
set errorformat&
enddef
@@ -1813,6 +1844,10 @@ def Test_echo_cmd()
echo str1 str2
assert_match('^some more$', g:Screenline(&lines))
+ echo "one\ntwo"
+ assert_match('^one$', g:Screenline(&lines - 1))
+ assert_match('^two$', g:Screenline(&lines))
+
v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:')
enddef
diff --git a/src/version.c b/src/version.c
index 285b3914d..e262953d7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4602,
+/**/
4601,
/**/
4600,
diff --git a/src/vim9.h b/src/vim9.h
index 5fd852630..ed5f67695 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -87,8 +87,8 @@ typedef enum {
ISN_PUSHS, // push string isn_arg.string
ISN_PUSHBLOB, // push blob isn_arg.blob
ISN_PUSHFUNC, // push func isn_arg.string
- ISN_PUSHCHANNEL, // push channel isn_arg.channel
- ISN_PUSHJOB, // push channel isn_arg.job
+ ISN_PUSHCHANNEL, // push NULL channel
+ ISN_PUSHJOB, // push NULL job
ISN_NEWLIST, // push list from stack items, size is isn_arg.number
ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
ISN_NEWPARTIAL, // push NULL partial
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 06b6c79b9..fde818882 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2238,10 +2238,10 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
generate_NEWDICT(cctx, 0);
break;
case VAR_JOB:
- generate_PUSHJOB(cctx, NULL);
+ generate_PUSHJOB(cctx);
break;
case VAR_CHANNEL:
- generate_PUSHCHANNEL(cctx, NULL);
+ generate_PUSHCHANNEL(cctx);
break;
case VAR_NUMBER:
case VAR_UNKNOWN:
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 312c5fad0..2d6a3fead 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2611,8 +2611,10 @@ exec_instructions(ectx_T *ectx)
case ISN_CEXPR_AUCMD:
#ifdef FEAT_QUICKFIX
+ force_abort = TRUE;
if (trigger_cexpr_autocmd(iptr->isn_arg.number) == FAIL)
goto on_error;
+ force_abort = FALSE;
#endif
break;
@@ -3040,7 +3042,9 @@ exec_instructions(ectx_T *ectx)
s = tv2string(tv, &tofree, numbuf, 0);
if (s == NULL || *s == NUL)
{
+ // cannot happen?
clear_tv(tv);
+ vim_free(tofree);
goto on_error;
}
}
@@ -3270,17 +3274,13 @@ exec_instructions(ectx_T *ectx)
case ISN_PUSHCHANNEL:
#ifdef FEAT_JOB_CHANNEL
tv->v_type = VAR_CHANNEL;
- tv->vval.v_channel = iptr->isn_arg.channel;
- if (tv->vval.v_channel != NULL)
- ++tv->vval.v_channel->ch_refcount;
+ tv->vval.v_channel = NULL;
#endif
break;
case ISN_PUSHJOB:
#ifdef FEAT_JOB_CHANNEL
tv->v_type = VAR_JOB;
- tv->vval.v_job = iptr->isn_arg.job;
- if (tv->vval.v_job != NULL)
- ++tv->vval.v_job->jv_refcount;
+ tv->vval.v_job = NULL;
#endif
break;
default:
@@ -5644,26 +5644,12 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
break;
case ISN_PUSHCHANNEL:
#ifdef FEAT_JOB_CHANNEL
- {
- channel_T *channel = iptr->isn_arg.channel;
-
- smsg("%s%4d PUSHCHANNEL %d", pfx, current,
- channel == NULL ? 0 : channel->ch_id);
- }
+ smsg("%s%4d PUSHCHANNEL 0", pfx, current);
#endif
break;
case ISN_PUSHJOB:
#ifdef FEAT_JOB_CHANNEL
- {
- typval_T tv;
- char_u *name;
- char_u buf[NUMBUFLEN];
-
- tv.v_type = VAR_JOB;
- tv.vval.v_job = iptr->isn_arg.job;
- name = job_to_string_buf(&tv, buf);
- smsg("%s%4d PUSHJOB \"%s\"", pfx, current, name);
- }
+ smsg("%s%4d PUSHJOB \"no process\"", pfx, current);
#endif
break;
case ISN_PUSHEXC:
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 48e7edfed..7f23884f3 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -592,12 +592,12 @@ generate_tv_PUSH(cctx_T *cctx, typval_T *tv)
case VAR_JOB:
if (tv->vval.v_job != NULL)
iemsg("non-null job constant not supported");
- generate_PUSHJOB(cctx, NULL);
+ generate_PUSHJOB(cctx);
break;
case VAR_CHANNEL:
if (tv->vval.v_channel != NULL)
iemsg("non-null channel constant not supported");
- generate_PUSHCHANNEL(cctx, NULL);
+ generate_PUSHCHANNEL(cctx);
break;
#endif
case VAR_FUNC:
@@ -723,36 +723,30 @@ generate_PUSHS(cctx_T *cctx, char_u **str)
}
/*
- * Generate an ISN_PUSHCHANNEL instruction.
- * Consumes "channel".
+ * Generate an ISN_PUSHCHANNEL instruction. Channel is always NULL.
*/
int
-generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel)
+generate_PUSHCHANNEL(cctx_T *cctx)
{
isn_T *isn;
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel)) == NULL)
return FAIL;
- isn->isn_arg.channel = channel;
-
return OK;
}
/*
- * Generate an ISN_PUSHJOB instruction.
- * Consumes "job".
+ * Generate an ISN_PUSHJOB instruction. Job is always NULL.
*/
int
-generate_PUSHJOB(cctx_T *cctx, job_T *job)
+generate_PUSHJOB(cctx_T *cctx)
{
isn_T *isn;
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr_type(cctx, ISN_PUSHJOB, &t_job)) == NULL)
return FAIL;
- isn->isn_arg.job = job;
-
return OK;
}
@@ -2081,18 +2075,6 @@ delete_instr(isn_T *isn)
blob_unref(isn->isn_arg.blob);
break;
- case ISN_PUSHJOB:
-#ifdef FEAT_JOB_CHANNEL
- job_unref(isn->isn_arg.job);
-#endif
- break;
-
- case ISN_PUSHCHANNEL:
-#ifdef FEAT_JOB_CHANNEL
- channel_unref(isn->isn_arg.channel);
-#endif
- break;
-
case ISN_UCALL:
vim_free(isn->isn_arg.ufunc.cuf_name);
break;
@@ -2241,7 +2223,9 @@ delete_instr(isn_T *isn)
case ISN_PROF_END:
case ISN_PROF_START:
case ISN_PUSHBOOL:
+ case ISN_PUSHCHANNEL:
case ISN_PUSHF:
+ case ISN_PUSHJOB:
case ISN_PUSHNR:
case ISN_PUSHSPEC:
case ISN_PUT: