Skip to content

Commit 53f5e51

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.1507: assert message is confusing with boolean result
Problem: Assert message is confusing with boolean result. assert_inrange() replaces message instead of adding it. Solution: Don't put quotes around expected boolean value. Append message for assert_inrange(). (closes #12342, closes #12341)
1 parent 88bb3e0 commit 53f5e51

4 files changed

Lines changed: 25 additions & 33 deletions

File tree

src/testdir/test_assert.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ func Test_assert_false()
99
call assert_equal(0, v:false->assert_false())
1010

1111
call assert_equal(1, assert_false(123))
12-
call assert_match("Expected 'False' but got 123", v:errors[0])
12+
call assert_match("Expected False but got 123", v:errors[0])
1313
call remove(v:errors, 0)
1414

1515
call assert_equal(1, 123->assert_false())
16-
call assert_match("Expected 'False' but got 123", v:errors[0])
16+
call assert_match("Expected False but got 123", v:errors[0])
1717
call remove(v:errors, 0)
1818
endfunc
1919

@@ -24,11 +24,11 @@ func Test_assert_true()
2424
call assert_equal(0, v:true->assert_true())
2525

2626
call assert_equal(1, assert_true(0))
27-
call assert_match("Expected 'True' but got 0", v:errors[0])
27+
call assert_match("Expected True but got 0", v:errors[0])
2828
call remove(v:errors, 0)
2929

3030
call assert_equal(1, 0->assert_true())
31-
call assert_match("Expected 'True' but got 0", v:errors[0])
31+
call assert_match("Expected True but got 0", v:errors[0])
3232
call remove(v:errors, 0)
3333
endfunc
3434

@@ -416,8 +416,11 @@ func Test_assert_inrange()
416416
call remove(v:errors, 0)
417417

418418
" Use a custom message
419+
call assert_equal(1, assert_inrange(5, 7, 8, "Higher"))
420+
call assert_match("Higher: Expected range 5 - 7, but got 8", v:errors[0])
421+
call remove(v:errors, 0)
419422
call assert_equal(1, assert_inrange(5, 7, 8.0, "Higher"))
420-
call assert_match("Higher", v:errors[0])
423+
call assert_match("Higher: Expected range 5.0 - 7.0, but got 8.0", v:errors[0])
421424
call remove(v:errors, 0)
422425

423426
" Invalid arguments

src/testing.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,11 @@ fill_assert_error(
223223
}
224224
else
225225
{
226-
ga_concat(gap, (char_u *)"'");
226+
if (atype == ASSERT_FAILS)
227+
ga_concat(gap, (char_u *)"'");
227228
ga_concat_shorten_esc(gap, exp_str);
228-
ga_concat(gap, (char_u *)"'");
229+
if (atype == ASSERT_FAILS)
230+
ga_concat(gap, (char_u *)"'");
229231
}
230232
if (atype != ASSERT_NOTEQUAL)
231233
{
@@ -743,7 +745,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
743745
actual_tv.vval.v_string = actual;
744746
}
745747
fill_assert_error(&ga, &argvars[2], expected_str,
746-
&argvars[error_found_index], &actual_tv, ASSERT_OTHER);
748+
&argvars[error_found_index], &actual_tv, ASSERT_FAILS);
747749
ga_concat(&ga, (char_u *)": ");
748750
assert_append_cmd_or_arg(&ga, argvars, cmd);
749751
assert_error(&ga);
@@ -785,9 +787,7 @@ assert_inrange(typval_T *argvars)
785787
{
786788
garray_T ga;
787789
int error = FALSE;
788-
char_u *tofree;
789-
char msg[200];
790-
char_u numbuf[NUMBUFLEN];
790+
char_u expected_str[200];
791791

792792
if (argvars[0].v_type == VAR_FLOAT
793793
|| argvars[1].v_type == VAR_FLOAT
@@ -800,17 +800,10 @@ assert_inrange(typval_T *argvars)
800800
if (factual < flower || factual > fupper)
801801
{
802802
prepare_assert_error(&ga);
803-
if (argvars[3].v_type != VAR_UNKNOWN)
804-
{
805-
ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0));
806-
vim_free(tofree);
807-
}
808-
else
809-
{
810-
vim_snprintf(msg, 200, "Expected range %g - %g, but got %g",
811-
flower, fupper, factual);
812-
ga_concat(&ga, (char_u *)msg);
813-
}
803+
vim_snprintf((char *)expected_str, 200, "range %g - %g,",
804+
flower, fupper);
805+
fill_assert_error(&ga, &argvars[3], expected_str, NULL,
806+
&argvars[2], ASSERT_OTHER);
814807
assert_error(&ga);
815808
ga_clear(&ga);
816809
return 1;
@@ -827,17 +820,10 @@ assert_inrange(typval_T *argvars)
827820
if (actual < lower || actual > upper)
828821
{
829822
prepare_assert_error(&ga);
830-
if (argvars[3].v_type != VAR_UNKNOWN)
831-
{
832-
ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0));
833-
vim_free(tofree);
834-
}
835-
else
836-
{
837-
vim_snprintf(msg, 200, "Expected range %ld - %ld, but got %ld",
838-
(long)lower, (long)upper, (long)actual);
839-
ga_concat(&ga, (char_u *)msg);
840-
}
823+
vim_snprintf((char *)expected_str, 200, "range %ld - %ld,",
824+
(long)lower, (long)upper);
825+
fill_assert_error(&ga, &argvars[3], expected_str, NULL,
826+
&argvars[2], ASSERT_OTHER);
841827
assert_error(&ga);
842828
ga_clear(&ga);
843829
return 1;

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1507,
698700
/**/
699701
1506,
700702
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,7 @@ typedef enum {
22542254
ASSERT_NOTEQUAL,
22552255
ASSERT_MATCH,
22562256
ASSERT_NOTMATCH,
2257+
ASSERT_FAILS,
22572258
ASSERT_OTHER
22582259
} assert_type_T;
22592260

0 commit comments

Comments
 (0)