]> granicus.if.org Git - vim/commitdiff
patch 8.0.0254: error message of assert functions is sometimes incomplete v8.0.0254
authorBram Moolenaar <Bram@vim.org>
Sat, 28 Jan 2017 17:08:12 +0000 (18:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 28 Jan 2017 17:08:12 +0000 (18:08 +0100)
Problem:    When using an assert function one can either specify a message or
            get a message about what failed, not both.
Solution:   Concatenate the error with the message.

src/eval.c
src/testdir/test_assert.vim
src/version.c

index 5846936cc00ae0abbcde66e2304ca5498effb7f6..a5ae4f815b11bf46ac7de86223e9d07c215c15ee 100644 (file)
@@ -9240,35 +9240,34 @@ fill_assert_error(
 
     if (opt_msg_tv->v_type != VAR_UNKNOWN)
     {
-       ga_concat(gap, tv2string(opt_msg_tv, &tofree, numbuf, 0));
+       ga_concat(gap, echo_string(opt_msg_tv, &tofree, numbuf, 0));
        vim_free(tofree);
+       ga_concat(gap, (char_u *)": ");
     }
+
+    if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
+       ga_concat(gap, (char_u *)"Pattern ");
+    else if (atype == ASSERT_NOTEQUAL)
+       ga_concat(gap, (char_u *)"Expected not equal to ");
     else
+       ga_concat(gap, (char_u *)"Expected ");
+    if (exp_str == NULL)
     {
-       if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
-           ga_concat(gap, (char_u *)"Pattern ");
-       else if (atype == ASSERT_NOTEQUAL)
-           ga_concat(gap, (char_u *)"Expected not equal to ");
-       else
-           ga_concat(gap, (char_u *)"Expected ");
-       if (exp_str == NULL)
-       {
-           ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
-           vim_free(tofree);
-       }
+       ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
+       vim_free(tofree);
+    }
+    else
+       ga_concat_esc(gap, exp_str);
+    if (atype != ASSERT_NOTEQUAL)
+    {
+       if (atype == ASSERT_MATCH)
+           ga_concat(gap, (char_u *)" does not match ");
+       else if (atype == ASSERT_NOTMATCH)
+           ga_concat(gap, (char_u *)" does match ");
        else
-           ga_concat_esc(gap, exp_str);
-       if (atype != ASSERT_NOTEQUAL)
-       {
-           if (atype == ASSERT_MATCH)
-               ga_concat(gap, (char_u *)" does not match ");
-           else if (atype == ASSERT_NOTMATCH)
-               ga_concat(gap, (char_u *)" does match ");
-           else
-               ga_concat(gap, (char_u *)" but got ");
-           ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
-           vim_free(tofree);
-       }
+           ga_concat(gap, (char_u *)" but got ");
+       ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
+       vim_free(tofree);
     }
 }
 
index 8c54bddb8a301b24f344cce6f4c24cfd77f80414..986f0d9a7e9066db62e9e81b3676228e60e458d3 100644 (file)
@@ -121,6 +121,12 @@ func Test_assert_inrange()
   call assert_fails('call assert_inrange(1, 1)', 'E119:')
 endfunc
 
+func Test_assert_with_msg()
+  call assert_equal('foo', 'bar', 'testing')
+  call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0])
+  call remove(v:errors, 0)
+endfunc
+
 func Test_user_is_happy()
   smile
   sleep 300m
index 19ba72e159131a753fb0a3183c8051bddd604dfc..e66e1b97c53fd6f2a82304bb050c34c2f63fc594 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    254,
 /**/
     253,
 /**/