Mercurial > vim
changeset 17322:ccd21c8f916b v8.1.1660
patch 8.1.1660: assert_fails() does not fail inside try/catch
commit https://github.com/vim/vim/commit/7780e5c1c5485a979ab6e3914a43e17912e213a8
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 10 22:04:48 2019 +0200
patch 8.1.1660: assert_fails() does not fail inside try/catch
Problem: Assert_fails() does not fail inside try/catch.
Solution: Set trylevel to zero. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/4639)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 10 Jul 2019 22:15:05 +0200 |
parents | 8f7e58f2d2cb |
children | 66db69fb9b4b |
files | src/eval.c src/testdir/test_assert.vim src/version.c |
diffstat | 3 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -9910,10 +9910,14 @@ assert_fails(typval_T *argvars) char_u *cmd = tv_get_string_chk(&argvars[0]); garray_T ga; int ret = 0; - + int save_trylevel = trylevel; + + // trylevel must be zero for a ":throw" command to be considered failed + trylevel = 0; called_emsg = FALSE; suppress_errthrow = TRUE; emsg_silent = TRUE; + do_cmdline_cmd(cmd); if (!called_emsg) { @@ -9939,10 +9943,11 @@ assert_fails(typval_T *argvars) assert_append_cmd_or_arg(&ga, argvars, cmd); assert_error(&ga); ga_clear(&ga); - ret = 1; - } - } - + ret = 1; + } + } + + trylevel = save_trylevel; called_emsg = FALSE; suppress_errthrow = FALSE; emsg_silent = FALSE;
--- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -166,6 +166,12 @@ func Test_assert_fail_fails() call remove(v:errors, 0) endfunc +func Test_assert_fails_in_try_block() + try + call assert_equal(0, assert_fails('throw "error"')) + endtry +endfunc + func Test_assert_beeps() new call assert_equal(0, assert_beeps('normal h'))