Skip to content

Commit 631e8f9

Browse files
committed
patch 8.2.1953: Vim9: extra "unknown" error after other error
Problem: Vim9: extra "unknown" error after other error. Solution: Restore did_emsg count after EXEC instruction. (closes #7254) Improve error message from assert_fails()
1 parent c7f7f6d commit 631e8f9

5 files changed

Lines changed: 49 additions & 9 deletions

File tree

src/testdir/test_assert.vim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ func Test_assert_false()
66
call assert_equal(0, v:false->assert_false())
77

88
call assert_equal(1, assert_false(123))
9-
call assert_match("Expected False but got 123", v:errors[0])
9+
call assert_match("Expected 'False' but got 123", v:errors[0])
1010
call remove(v:errors, 0)
1111

1212
call assert_equal(1, 123->assert_false())
13-
call assert_match("Expected False but got 123", v:errors[0])
13+
call assert_match("Expected 'False' but got 123", v:errors[0])
1414
call remove(v:errors, 0)
1515
endfunc
1616

@@ -21,11 +21,11 @@ func Test_assert_true()
2121
call assert_equal(0, v:true->assert_true())
2222

2323
call assert_equal(1, assert_true(0))
24-
call assert_match("Expected True but got 0", v:errors[0])
24+
call assert_match("Expected 'True' but got 0", v:errors[0])
2525
call remove(v:errors, 0)
2626

2727
call assert_equal(1, 0->assert_true())
28-
call assert_match("Expected True but got 0", v:errors[0])
28+
call assert_match("Expected 'True' but got 0", v:errors[0])
2929
call remove(v:errors, 0)
3030
endfunc
3131

@@ -234,11 +234,11 @@ func Test_assert_fail_fails()
234234
call remove(v:errors, 0)
235235

236236
call assert_equal(1, assert_fails('xxx', ['E9876']))
237-
call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0])
237+
call assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
238238
call remove(v:errors, 0)
239239

240240
call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876']))
241-
call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0])
241+
call assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
242242
call remove(v:errors, 0)
243243

244244
call assert_equal(1, assert_fails('echo', '', 'echo command'))

src/testdir/test_vim9_script.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,28 @@ def Test_catch_exception_in_callback()
28592859
unlet g:caught
28602860
enddef
28612861

2862+
def Test_no_unknown_error_after_error()
2863+
if !has('unix') || !has('job')
2864+
throw 'Skipped: not unix of missing +job feature'
2865+
endif
2866+
var lines =<< trim END
2867+
vim9script
2868+
var source: list<number>
2869+
def Out_cb(...l: any)
2870+
eval [][0]
2871+
enddef
2872+
def Exit_cb(...l: any)
2873+
sleep 1m
2874+
source += l
2875+
enddef
2876+
var myjob = job_start('echo burp', #{out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'})
2877+
sleep 100m
2878+
END
2879+
writefile(lines, 'Xdef')
2880+
assert_fails('so Xdef', ['E684:', 'E1012:'])
2881+
delete('Xdef')
2882+
enddef
2883+
28622884
def Test_put_with_linebreak()
28632885
new
28642886
var lines =<< trim END

src/testing.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ fill_assert_error(
220220
vim_free(tofree);
221221
}
222222
else
223+
{
224+
ga_concat(gap, (char_u *)"'");
223225
ga_concat_shorten_esc(gap, exp_str);
226+
ga_concat(gap, (char_u *)"'");
227+
}
224228
if (atype != ASSERT_NOTEQUAL)
225229
{
226230
if (atype == ASSERT_MATCH)
@@ -571,6 +575,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
571575
{
572576
char_u buf[NUMBUFLEN];
573577
char_u *expected;
578+
char_u *expected_str = NULL;
574579
int error_found = FALSE;
575580
int error_found_index = 1;
576581
char_u *actual = emsg_assert_fails_msg == NULL ? (char_u *)"[unknown]"
@@ -598,14 +603,18 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
598603
if (!pattern_match(expected, actual, FALSE))
599604
{
600605
error_found = TRUE;
606+
expected_str = expected;
601607
}
602608
else if (list->lv_len == 2)
603609
{
604610
tv = &list->lv_u.mat.lv_last->li_tv;
605611
actual = get_vim_var_str(VV_ERRMSG);
606612
expected = tv_get_string_buf_chk(tv, buf);
607613
if (!pattern_match(expected, actual, FALSE))
614+
{
608615
error_found = TRUE;
616+
expected_str = expected;
617+
}
609618
}
610619
}
611620
else
@@ -665,7 +674,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
665674
actual_tv.v_type = VAR_STRING;
666675
actual_tv.vval.v_string = actual;
667676
}
668-
fill_assert_error(&ga, &argvars[2], NULL,
677+
fill_assert_error(&ga, &argvars[2], expected_str,
669678
&argvars[error_found_index], &actual_tv, ASSERT_OTHER);
670679
ga_concat(&ga, (char_u *)": ");
671680
assert_append_cmd_or_arg(&ga, argvars, cmd);

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+
1953,
753755
/**/
754756
1952,
755757
/**/

src/vim9execute.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,15 @@ call_def_function(
10711071
{
10721072
// execute Ex command line
10731073
case ISN_EXEC:
1074-
SOURCING_LNUM = iptr->isn_lnum;
1075-
do_cmdline_cmd(iptr->isn_arg.string);
1074+
{
1075+
int save_did_emsg = did_emsg;
1076+
1077+
SOURCING_LNUM = iptr->isn_lnum;
1078+
do_cmdline_cmd(iptr->isn_arg.string);
1079+
// do_cmdline_cmd() will reset did_emsg, but we want to
1080+
// keep track of the count to compare with did_emsg_before.
1081+
did_emsg += save_did_emsg;
1082+
}
10761083
break;
10771084

10781085
// execute Ex command from pieces on the stack

0 commit comments

Comments
 (0)