Skip to content

Commit 397a87a

Browse files
committed
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.
1 parent efd73ae commit 397a87a

File tree

8 files changed

+82
-52
lines changed

8 files changed

+82
-52
lines changed

src/proto/vim9instr.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ int generate_PUSHBOOL(cctx_T *cctx, varnumber_T number);
1919
int generate_PUSHSPEC(cctx_T *cctx, varnumber_T number);
2020
int generate_PUSHF(cctx_T *cctx, float_T fnumber);
2121
int generate_PUSHS(cctx_T *cctx, char_u **str);
22-
int generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel);
23-
int generate_PUSHJOB(cctx_T *cctx, job_T *job);
22+
int generate_PUSHCHANNEL(cctx_T *cctx);
23+
int generate_PUSHJOB(cctx_T *cctx);
2424
int generate_PUSHBLOB(cctx_T *cctx, blob_T *blob);
2525
int generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type);
2626
int generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type);

src/testdir/test_vim9_expr.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,29 @@ def Test_expr8_call_global()
33123312
v9.CheckDefAndScriptFailure(lines, 'E117: Unknown function: ExistingGlobal')
33133313
enddef
33143314

3315+
def Test_expr8_autoload_var()
3316+
var auto_lines =<< trim END
3317+
let autofile#var = 'found'
3318+
END
3319+
mkdir('Xruntime/autoload', 'p')
3320+
writefile(auto_lines, 'Xruntime/autoload/autofile.vim')
3321+
var save_rtp = &rtp
3322+
&rtp = getcwd() .. '/Xruntime,' .. &rtp
3323+
3324+
var lines =<< trim END
3325+
assert_equal('found', autofile#var)
3326+
END
3327+
v9.CheckDefAndScriptSuccess(lines)
3328+
3329+
lines =<< trim END
3330+
echo autofile#other
3331+
END
3332+
v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: autofile#other')
3333+
3334+
&rtp = save_rtp
3335+
delete('Xruntime', 'rf')
3336+
enddef
3337+
33153338
def Test_expr8_call_autoload()
33163339
var auto_lines =<< trim END
33173340
def g:some#func(): string

src/testdir/test_vim9_script.vim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,37 @@ def Test_cexpr_vimscript()
12461246
assert_equal(19, getqflist()[0].lnum)
12471247
END
12481248
v9.CheckScriptSuccess(lines)
1249+
1250+
lines =<< trim END
1251+
vim9script
1252+
def CexprFail()
1253+
au QuickfixCmdPre * echo g:doesnotexist
1254+
cexpr 'File otherFile line 99'
1255+
g:didContinue = 'yes'
1256+
enddef
1257+
CexprFail()
1258+
g:didContinue = 'also'
1259+
END
1260+
g:didContinue = 'no'
1261+
v9.CheckScriptFailure(lines, 'E121: Undefined variable: g:doesnotexist')
1262+
assert_equal('no', g:didContinue)
1263+
au! QuickfixCmdPre
1264+
1265+
lines =<< trim END
1266+
vim9script
1267+
def CexprFail()
1268+
cexpr g:aNumber
1269+
g:didContinue = 'yes'
1270+
enddef
1271+
CexprFail()
1272+
g:didContinue = 'also'
1273+
END
1274+
g:aNumber = 123
1275+
g:didContinue = 'no'
1276+
v9.CheckScriptFailure(lines, 'E777: String or List expected')
1277+
assert_equal('no', g:didContinue)
1278+
unlet g:didContinue
1279+
12491280
set errorformat&
12501281
enddef
12511282

@@ -1813,6 +1844,10 @@ def Test_echo_cmd()
18131844
echo str1 str2
18141845
assert_match('^some more$', g:Screenline(&lines))
18151846

1847+
echo "one\ntwo"
1848+
assert_match('^one$', g:Screenline(&lines - 1))
1849+
assert_match('^two$', g:Screenline(&lines))
1850+
18161851
v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:')
18171852
enddef
18181853

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
4602,
753755
/**/
754756
4601,
755757
/**/

src/vim9.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ typedef enum {
8787
ISN_PUSHS, // push string isn_arg.string
8888
ISN_PUSHBLOB, // push blob isn_arg.blob
8989
ISN_PUSHFUNC, // push func isn_arg.string
90-
ISN_PUSHCHANNEL, // push channel isn_arg.channel
91-
ISN_PUSHJOB, // push channel isn_arg.job
90+
ISN_PUSHCHANNEL, // push NULL channel
91+
ISN_PUSHJOB, // push NULL job
9292
ISN_NEWLIST, // push list from stack items, size is isn_arg.number
9393
ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
9494
ISN_NEWPARTIAL, // push NULL partial

src/vim9compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,10 +2238,10 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
22382238
generate_NEWDICT(cctx, 0);
22392239
break;
22402240
case VAR_JOB:
2241-
generate_PUSHJOB(cctx, NULL);
2241+
generate_PUSHJOB(cctx);
22422242
break;
22432243
case VAR_CHANNEL:
2244-
generate_PUSHCHANNEL(cctx, NULL);
2244+
generate_PUSHCHANNEL(cctx);
22452245
break;
22462246
case VAR_NUMBER:
22472247
case VAR_UNKNOWN:

src/vim9execute.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,8 +2611,10 @@ exec_instructions(ectx_T *ectx)
26112611

26122612
case ISN_CEXPR_AUCMD:
26132613
#ifdef FEAT_QUICKFIX
2614+
force_abort = TRUE;
26142615
if (trigger_cexpr_autocmd(iptr->isn_arg.number) == FAIL)
26152616
goto on_error;
2617+
force_abort = FALSE;
26162618
#endif
26172619
break;
26182620

@@ -3040,7 +3042,9 @@ exec_instructions(ectx_T *ectx)
30403042
s = tv2string(tv, &tofree, numbuf, 0);
30413043
if (s == NULL || *s == NUL)
30423044
{
3045+
// cannot happen?
30433046
clear_tv(tv);
3047+
vim_free(tofree);
30443048
goto on_error;
30453049
}
30463050
}
@@ -3270,17 +3274,13 @@ exec_instructions(ectx_T *ectx)
32703274
case ISN_PUSHCHANNEL:
32713275
#ifdef FEAT_JOB_CHANNEL
32723276
tv->v_type = VAR_CHANNEL;
3273-
tv->vval.v_channel = iptr->isn_arg.channel;
3274-
if (tv->vval.v_channel != NULL)
3275-
++tv->vval.v_channel->ch_refcount;
3277+
tv->vval.v_channel = NULL;
32763278
#endif
32773279
break;
32783280
case ISN_PUSHJOB:
32793281
#ifdef FEAT_JOB_CHANNEL
32803282
tv->v_type = VAR_JOB;
3281-
tv->vval.v_job = iptr->isn_arg.job;
3282-
if (tv->vval.v_job != NULL)
3283-
++tv->vval.v_job->jv_refcount;
3283+
tv->vval.v_job = NULL;
32843284
#endif
32853285
break;
32863286
default:
@@ -5644,26 +5644,12 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
56445644
break;
56455645
case ISN_PUSHCHANNEL:
56465646
#ifdef FEAT_JOB_CHANNEL
5647-
{
5648-
channel_T *channel = iptr->isn_arg.channel;
5649-
5650-
smsg("%s%4d PUSHCHANNEL %d", pfx, current,
5651-
channel == NULL ? 0 : channel->ch_id);
5652-
}
5647+
smsg("%s%4d PUSHCHANNEL 0", pfx, current);
56535648
#endif
56545649
break;
56555650
case ISN_PUSHJOB:
56565651
#ifdef FEAT_JOB_CHANNEL
5657-
{
5658-
typval_T tv;
5659-
char_u *name;
5660-
char_u buf[NUMBUFLEN];
5661-
5662-
tv.v_type = VAR_JOB;
5663-
tv.vval.v_job = iptr->isn_arg.job;
5664-
name = job_to_string_buf(&tv, buf);
5665-
smsg("%s%4d PUSHJOB \"%s\"", pfx, current, name);
5666-
}
5652+
smsg("%s%4d PUSHJOB \"no process\"", pfx, current);
56675653
#endif
56685654
break;
56695655
case ISN_PUSHEXC:

src/vim9instr.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,12 @@ generate_tv_PUSH(cctx_T *cctx, typval_T *tv)
592592
case VAR_JOB:
593593
if (tv->vval.v_job != NULL)
594594
iemsg("non-null job constant not supported");
595-
generate_PUSHJOB(cctx, NULL);
595+
generate_PUSHJOB(cctx);
596596
break;
597597
case VAR_CHANNEL:
598598
if (tv->vval.v_channel != NULL)
599599
iemsg("non-null channel constant not supported");
600-
generate_PUSHCHANNEL(cctx, NULL);
600+
generate_PUSHCHANNEL(cctx);
601601
break;
602602
#endif
603603
case VAR_FUNC:
@@ -723,36 +723,30 @@ generate_PUSHS(cctx_T *cctx, char_u **str)
723723
}
724724

725725
/*
726-
* Generate an ISN_PUSHCHANNEL instruction.
727-
* Consumes "channel".
726+
* Generate an ISN_PUSHCHANNEL instruction. Channel is always NULL.
728727
*/
729728
int
730-
generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel)
729+
generate_PUSHCHANNEL(cctx_T *cctx)
731730
{
732731
isn_T *isn;
733732

734733
RETURN_OK_IF_SKIP(cctx);
735734
if ((isn = generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel)) == NULL)
736735
return FAIL;
737-
isn->isn_arg.channel = channel;
738-
739736
return OK;
740737
}
741738

742739
/*
743-
* Generate an ISN_PUSHJOB instruction.
744-
* Consumes "job".
740+
* Generate an ISN_PUSHJOB instruction. Job is always NULL.
745741
*/
746742
int
747-
generate_PUSHJOB(cctx_T *cctx, job_T *job)
743+
generate_PUSHJOB(cctx_T *cctx)
748744
{
749745
isn_T *isn;
750746

751747
RETURN_OK_IF_SKIP(cctx);
752748
if ((isn = generate_instr_type(cctx, ISN_PUSHJOB, &t_job)) == NULL)
753749
return FAIL;
754-
isn->isn_arg.job = job;
755-
756750
return OK;
757751
}
758752

@@ -2081,18 +2075,6 @@ delete_instr(isn_T *isn)
20812075
blob_unref(isn->isn_arg.blob);
20822076
break;
20832077

2084-
case ISN_PUSHJOB:
2085-
#ifdef FEAT_JOB_CHANNEL
2086-
job_unref(isn->isn_arg.job);
2087-
#endif
2088-
break;
2089-
2090-
case ISN_PUSHCHANNEL:
2091-
#ifdef FEAT_JOB_CHANNEL
2092-
channel_unref(isn->isn_arg.channel);
2093-
#endif
2094-
break;
2095-
20962078
case ISN_UCALL:
20972079
vim_free(isn->isn_arg.ufunc.cuf_name);
20982080
break;
@@ -2241,7 +2223,9 @@ delete_instr(isn_T *isn)
22412223
case ISN_PROF_END:
22422224
case ISN_PROF_START:
22432225
case ISN_PUSHBOOL:
2226+
case ISN_PUSHCHANNEL:
22442227
case ISN_PUSHF:
2228+
case ISN_PUSHJOB:
22452229
case ISN_PUSHNR:
22462230
case ISN_PUSHSPEC:
22472231
case ISN_PUT:

0 commit comments

Comments
 (0)