Mercurial > vim
changeset 32351:c9b5b21a0369 v9.0.1507
patch 9.0.1507: assert message is confusing with boolean result
Commit: https://github.com/vim/vim/commit/53f5e51628b56ef9171671cd6e9970374036a084
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu May 4 18:58:22 2023 +0100
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 May 2023 20:00:06 +0200 |
parents | f849791c1037 |
children | 0d9e079a4c44 |
files | src/testdir/test_assert.vim src/testing.c src/version.c src/vim.h |
diffstat | 4 files changed, 25 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -9,11 +9,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 @@ -24,11 +24,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 @@ -416,8 +416,11 @@ func Test_assert_inrange() call remove(v:errors, 0) " Use a custom message + call assert_equal(1, assert_inrange(5, 7, 8, "Higher")) + call assert_match("Higher: Expected range 5 - 7, but got 8", v:errors[0]) + call remove(v:errors, 0) call assert_equal(1, assert_inrange(5, 7, 8.0, "Higher")) - call assert_match("Higher", v:errors[0]) + call assert_match("Higher: Expected range 5.0 - 7.0, but got 8.0", v:errors[0]) call remove(v:errors, 0) " Invalid arguments
--- a/src/testing.c +++ b/src/testing.c @@ -223,9 +223,11 @@ fill_assert_error( } else { - ga_concat(gap, (char_u *)"'"); + if (atype == ASSERT_FAILS) + ga_concat(gap, (char_u *)"'"); ga_concat_shorten_esc(gap, exp_str); - ga_concat(gap, (char_u *)"'"); + if (atype == ASSERT_FAILS) + ga_concat(gap, (char_u *)"'"); } if (atype != ASSERT_NOTEQUAL) { @@ -743,7 +745,7 @@ f_assert_fails(typval_T *argvars, typval actual_tv.vval.v_string = actual; } fill_assert_error(&ga, &argvars[2], expected_str, - &argvars[error_found_index], &actual_tv, ASSERT_OTHER); + &argvars[error_found_index], &actual_tv, ASSERT_FAILS); ga_concat(&ga, (char_u *)": "); assert_append_cmd_or_arg(&ga, argvars, cmd); assert_error(&ga); @@ -785,9 +787,7 @@ assert_inrange(typval_T *argvars) { garray_T ga; int error = FALSE; - char_u *tofree; - char msg[200]; - char_u numbuf[NUMBUFLEN]; + char_u expected_str[200]; if (argvars[0].v_type == VAR_FLOAT || argvars[1].v_type == VAR_FLOAT @@ -800,17 +800,10 @@ assert_inrange(typval_T *argvars) if (factual < flower || factual > fupper) { prepare_assert_error(&ga); - if (argvars[3].v_type != VAR_UNKNOWN) - { - ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0)); - vim_free(tofree); - } - else - { - vim_snprintf(msg, 200, "Expected range %g - %g, but got %g", - flower, fupper, factual); - ga_concat(&ga, (char_u *)msg); - } + vim_snprintf((char *)expected_str, 200, "range %g - %g,", + flower, fupper); + fill_assert_error(&ga, &argvars[3], expected_str, NULL, + &argvars[2], ASSERT_OTHER); assert_error(&ga); ga_clear(&ga); return 1; @@ -827,17 +820,10 @@ assert_inrange(typval_T *argvars) if (actual < lower || actual > upper) { prepare_assert_error(&ga); - if (argvars[3].v_type != VAR_UNKNOWN) - { - ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0)); - vim_free(tofree); - } - else - { - vim_snprintf(msg, 200, "Expected range %ld - %ld, but got %ld", - (long)lower, (long)upper, (long)actual); - ga_concat(&ga, (char_u *)msg); - } + vim_snprintf((char *)expected_str, 200, "range %ld - %ld,", + (long)lower, (long)upper); + fill_assert_error(&ga, &argvars[3], expected_str, NULL, + &argvars[2], ASSERT_OTHER); assert_error(&ga); ga_clear(&ga); return 1;