diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-09-06 22:26:57 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-09-06 22:26:57 +0200 |
commit | 44d6652d561d628d12e3ff7f6636ea7d1f805ced (patch) | |
tree | d56a1089639a79cb532db4dac3b0089e3ef27254 /src/testing.c | |
parent | 9bd5d879c2ecfbdbb168b090e12f4b89724a302e (diff) | |
download | vim-git-44d6652d561d628d12e3ff7f6636ea7d1f805ced.tar.gz |
patch 8.2.1632: not checking the context of test_fails()v8.2.1632
Problem: Not checking the context of test_fails().
Solution: Add the line number and context arguments. Give error if
assert_fails() argument types are wrong.
Diffstat (limited to 'src/testing.c')
-rw-r--r-- | src/testing.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/testing.c b/src/testing.c index 5f7858d89..8db7d62ed 100644 --- a/src/testing.c +++ b/src/testing.c @@ -550,7 +550,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv) garray_T ga; int save_trylevel = trylevel; int called_emsg_before = called_emsg; - int wrong_arg = FALSE; + char *wrong_arg_msg = NULL; // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; @@ -590,7 +590,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv) if (list == NULL || list->lv_len < 1 || list->lv_len > 2) { - wrong_arg = TRUE; + wrong_arg_msg = e_assert_fails_second_arg; goto theend; } CHECK_LIST_MATERIALIZE(list); @@ -611,26 +611,38 @@ f_assert_fails(typval_T *argvars, typval_T *rettv) } else { - wrong_arg = TRUE; + wrong_arg_msg = e_assert_fails_second_arg; goto theend; } if (!error_found && argvars[2].v_type != VAR_UNKNOWN - && argvars[3].v_type == VAR_NUMBER) + && argvars[3].v_type != VAR_UNKNOWN) { - if (argvars[3].vval.v_number >= 0 - && argvars[3].vval.v_number != emsg_assert_fails_lnum) + if (argvars[3].v_type != VAR_NUMBER) + { + wrong_arg_msg = e_assert_fails_fourth_argument; + goto theend; + } + else if (argvars[3].vval.v_number >= 0 + && argvars[3].vval.v_number != emsg_assert_fails_lnum) { error_found = TRUE; error_found_index = 3; } - if (!error_found && argvars[4].v_type == VAR_STRING - && argvars[4].vval.v_string != NULL + if (!error_found && argvars[4].v_type != VAR_UNKNOWN) + { + if (argvars[4].v_type != VAR_STRING) + { + wrong_arg_msg = e_assert_fails_fifth_argument; + goto theend; + } + else if (argvars[4].vval.v_string != NULL && !pattern_match(argvars[4].vval.v_string, emsg_assert_fails_context, FALSE)) - { - error_found = TRUE; - error_found_index = 4; + { + error_found = TRUE; + error_found_index = 4; + } } } @@ -672,8 +684,8 @@ theend: emsg_assert_fails_used = FALSE; VIM_CLEAR(emsg_assert_fails_msg); set_vim_var_string(VV_ERRMSG, NULL, 0); - if (wrong_arg) - emsg(_("E856: assert_fails() second argument must be a string or a list with one or two strings")); + if (wrong_arg_msg != NULL) + emsg(_(wrong_arg_msg)); } /* |