diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:33:10 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:47:25 +0800 |
commit | 6956971ec790e636b16eeaec798c826515da9834 (patch) | |
tree | f48445ed4f2cb998a56ef56709ef4a87c8411e0d /src/nvim/testing.c | |
parent | 02f80d9a8a560a93142bcebf324ba14cde4dd1b5 (diff) | |
download | rneovim-6956971ec790e636b16eeaec798c826515da9834.tar.gz rneovim-6956971ec790e636b16eeaec798c826515da9834.tar.bz2 rneovim-6956971ec790e636b16eeaec798c826515da9834.zip |
vim-patch:8.2.1632: not checking the context of test_fails()
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.
https://github.com/vim/vim/commit/44d6652d561d628d12e3ff7f6636ea7d1f805ced
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/testing.c')
-rw-r--r-- | src/nvim/testing.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 9dfd828a67..9dd41224da 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -14,6 +14,12 @@ # include "testing.c.generated.h" #endif +static char e_assert_fails_second_arg[] + = N_("E856: assert_fails() second argument must be a string or a list with one or two strings"); +static char e_assert_fails_fourth_argument[] + = N_("E1115: assert_fails() fourth argument must be a number"); +static char e_assert_fails_fifth_argument[] + = N_("E1116: assert_fails() fifth argument must be a string"); static char e_calling_test_garbagecollect_now_while_v_testing_is_not_set[] = N_("E1142: Calling test_garbagecollect_now() while v:testing is not set"); @@ -480,7 +486,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) garray_T ga; int save_trylevel = trylevel; const int called_emsg_before = called_emsg; - bool wrong_arg = false; + char *wrong_arg_msg = NULL; // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; @@ -509,7 +515,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } else if (argvars[1].v_type == VAR_LIST) { const list_T *const list = argvars[1].vval.v_list; if (list == NULL || tv_list_len(list) < 1 || tv_list_len(list) > 2) { - wrong_arg = true; + wrong_arg_msg = e_assert_fails_second_arg; goto theend; } const typval_T *tv = TV_LIST_ITEM_TV(tv_list_first(list)); @@ -525,23 +531,30 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } } 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) { - if (argvars[3].vval.v_number >= 0 - && argvars[3].vval.v_number != emsg_assert_fails_lnum) { + && argvars[3].v_type != VAR_UNKNOWN) { + 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 - && !pattern_match(argvars[4].vval.v_string, - emsg_assert_fails_context, false)) { - error_found = true; - error_found_index = 4; + 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; + } } } @@ -576,9 +589,8 @@ theend: emsg_assert_fails_used = false; XFREE_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)); } } |