]> granicus.if.org Git - vim/commitdiff
patch 8.2.1953: Vim9: extra "unknown" error after other error v8.2.1953
authorBram Moolenaar <Bram@vim.org>
Wed, 4 Nov 2020 14:07:16 +0000 (15:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 4 Nov 2020 14:07:16 +0000 (15:07 +0100)
Problem:    Vim9: extra "unknown" error after other error.
Solution:   Restore did_emsg count after EXEC instruction. (closes #7254)
            Improve error message from assert_fails()

src/testdir/test_assert.vim
src/testdir/test_vim9_script.vim
src/testing.c
src/version.c
src/vim9execute.c

index 04fde2d655ef6c6be5f9f049671b567d00c67864..04bd87729f22507fa49297c5ea5d2101d19ab786 100644 (file)
@@ -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'))
index 38f24d3491177e4f3a408120a3dac2adf95a8b40..ea9c7c614d1ce3368e690b7afcc20daa2cac5386 100644 (file)
@@ -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
index 919b91182b8d4c64a22e28c3c36cc01f737ba346..6d4f588f8d6e8796b0c5b58a71e6bed960a07329 100644 (file)
@@ -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_T *rettv)
     {
        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_T *rettv)
            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_T *rettv)
                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_T *rettv)
                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);
index 98a3ab1530e09857f45db30262917adc3d8b9b33..a55d2f3eeef32199bde3d46b0ada5f6170bcc0cc 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1953,
 /**/
     1952,
 /**/
index eb0e1db638822d5b8b816cd5f287a7c71bacaa28..c9ae709d63d0567af908e52edba86d2b4c0a3b2f 100644 (file)
@@ -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