diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-10-07 20:16:49 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-10-07 20:16:49 +0200 |
commit | 1307d1c003b01b4f67524c95feb07c3d91c7c428 (patch) | |
tree | 8c365b3c02351b128d4aea2744f4411425a84b30 | |
parent | a05a0d325c7615439f4a42f00682b2ebad43c8d9 (diff) |
patch 8.1.0460: assert_fails() does not take a message argumentv8.1.0460
Problem: assert_fails() does not take a message argument
Solution: Add the argument.
-rw-r--r-- | src/eval.c | 11 | ||||
-rw-r--r-- | src/evalfunc.c | 4 | ||||
-rw-r--r-- | src/testdir/test_assert.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 22 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c index 4f457a457b..8746d55563 100644 --- a/src/eval.c +++ b/src/eval.c @@ -9041,6 +9041,8 @@ assert_fails(typval_T *argvars) char_u *cmd = get_tv_string_chk(&argvars[0]); garray_T ga; int ret = 0; + char_u numbuf[NUMBUFLEN]; + char_u *tofree; called_emsg = FALSE; suppress_errthrow = TRUE; @@ -9050,7 +9052,14 @@ assert_fails(typval_T *argvars) { prepare_assert_error(&ga); ga_concat(&ga, (char_u *)"command did not fail: "); - ga_concat(&ga, cmd); + if (argvars[1].v_type != VAR_UNKNOWN + && argvars[2].v_type != VAR_UNKNOWN) + { + ga_concat(&ga, echo_string(&argvars[2], &tofree, numbuf, 0)); + vim_free(tofree); + } + else + ga_concat(&ga, cmd); assert_error(&ga); ga_clear(&ga); ret = 1; diff --git a/src/evalfunc.c b/src/evalfunc.c index c9f4c4581c..0d799964ff 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -512,7 +512,7 @@ static struct fst {"assert_equal", 2, 3, f_assert_equal}, {"assert_equalfile", 2, 2, f_assert_equalfile}, {"assert_exception", 1, 2, f_assert_exception}, - {"assert_fails", 1, 2, f_assert_fails}, + {"assert_fails", 1, 3, f_assert_fails}, {"assert_false", 1, 2, f_assert_false}, {"assert_inrange", 3, 4, f_assert_inrange}, {"assert_match", 2, 3, f_assert_match}, @@ -1507,7 +1507,7 @@ f_assert_exception(typval_T *argvars, typval_T *rettv) } /* - * "assert_fails(cmd [, error])" function + * "assert_fails(cmd [, error[, msg]])" function */ static void f_assert_fails(typval_T *argvars, typval_T *rettv) diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim index 28db289b2a..fb31478aa4 100644 --- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -152,6 +152,14 @@ func Test_assert_fail_fails() call assert_equal(1, assert_fails('xxx', {})) call assert_match("Expected {} but got 'E731:", v:errors[0]) call remove(v:errors, 0) + + call assert_equal(1, assert_fails('xxx', {}, 'stupid')) + call assert_match("stupid: Expected {} but got 'E731:", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_fails('echo', '', 'echo command')) + call assert_match("command did not fail: echo command", v:errors[0]) + call remove(v:errors, 0) endfunc func Test_assert_beeps() diff --git a/src/version.c b/src/version.c index c868496700..7a2e94a112 100644 --- a/src/version.c +++ b/src/version.c @@ -793,6 +793,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 460, +/**/ 459, /**/ 458, |