Skip to content

Commit c7b831c

Browse files
committed
patch 8.0.0254: error message of assert functions is sometimes incomplete
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.
1 parent 36ae89c commit c7b831c

3 files changed

Lines changed: 31 additions & 24 deletions

File tree

src/eval.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9240,35 +9240,34 @@ fill_assert_error(
92409240

92419241
if (opt_msg_tv->v_type != VAR_UNKNOWN)
92429242
{
9243-
ga_concat(gap, tv2string(opt_msg_tv, &tofree, numbuf, 0));
9243+
ga_concat(gap, echo_string(opt_msg_tv, &tofree, numbuf, 0));
92449244
vim_free(tofree);
9245+
ga_concat(gap, (char_u *)": ");
92459246
}
9247+
9248+
if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
9249+
ga_concat(gap, (char_u *)"Pattern ");
9250+
else if (atype == ASSERT_NOTEQUAL)
9251+
ga_concat(gap, (char_u *)"Expected not equal to ");
92469252
else
9253+
ga_concat(gap, (char_u *)"Expected ");
9254+
if (exp_str == NULL)
92479255
{
9248-
if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
9249-
ga_concat(gap, (char_u *)"Pattern ");
9250-
else if (atype == ASSERT_NOTEQUAL)
9251-
ga_concat(gap, (char_u *)"Expected not equal to ");
9252-
else
9253-
ga_concat(gap, (char_u *)"Expected ");
9254-
if (exp_str == NULL)
9255-
{
9256-
ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
9257-
vim_free(tofree);
9258-
}
9256+
ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
9257+
vim_free(tofree);
9258+
}
9259+
else
9260+
ga_concat_esc(gap, exp_str);
9261+
if (atype != ASSERT_NOTEQUAL)
9262+
{
9263+
if (atype == ASSERT_MATCH)
9264+
ga_concat(gap, (char_u *)" does not match ");
9265+
else if (atype == ASSERT_NOTMATCH)
9266+
ga_concat(gap, (char_u *)" does match ");
92599267
else
9260-
ga_concat_esc(gap, exp_str);
9261-
if (atype != ASSERT_NOTEQUAL)
9262-
{
9263-
if (atype == ASSERT_MATCH)
9264-
ga_concat(gap, (char_u *)" does not match ");
9265-
else if (atype == ASSERT_NOTMATCH)
9266-
ga_concat(gap, (char_u *)" does match ");
9267-
else
9268-
ga_concat(gap, (char_u *)" but got ");
9269-
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
9270-
vim_free(tofree);
9271-
}
9268+
ga_concat(gap, (char_u *)" but got ");
9269+
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
9270+
vim_free(tofree);
92729271
}
92739272
}
92749273

src/testdir/test_assert.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ func Test_assert_inrange()
121121
call assert_fails('call assert_inrange(1, 1)', 'E119:')
122122
endfunc
123123

124+
func Test_assert_with_msg()
125+
call assert_equal('foo', 'bar', 'testing')
126+
call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0])
127+
call remove(v:errors, 0)
128+
endfunc
129+
124130
func Test_user_is_happy()
125131
smile
126132
sleep 300m

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
254,
767769
/**/
768770
253,
769771
/**/

0 commit comments

Comments
 (0)