forked from aniani/vim
patch 8.2.4602: Vim9: not enough test coverage for executing :def function
Problem: Vim9: not enough test coverage for executing :def function. Solution: Add a few more tests. Fix uncovered problem. Remove dead code.
This commit is contained in:
parent
efd73ae5d2
commit
397a87ac1c
@ -19,8 +19,8 @@ int generate_PUSHBOOL(cctx_T *cctx, varnumber_T number);
|
|||||||
int generate_PUSHSPEC(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_PUSHF(cctx_T *cctx, float_T fnumber);
|
||||||
int generate_PUSHS(cctx_T *cctx, char_u **str);
|
int generate_PUSHS(cctx_T *cctx, char_u **str);
|
||||||
int generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel);
|
int generate_PUSHCHANNEL(cctx_T *cctx);
|
||||||
int generate_PUSHJOB(cctx_T *cctx, job_T *job);
|
int generate_PUSHJOB(cctx_T *cctx);
|
||||||
int generate_PUSHBLOB(cctx_T *cctx, blob_T *blob);
|
int generate_PUSHBLOB(cctx_T *cctx, blob_T *blob);
|
||||||
int generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type);
|
int generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type);
|
||||||
int generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type);
|
int generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type);
|
||||||
|
@ -3312,6 +3312,29 @@ def Test_expr8_call_global()
|
|||||||
v9.CheckDefAndScriptFailure(lines, 'E117: Unknown function: ExistingGlobal')
|
v9.CheckDefAndScriptFailure(lines, 'E117: Unknown function: ExistingGlobal')
|
||||||
enddef
|
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()
|
def Test_expr8_call_autoload()
|
||||||
var auto_lines =<< trim END
|
var auto_lines =<< trim END
|
||||||
def g:some#func(): string
|
def g:some#func(): string
|
||||||
|
@ -1246,6 +1246,37 @@ def Test_cexpr_vimscript()
|
|||||||
assert_equal(19, getqflist()[0].lnum)
|
assert_equal(19, getqflist()[0].lnum)
|
||||||
END
|
END
|
||||||
v9.CheckScriptSuccess(lines)
|
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&
|
set errorformat&
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
@ -1813,6 +1844,10 @@ def Test_echo_cmd()
|
|||||||
echo str1 str2
|
echo str1 str2
|
||||||
assert_match('^some more$', g:Screenline(&lines))
|
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:')
|
v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4602,
|
||||||
/**/
|
/**/
|
||||||
4601,
|
4601,
|
||||||
/**/
|
/**/
|
||||||
|
@ -87,8 +87,8 @@ typedef enum {
|
|||||||
ISN_PUSHS, // push string isn_arg.string
|
ISN_PUSHS, // push string isn_arg.string
|
||||||
ISN_PUSHBLOB, // push blob isn_arg.blob
|
ISN_PUSHBLOB, // push blob isn_arg.blob
|
||||||
ISN_PUSHFUNC, // push func isn_arg.string
|
ISN_PUSHFUNC, // push func isn_arg.string
|
||||||
ISN_PUSHCHANNEL, // push channel isn_arg.channel
|
ISN_PUSHCHANNEL, // push NULL channel
|
||||||
ISN_PUSHJOB, // push channel isn_arg.job
|
ISN_PUSHJOB, // push NULL job
|
||||||
ISN_NEWLIST, // push list from stack items, size is isn_arg.number
|
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_NEWDICT, // push dict from stack items, size is isn_arg.number
|
||||||
ISN_NEWPARTIAL, // push NULL partial
|
ISN_NEWPARTIAL, // push NULL partial
|
||||||
|
@ -2238,10 +2238,10 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
generate_NEWDICT(cctx, 0);
|
generate_NEWDICT(cctx, 0);
|
||||||
break;
|
break;
|
||||||
case VAR_JOB:
|
case VAR_JOB:
|
||||||
generate_PUSHJOB(cctx, NULL);
|
generate_PUSHJOB(cctx);
|
||||||
break;
|
break;
|
||||||
case VAR_CHANNEL:
|
case VAR_CHANNEL:
|
||||||
generate_PUSHCHANNEL(cctx, NULL);
|
generate_PUSHCHANNEL(cctx);
|
||||||
break;
|
break;
|
||||||
case VAR_NUMBER:
|
case VAR_NUMBER:
|
||||||
case VAR_UNKNOWN:
|
case VAR_UNKNOWN:
|
||||||
|
@ -2611,8 +2611,10 @@ exec_instructions(ectx_T *ectx)
|
|||||||
|
|
||||||
case ISN_CEXPR_AUCMD:
|
case ISN_CEXPR_AUCMD:
|
||||||
#ifdef FEAT_QUICKFIX
|
#ifdef FEAT_QUICKFIX
|
||||||
|
force_abort = TRUE;
|
||||||
if (trigger_cexpr_autocmd(iptr->isn_arg.number) == FAIL)
|
if (trigger_cexpr_autocmd(iptr->isn_arg.number) == FAIL)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
force_abort = FALSE;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3040,7 +3042,9 @@ exec_instructions(ectx_T *ectx)
|
|||||||
s = tv2string(tv, &tofree, numbuf, 0);
|
s = tv2string(tv, &tofree, numbuf, 0);
|
||||||
if (s == NULL || *s == NUL)
|
if (s == NULL || *s == NUL)
|
||||||
{
|
{
|
||||||
|
// cannot happen?
|
||||||
clear_tv(tv);
|
clear_tv(tv);
|
||||||
|
vim_free(tofree);
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3270,17 +3274,13 @@ exec_instructions(ectx_T *ectx)
|
|||||||
case ISN_PUSHCHANNEL:
|
case ISN_PUSHCHANNEL:
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
tv->v_type = VAR_CHANNEL;
|
tv->v_type = VAR_CHANNEL;
|
||||||
tv->vval.v_channel = iptr->isn_arg.channel;
|
tv->vval.v_channel = NULL;
|
||||||
if (tv->vval.v_channel != NULL)
|
|
||||||
++tv->vval.v_channel->ch_refcount;
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case ISN_PUSHJOB:
|
case ISN_PUSHJOB:
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
tv->v_type = VAR_JOB;
|
tv->v_type = VAR_JOB;
|
||||||
tv->vval.v_job = iptr->isn_arg.job;
|
tv->vval.v_job = NULL;
|
||||||
if (tv->vval.v_job != NULL)
|
|
||||||
++tv->vval.v_job->jv_refcount;
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -5644,26 +5644,12 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
|
|||||||
break;
|
break;
|
||||||
case ISN_PUSHCHANNEL:
|
case ISN_PUSHCHANNEL:
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
{
|
smsg("%s%4d PUSHCHANNEL 0", pfx, current);
|
||||||
channel_T *channel = iptr->isn_arg.channel;
|
|
||||||
|
|
||||||
smsg("%s%4d PUSHCHANNEL %d", pfx, current,
|
|
||||||
channel == NULL ? 0 : channel->ch_id);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case ISN_PUSHJOB:
|
case ISN_PUSHJOB:
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
{
|
smsg("%s%4d PUSHJOB \"no process\"", pfx, current);
|
||||||
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);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case ISN_PUSHEXC:
|
case ISN_PUSHEXC:
|
||||||
|
@ -592,12 +592,12 @@ generate_tv_PUSH(cctx_T *cctx, typval_T *tv)
|
|||||||
case VAR_JOB:
|
case VAR_JOB:
|
||||||
if (tv->vval.v_job != NULL)
|
if (tv->vval.v_job != NULL)
|
||||||
iemsg("non-null job constant not supported");
|
iemsg("non-null job constant not supported");
|
||||||
generate_PUSHJOB(cctx, NULL);
|
generate_PUSHJOB(cctx);
|
||||||
break;
|
break;
|
||||||
case VAR_CHANNEL:
|
case VAR_CHANNEL:
|
||||||
if (tv->vval.v_channel != NULL)
|
if (tv->vval.v_channel != NULL)
|
||||||
iemsg("non-null channel constant not supported");
|
iemsg("non-null channel constant not supported");
|
||||||
generate_PUSHCHANNEL(cctx, NULL);
|
generate_PUSHCHANNEL(cctx);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case VAR_FUNC:
|
case VAR_FUNC:
|
||||||
@ -723,36 +723,30 @@ generate_PUSHS(cctx_T *cctx, char_u **str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate an ISN_PUSHCHANNEL instruction.
|
* Generate an ISN_PUSHCHANNEL instruction. Channel is always NULL.
|
||||||
* Consumes "channel".
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel)
|
generate_PUSHCHANNEL(cctx_T *cctx)
|
||||||
{
|
{
|
||||||
isn_T *isn;
|
isn_T *isn;
|
||||||
|
|
||||||
RETURN_OK_IF_SKIP(cctx);
|
RETURN_OK_IF_SKIP(cctx);
|
||||||
if ((isn = generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel)) == NULL)
|
if ((isn = generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel)) == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
isn->isn_arg.channel = channel;
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate an ISN_PUSHJOB instruction.
|
* Generate an ISN_PUSHJOB instruction. Job is always NULL.
|
||||||
* Consumes "job".
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
generate_PUSHJOB(cctx_T *cctx, job_T *job)
|
generate_PUSHJOB(cctx_T *cctx)
|
||||||
{
|
{
|
||||||
isn_T *isn;
|
isn_T *isn;
|
||||||
|
|
||||||
RETURN_OK_IF_SKIP(cctx);
|
RETURN_OK_IF_SKIP(cctx);
|
||||||
if ((isn = generate_instr_type(cctx, ISN_PUSHJOB, &t_job)) == NULL)
|
if ((isn = generate_instr_type(cctx, ISN_PUSHJOB, &t_job)) == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
isn->isn_arg.job = job;
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2081,18 +2075,6 @@ delete_instr(isn_T *isn)
|
|||||||
blob_unref(isn->isn_arg.blob);
|
blob_unref(isn->isn_arg.blob);
|
||||||
break;
|
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:
|
case ISN_UCALL:
|
||||||
vim_free(isn->isn_arg.ufunc.cuf_name);
|
vim_free(isn->isn_arg.ufunc.cuf_name);
|
||||||
break;
|
break;
|
||||||
@ -2241,7 +2223,9 @@ delete_instr(isn_T *isn)
|
|||||||
case ISN_PROF_END:
|
case ISN_PROF_END:
|
||||||
case ISN_PROF_START:
|
case ISN_PROF_START:
|
||||||
case ISN_PUSHBOOL:
|
case ISN_PUSHBOOL:
|
||||||
|
case ISN_PUSHCHANNEL:
|
||||||
case ISN_PUSHF:
|
case ISN_PUSHF:
|
||||||
|
case ISN_PUSHJOB:
|
||||||
case ISN_PUSHNR:
|
case ISN_PUSHNR:
|
||||||
case ISN_PUSHSPEC:
|
case ISN_PUSHSPEC:
|
||||||
case ISN_PUT:
|
case ISN_PUT:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user