Patch 8.2.1953
Problem: Vim9: extra "unknown" error after other error.
Solution: Restore did_emsg count after EXEC instruction. (closes #7254)
Improve error message from assert_fails()
Files: src/vim9execute.c, src/testing.c,
src/testdir/test_vim9_script.vim, src/testdir/test_assert.vim
*** ../vim-8.2.1952/src/vim9execute.c 2020-11-04 13:38:24.297472668 +0100
--- src/vim9execute.c 2020-11-04 14:50:48.842494468 +0100
***************
*** 1071,1078 ****
{
// execute Ex command line
case ISN_EXEC:
! SOURCING_LNUM = iptr->isn_lnum;
! do_cmdline_cmd(iptr->isn_arg.string);
break;
// execute Ex command from pieces on the stack
--- 1071,1085 ----
{
// execute Ex command line
case ISN_EXEC:
! {
! int save_did_emsg = did_emsg;
!
! SOURCING_LNUM = iptr->isn_lnum;
! do_cmdline_cmd(iptr->isn_arg.string);
! // do_cmdline_cmd() will reset did_emsg, but we want to
! // keep track of the count to compare with did_emsg_before.
! did_emsg += save_did_emsg;
! }
break;
// execute Ex command from pieces on the stack
*** ../vim-8.2.1952/src/testing.c 2020-10-28 20:19:56.368057090 +0100
--- src/testing.c 2020-11-04 14:55:49.297724460 +0100
***************
*** 220,226 ****
--- 220,230 ----
vim_free(tofree);
}
else
+ {
+ ga_concat(gap, (char_u *)"'");
ga_concat_shorten_esc(gap, exp_str);
+ ga_concat(gap, (char_u *)"'");
+ }
if (atype != ASSERT_NOTEQUAL)
{
if (atype == ASSERT_MATCH)
***************
*** 571,576 ****
--- 575,581 ----
{
char_u buf[NUMBUFLEN];
char_u *expected;
+ char_u *expected_str = NULL;
int error_found = FALSE;
int error_found_index = 1;
char_u *actual = emsg_assert_fails_msg == NULL ? (char_u *)"[unknown]"
***************
*** 598,603 ****
--- 603,609 ----
if (!pattern_match(expected, actual, FALSE))
{
error_found = TRUE;
+ expected_str = expected;
}
else if (list->lv_len == 2)
{
***************
*** 605,611 ****
--- 611,620 ----
actual = get_vim_var_str(VV_ERRMSG);
expected = tv_get_string_buf_chk(tv, buf);
if (!pattern_match(expected, actual, FALSE))
+ {
error_found = TRUE;
+ expected_str = expected;
+ }
}
}
else
***************
*** 665,671 ****
actual_tv.v_type = VAR_STRING;
actual_tv.vval.v_string = actual;
}
! fill_assert_error(&ga, &argvars[2], NULL,
&argvars[error_found_index], &actual_tv, ASSERT_OTHER);
ga_concat(&ga, (char_u *)": ");
assert_append_cmd_or_arg(&ga, argvars, cmd);
--- 674,680 ----
actual_tv.v_type = VAR_STRING;
actual_tv.vval.v_string = actual;
}
! fill_assert_error(&ga, &argvars[2], expected_str,
&argvars[error_found_index], &actual_tv, ASSERT_OTHER);
ga_concat(&ga, (char_u *)": ");
assert_append_cmd_or_arg(&ga, argvars, cmd);
*** ../vim-8.2.1952/src/testdir/test_vim9_script.vim 2020-10-28 13:53:46.553128946 +0100
--- src/testdir/test_vim9_script.vim 2020-11-04 14:43:37.731598717 +0100
***************
*** 2859,2864 ****
--- 2859,2886 ----
unlet g:caught
enddef
+ def Test_no_unknown_error_after_error()
+ if !has('unix') || !has('job')
+ throw 'Skipped: not unix of missing +job feature'
+ endif
+ var lines =<< trim END
+ vim9script
+ var source: list<number>
+ def Out_cb(...l: any)
+ eval [][0]
+ enddef
+ def Exit_cb(...l: any)
+ sleep 1m
+ source += l
+ enddef
+ var myjob = job_start('echo burp', #{out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'})
+ sleep 100m
+ END
+ writefile(lines, 'Xdef')
+ assert_fails('so Xdef', ['E684:', 'E1012:'])
+ delete('Xdef')
+ enddef
+
def Test_put_with_linebreak()
new
var lines =<< trim END
*** ../vim-8.2.1952/src/testdir/test_assert.vim 2020-09-16 17:55:36.537602345 +0200
--- src/testdir/test_assert.vim 2020-11-04 15:02:30.511513587 +0100
***************
*** 6,16 ****
call assert_equal(0, v:false->assert_false())
call assert_equal(1, assert_false(123))
! call assert_match("Expected False but got 123", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, 123->assert_false())
! call assert_match("Expected False but got 123", v:errors[0])
call remove(v:errors, 0)
endfunc
--- 6,16 ----
call assert_equal(0, v:false->assert_false())
call assert_equal(1, assert_false(123))
! call assert_match("Expected 'False' but got 123", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, 123->assert_false())
! call assert_match("Expected 'False' but got 123", v:errors[0])
call remove(v:errors, 0)
endfunc
***************
*** 21,31 ****
call assert_equal(0, v:true->assert_true())
call assert_equal(1, assert_true(0))
! call assert_match("Expected True but got 0", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, 0->assert_true())
! call assert_match("Expected True but got 0", v:errors[0])
call remove(v:errors, 0)
endfunc
--- 21,31 ----
call assert_equal(0, v:true->assert_true())
call assert_equal(1, assert_true(0))
! call assert_match("Expected 'True' but got 0", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, 0->assert_true())
! call assert_match("Expected 'True' but got 0", v:errors[0])
call remove(v:errors, 0)
endfunc
***************
*** 234,244 ****
call remove(v:errors, 0)
call assert_equal(1, assert_fails('xxx', ['E9876']))
! call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876']))
! call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, assert_fails('echo', '', 'echo command'))
--- 234,244 ----
call remove(v:errors, 0)
call assert_equal(1, assert_fails('xxx', ['E9876']))
! call assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876']))
! call assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, assert_fails('echo', '', 'echo command'))
*** ../vim-8.2.1952/src/version.c 2020-11-04 13:38:24.297472668 +0100
--- src/version.c 2020-11-04 14:37:44.896502304 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1953,
/**/
--
Press any key to continue, press any other key to quit.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///