changeset 22810:2d05dd71aac3 v8.2.1953

patch 8.2.1953: Vim9: extra "unknown" error after other error Commit: https://github.com/vim/vim/commit/631e8f93458b102091d54c502f489c03e454d4da Author: Bram Moolenaar <Bram@vim.org> Date: Wed Nov 4 15:07:16 2020 +0100 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 https://github.com/vim/vim/issues/7254) Improve error message from assert_fails()
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Nov 2020 15:15:04 +0100
parents b736ff223ecc
children f2e4940ef271
files src/testdir/test_assert.vim src/testdir/test_vim9_script.vim src/testing.c src/version.c src/vim9execute.c
diffstat 5 files changed, 49 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_assert.vim
+++ b/src/testdir/test_assert.vim
@@ -6,11 +6,11 @@ func Test_assert_false()
   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 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 assert_match("Expected 'False' but got 123", v:errors[0])
   call remove(v:errors, 0)
 endfunc
 
@@ -21,11 +21,11 @@ func Test_assert_true()
   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 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 assert_match("Expected 'True' but got 0", v:errors[0])
   call remove(v:errors, 0)
 endfunc
 
@@ -234,11 +234,11 @@ func Test_assert_fail_fails()
   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 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 assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
   call remove(v:errors, 0)
 
   call assert_equal(1, assert_fails('echo', '', 'echo command'))
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2859,6 +2859,28 @@ def Test_catch_exception_in_callback()
   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
--- a/src/testing.c
+++ b/src/testing.c
@@ -220,7 +220,11 @@ fill_assert_error(
 	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,6 +575,7 @@ f_assert_fails(typval_T *argvars, typval
     {
 	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,6 +603,7 @@ f_assert_fails(typval_T *argvars, typval
 	    if (!pattern_match(expected, actual, FALSE))
 	    {
 		error_found = TRUE;
+		expected_str = expected;
 	    }
 	    else if (list->lv_len == 2)
 	    {
@@ -605,7 +611,10 @@ f_assert_fails(typval_T *argvars, typval
 		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,7 +674,7 @@ f_assert_fails(typval_T *argvars, typval
 		actual_tv.v_type = VAR_STRING;
 		actual_tv.vval.v_string = actual;
 	    }
-	    fill_assert_error(&ga, &argvars[2], NULL,
+	    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);
--- 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 */
 /**/
+    1953,
+/**/
     1952,
 /**/
     1951,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1071,8 +1071,15 @@ call_def_function(
 	{
 	    // execute Ex command line
 	    case ISN_EXEC:
-		SOURCING_LNUM = iptr->isn_lnum;
-		do_cmdline_cmd(iptr->isn_arg.string);
+		{
+		    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