From 88e906d165b5dd57fb13b190ec9cb2d67bc6b223 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 26 Jan 2023 08:52:21 +0800 Subject: vim-patch:9.0.1245: code is indented more than necessary (#21998) Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes vim/vim#11879) https://github.com/vim/vim/commit/032713f8299abd92fcfb1e490d1ae5c1ecadde41 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testing.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index edf92c78ac..b5921b3445 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -77,31 +77,32 @@ static void ga_concat_esc(garray_T *gap, const char *p, int clen) memmove(buf, p, (size_t)clen); buf[clen] = NUL; ga_concat(gap, buf); - } else { - switch (*p) { - case BS: - ga_concat(gap, "\\b"); break; - case ESC: - ga_concat(gap, "\\e"); break; - case FF: - ga_concat(gap, "\\f"); break; - case NL: - ga_concat(gap, "\\n"); break; - case TAB: - ga_concat(gap, "\\t"); break; - case CAR: - ga_concat(gap, "\\r"); break; - case '\\': - ga_concat(gap, "\\\\"); break; - default: - if ((uint8_t)(*p) < ' ' || *p == 0x7f) { - vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p); - ga_concat(gap, buf); - } else { - ga_append(gap, (uint8_t)(*p)); - } - break; + return; + } + + switch (*p) { + case BS: + ga_concat(gap, "\\b"); break; + case ESC: + ga_concat(gap, "\\e"); break; + case FF: + ga_concat(gap, "\\f"); break; + case NL: + ga_concat(gap, "\\n"); break; + case TAB: + ga_concat(gap, "\\t"); break; + case CAR: + ga_concat(gap, "\\r"); break; + case '\\': + ga_concat(gap, "\\\\"); break; + default: + if ((uint8_t)(*p) < ' ' || *p == 0x7f) { + vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p); + ga_concat(gap, buf); + } else { + ga_append(gap, (uint8_t)(*p)); } + break; } } -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/testing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index b5921b3445..3569856f2c 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -395,12 +395,12 @@ static int assert_equalfile(typval_T *argvars) char line2[200]; ptrdiff_t lineidx = 0; if (fd1 == NULL) { - snprintf(IObuff, IOSIZE, (char *)e_notread, fname1); + snprintf(IObuff, IOSIZE, e_notread, fname1); } else { FILE *const fd2 = os_fopen(fname2, READBIN); if (fd2 == NULL) { fclose(fd1); - snprintf(IObuff, IOSIZE, (char *)e_notread, fname2); + snprintf(IObuff, IOSIZE, e_notread, fname2); } else { int64_t linecount = 1; for (int64_t count = 0;; count++) { -- cgit From 371823d407d7d7519735131bcad4670c62a731a7 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:13:53 +0200 Subject: refactor: make error message definitions const message.c functions now take const char * as a format. Error message definitions can be made const. --- src/nvim/testing.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 3569856f2c..2b5284e15e 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -34,13 +34,13 @@ # include "testing.c.generated.h" #endif -static char e_assert_fails_second_arg[] +static const 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[] +static const char e_assert_fails_fourth_argument[] = N_("E1115: assert_fails() fourth argument must be a number"); -static char e_assert_fails_fifth_argument[] +static const 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[] +static const char e_calling_test_garbagecollect_now_while_v_testing_is_not_set[] = N_("E1142: Calling test_garbagecollect_now() while v:testing is not set"); /// Prepare "gap" for an assert error and add the sourcing position. @@ -507,7 +507,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; - char *wrong_arg_msg = NULL; + const char *wrong_arg_msg = NULL; // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/testing.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 2b5284e15e..907940f64a 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -185,16 +185,14 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str int todo = (int)exp_d->dv_hashtab.ht_used; for (const hashitem_T *hi = exp_d->dv_hashtab.ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { - dictitem_T *item2 = tv_dict_find(got_d, (const char *)hi->hi_key, -1); + dictitem_T *item2 = tv_dict_find(got_d, hi->hi_key, -1); if (item2 == NULL || !tv_equal(&TV_DICT_HI2DI(hi)->di_tv, &item2->di_tv, false, false)) { // item of exp_d not present in got_d or values differ. const size_t key_len = strlen(hi->hi_key); - tv_dict_add_tv(exp_tv->vval.v_dict, (const char *)hi->hi_key, key_len, - &TV_DICT_HI2DI(hi)->di_tv); + tv_dict_add_tv(exp_tv->vval.v_dict, hi->hi_key, key_len, &TV_DICT_HI2DI(hi)->di_tv); if (item2 != NULL) { - tv_dict_add_tv(got_tv->vval.v_dict, (const char *)hi->hi_key, key_len, - &item2->di_tv); + tv_dict_add_tv(got_tv->vval.v_dict, hi->hi_key, key_len, &item2->di_tv); } } else { omitted++; @@ -207,12 +205,11 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str todo = (int)got_d->dv_hashtab.ht_used; for (const hashitem_T *hi = got_d->dv_hashtab.ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { - dictitem_T *item2 = tv_dict_find(exp_d, (const char *)hi->hi_key, -1); + dictitem_T *item2 = tv_dict_find(exp_d, hi->hi_key, -1); if (item2 == NULL) { // item of got_d not present in exp_d const size_t key_len = strlen(hi->hi_key); - tv_dict_add_tv(got_tv->vval.v_dict, (const char *)hi->hi_key, key_len, - &TV_DICT_HI2DI(hi)->di_tv); + tv_dict_add_tv(got_tv->vval.v_dict, hi->hi_key, key_len, &TV_DICT_HI2DI(hi)->di_tv); } todo--; } -- cgit From b16729f8162ce21a52f079c3849f5011b768d0ce Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 23:17:43 +0800 Subject: vim-patch:8.2.1697: inconsistent capitalization of error messages (#23476) Problem: Inconsistent capitalization of error messages. Solution: Always start with a capital. https://github.com/vim/vim/commit/7707228aace9aff16434edf5377a354c6ad07316 Most of these errors are Vim9 script only. Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 907940f64a..0e779f9b8d 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -35,11 +35,11 @@ #endif static const char e_assert_fails_second_arg[] - = N_("E856: assert_fails() second argument must be a string or a list with one or two strings"); + = N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"); static const char e_assert_fails_fourth_argument[] - = N_("E1115: assert_fails() fourth argument must be a number"); + = N_("E1115: \"assert_fails()\" fourth argument must be a number"); static const char e_assert_fails_fifth_argument[] - = N_("E1116: assert_fails() fifth argument must be a string"); + = N_("E1116: \"assert_fails()\" fifth argument must be a string"); static const char e_calling_test_garbagecollect_now_while_v_testing_is_not_set[] = N_("E1142: Calling test_garbagecollect_now() while v:testing is not set"); -- cgit From f6299e9d6e13935cc67c2fab16c1a5f6dbc515f3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 06:22:18 +0800 Subject: vim-patch:8.2.3221: Vim9: argument types are not checked at compile time (#23480) Problem: Vim9: argument types are not checked at compile time. Solution: Add several more type checks. (Yegappan Lakshmanan, closes vim/vim#8632) https://github.com/vim/vim/commit/a764e73d4ffc5d046807c757eaacb9b0a5408152 Cherry-pick test_assert.vim change from patch 8.2.3229. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testing.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 0e779f9b8d..4a48743b44 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -500,12 +500,23 @@ void f_assert_exception(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "assert_fails(cmd [, error [, msg]])" function void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - const char *const cmd = tv_get_string_chk(&argvars[0]); garray_T ga; - int save_trylevel = trylevel; + const int save_trylevel = trylevel; const int called_emsg_before = called_emsg; const char *wrong_arg_msg = NULL; + if (tv_check_for_string_or_number_arg(argvars, 0) == FAIL + || tv_check_for_opt_string_or_list_arg(argvars, 1) == FAIL + || (argvars[1].v_type != VAR_UNKNOWN + && (argvars[2].v_type != VAR_UNKNOWN + && (tv_check_for_opt_number_arg(argvars, 3) == FAIL + || (argvars[3].v_type != VAR_UNKNOWN + && tv_check_for_opt_string_arg(argvars, 4) == FAIL))))) { + return; + } + + const char *const cmd = tv_get_string_chk(&argvars[0]); + // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; suppress_errthrow = true; @@ -682,6 +693,13 @@ static int assert_inrange(typval_T *argvars) /// "assert_inrange(lower, upper[, msg])" function void f_assert_inrange(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { + if (tv_check_for_float_or_nr_arg(argvars, 0) == FAIL + || tv_check_for_float_or_nr_arg(argvars, 1) == FAIL + || tv_check_for_float_or_nr_arg(argvars, 2) == FAIL + || tv_check_for_opt_string_arg(argvars, 3) == FAIL) { + return; + } + rettv->vval.v_number = assert_inrange(argvars); } -- cgit From d79e72621226cae91c8d8f6ad23e3c0670e1211c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 06:22:37 +0800 Subject: vim-patch:8.2.4397: crash when using many composing characters in error message (#23481) Problem: Crash when using many composing characters in error message. Solution: Use mb_cptr2char_adv() instead of mb_ptr2char_adv(). https://github.com/vim/vim/commit/34f8117dec685ace52cd9e578e2729db278163fc Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 4a48743b44..867a8ffd3a 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -121,7 +121,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char *str) for (const char *p = str; *p != NUL; p++) { int same_len = 1; const char *s = p; - const int c = mb_ptr2char_adv(&s); + const int c = mb_cptr2char_adv(&s); const int clen = (int)(s - p); while (*s != NUL && c == utf_ptr2char(s)) { same_len++; -- cgit From 0a3a2132d43be3a376214f75157d4d2b1340311e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 21:00:46 +0800 Subject: vim-patch:8.2.1953: Vim9: extra "unknown" error after other error Problem: Vim9: extra "unknown" error after other error. Solution: Restore did_emsg count after EXEC instruction. (closes vim/vim#7254) Improve error message from assert_fails() https://github.com/vim/vim/commit/631e8f93458b102091d54c502f489c03e454d4da Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 867a8ffd3a..27d5334fc5 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -142,7 +142,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char *str) } /// Fill "gap" with information about an assert error. -static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str, +static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *exp_str, typval_T *exp_tv_arg, typval_T *got_tv_arg, assert_type_T atype) { char *tofree; @@ -220,7 +220,13 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str ga_concat_shorten_esc(gap, tofree); xfree(tofree); } else { + if (atype != ASSERT_INRANGE) { + ga_concat(gap, "'"); + } ga_concat_shorten_esc(gap, exp_str); + if (atype != ASSERT_INRANGE) { + ga_concat(gap, "'"); + } } if (atype != ASSERT_NOTEQUAL) { @@ -534,6 +540,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } else if (argvars[1].v_type != VAR_UNKNOWN) { char buf[NUMBUFLEN]; const char *expected; + const char *expected_str = NULL; bool error_found = false; int error_found_index = 1; char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg; @@ -551,12 +558,14 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) expected = tv_get_string_buf_chk(tv, buf); if (!pattern_match(expected, actual, false)) { error_found = true; + expected_str = expected; } else if (tv_list_len(list) == 2) { tv = TV_LIST_ITEM_TV(tv_list_last(list)); actual = get_vim_var_str(VV_ERRMSG); expected = tv_get_string_buf_chk(tv, buf); if (!pattern_match(expected, actual, false)) { error_found = true; + expected_str = expected; } } } else { @@ -600,7 +609,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) actual_tv.v_type = VAR_STRING; actual_tv.vval.v_string = actual; } - fill_assert_error(&ga, &argvars[2], NULL, + fill_assert_error(&ga, &argvars[2], expected_str, &argvars[error_found_index], &actual_tv, ASSERT_OTHER); ga_concat(&ga, ": "); assert_append_cmd_or_arg(&ga, argvars, cmd); -- cgit From 17c8e39f8803daa6f0e6106ce1c087240cef4771 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 21:49:48 +0800 Subject: vim-patch:9.0.0213: using freed memory with error in assert argument Problem: Using freed memory with error in assert argument. Solution: Make a copy of the error. https://github.com/vim/vim/commit/249e1b903a9c0460d618f6dcc59aeb8c03b24b20 Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 27d5334fc5..25149f1b38 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -510,6 +510,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const int save_trylevel = trylevel; const int called_emsg_before = called_emsg; const char *wrong_arg_msg = NULL; + char *tofree = NULL; if (tv_check_for_string_or_number_arg(argvars, 0) == FAIL || tv_check_for_opt_string_or_list_arg(argvars, 1) == FAIL @@ -560,8 +561,9 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) error_found = true; expected_str = expected; } else if (tv_list_len(list) == 2) { + // make a copy, an error in pattern_match() may free it + tofree = actual = xstrdup(get_vim_var_str(VV_ERRMSG)); tv = TV_LIST_ITEM_TV(tv_list_last(list)); - actual = get_vim_var_str(VV_ERRMSG); expected = tv_get_string_buf_chk(tv, buf); if (!pattern_match(expected, actual, false)) { error_found = true; @@ -632,6 +634,7 @@ theend: msg_reset_scroll(); lines_left = Rows; XFREE_CLEAR(emsg_assert_fails_msg); + xfree(tofree); set_vim_var_string(VV_ERRMSG, NULL, 0); if (wrong_arg_msg != NULL) { emsg(_(wrong_arg_msg)); -- cgit From 5fb6b3431a52932dcc50bcc930f8b2c9b71a1bb0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 12:36:47 +0800 Subject: vim-patch:9.0.0404: crash when passing invalid arguments to assert_fails() Problem: Crash when passing invalid arguments to assert_fails(). Solution: Check for NULL string. https://github.com/vim/vim/commit/1540d334a04d874c2aa9d26b82dbbcd4bc5a78de Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 25149f1b38..92747822b4 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -531,6 +531,11 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) no_wait_return++; do_cmdline_cmd(cmd); + + // reset here for any errors reported below + trylevel = save_trylevel; + suppress_errthrow = false; + if (called_emsg == called_emsg_before) { prepare_assert_error(&ga); ga_concat(&ga, "command did not fail: "); @@ -557,6 +562,9 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } const typval_T *tv = TV_LIST_ITEM_TV(tv_list_first(list)); expected = tv_get_string_buf_chk(tv, buf); + if (expected == NULL) { + goto theend; + } if (!pattern_match(expected, actual, false)) { error_found = true; expected_str = expected; @@ -565,6 +573,9 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tofree = actual = xstrdup(get_vim_var_str(VV_ERRMSG)); tv = TV_LIST_ITEM_TV(tv_list_last(list)); expected = tv_get_string_buf_chk(tv, buf); + if (expected == NULL) { + goto theend; + } if (!pattern_match(expected, actual, false)) { error_found = true; expected_str = expected; -- cgit From 49a2bb91170f49101fa67b0cf4cbfec5885edcf4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 12:53:39 +0800 Subject: vim-patch:9.0.0846: using assert_fails() may cause hit-enter prompt Problem: Using assert_fails() may cause hit-enter prompt. Solution: Set no_wait_return. (closes vim/vim#11522) https://github.com/vim/vim/commit/f220643c260d55d21a841a3c4032daadc41bc50b Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 92747822b4..d9c376dd6a 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -522,14 +522,13 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - const char *const cmd = tv_get_string_chk(&argvars[0]); - // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; suppress_errthrow = true; in_assert_fails = true; no_wait_return++; + const char *const cmd = tv_get_string_chk(&argvars[0]); do_cmdline_cmd(cmd); // reset here for any errors reported below -- cgit From c11417b3d74f02568e37ea3370a7c24141d4f18a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 12:59:43 +0800 Subject: vim-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 vim/vim#12342, closes vim/vim#12341) https://github.com/vim/vim/commit/53f5e51628b56ef9171671cd6e9970374036a084 Move assert_type_T to testing.c and remove ASSERT_INRANGE. --- src/nvim/testing.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index d9c376dd6a..430d6713ff 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -30,6 +30,16 @@ #include "nvim/types.h" #include "nvim/vim.h" +/// Type of assert_* check being performed +typedef enum { + ASSERT_EQUAL, + ASSERT_NOTEQUAL, + ASSERT_MATCH, + ASSERT_NOTMATCH, + ASSERT_FAILS, + ASSERT_OTHER, +} assert_type_T; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "testing.c.generated.h" #endif @@ -220,11 +230,11 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e ga_concat_shorten_esc(gap, tofree); xfree(tofree); } else { - if (atype != ASSERT_INRANGE) { + if (atype == ASSERT_FAILS) { ga_concat(gap, "'"); } ga_concat_shorten_esc(gap, exp_str); - if (atype != ASSERT_INRANGE) { + if (atype == ASSERT_FAILS) { ga_concat(gap, "'"); } } @@ -622,7 +632,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) 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, ": "); assert_append_cmd_or_arg(&ga, argvars, cmd); assert_error(&ga); @@ -672,16 +682,9 @@ static int assert_inrange(typval_T *argvars) if (factual < flower || factual > fupper) { garray_T ga; prepare_assert_error(&ga); - if (argvars[3].v_type != VAR_UNKNOWN) { - char *const tofree = encode_tv2string(&argvars[3], NULL); - ga_concat(&ga, tofree); - xfree(tofree); - } else { - char msg[80]; - vim_snprintf(msg, sizeof(msg), "Expected range %g - %g, but got %g", - flower, fupper, factual); - ga_concat(&ga, msg); - } + char expected_str[200]; + vim_snprintf(expected_str, sizeof(expected_str), "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; @@ -697,13 +700,11 @@ static int assert_inrange(typval_T *argvars) if (actual < lower || actual > upper) { garray_T ga; prepare_assert_error(&ga); - - char msg[55]; - vim_snprintf(msg, sizeof(msg), + char expected_str[200]; + vim_snprintf(expected_str, sizeof(expected_str), "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", lower, upper); // -V576 - fill_assert_error(&ga, &argvars[3], msg, NULL, &argvars[2], - ASSERT_INRANGE); + fill_assert_error(&ga, &argvars[3], expected_str, NULL, &argvars[2], ASSERT_OTHER); assert_error(&ga); ga_clear(&ga); return 1; -- cgit From ca5a810c4a67c9c3f482d0c015270c26aee2c943 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 6 May 2023 20:00:17 +0800 Subject: vim-patch:9.0.1511: crash when using wrong arg types to assert_match() (#23507) Problem: Crash when using wrong arg types to assert_match(). Solution: Check for NULL pointer. (closes vim/vim#12349) https://github.com/vim/vim/commit/12e7a1fe7527e9e59adbe248a95b4b532e3ec58c --- src/nvim/testing.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 430d6713ff..5483a58525 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -287,11 +287,10 @@ static int assert_match_common(typval_T *argvars, assert_type_T atype) { char buf1[NUMBUFLEN]; char buf2[NUMBUFLEN]; - const int called_emsg_before = called_emsg; const char *const pat = tv_get_string_buf_chk(&argvars[0], buf1); const char *const text = tv_get_string_buf_chk(&argvars[1], buf2); - if (called_emsg == called_emsg_before + if (pat != NULL && text != NULL && pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { garray_T ga; prepare_assert_error(&ga); @@ -393,12 +392,10 @@ static int assert_equalfile(typval_T *argvars) { char buf1[NUMBUFLEN]; char buf2[NUMBUFLEN]; - const int called_emsg_before = called_emsg; const char *const fname1 = tv_get_string_buf_chk(&argvars[0], buf1); const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2); - garray_T ga; - if (called_emsg > called_emsg_before) { + if (fname1 == NULL || fname2 == NULL) { return 0; } @@ -451,7 +448,9 @@ static int assert_equalfile(typval_T *argvars) fclose(fd2); } } + if (IObuff[0] != NUL) { + garray_T ga; prepare_assert_error(&ga); if (argvars[2].v_type != VAR_UNKNOWN) { char *const tofree = encode_tv2echo(&argvars[2], NULL); @@ -475,6 +474,7 @@ static int assert_equalfile(typval_T *argvars) ga_clear(&ga); return 1; } + return 0; } -- cgit From d36dd2bae8e899b40cc21603e600a5046213bc36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Tue, 16 May 2023 05:33:03 +0200 Subject: refactor: use xstrl{cpy,cat} on IObuff (#23648) Replace usage of STR{CPY,CAT} with xstrl{cpy,cat} when using on IObuff Co-authored-by: ii14 --- src/nvim/testing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 5483a58525..25ec8e898a 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -418,11 +418,11 @@ static int assert_equalfile(typval_T *argvars) const int c2 = fgetc(fd2); if (c1 == EOF) { if (c2 != EOF) { - STRCPY(IObuff, "first file is shorter"); + xstrlcpy(IObuff, "first file is shorter", IOSIZE); } break; } else if (c2 == EOF) { - STRCPY(IObuff, "second file is shorter"); + xstrlcpy(IObuff, "second file is shorter", IOSIZE); break; } else { line1[lineidx] = (char)c1; -- cgit From c48f94d1f30056272ed030ad3f4529055ac07853 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 28 May 2023 16:34:47 +0200 Subject: build: remove LOG_LIST_ACTIONS option and related code It has not been used for a long time and the likelihood of it still working is low. --- src/nvim/testing.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 25ec8e898a..eea75f3021 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -775,5 +775,4 @@ void f_test_write_list_log(typval_T *const argvars, typval_T *const rettv, EvalF if (fname == NULL) { return; } - list_write_log(fname); } -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/testing.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index eea75f3021..4120da745f 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // testing.c: Support for tests #include @@ -703,7 +700,7 @@ static int assert_inrange(typval_T *argvars) char expected_str[200]; vim_snprintf(expected_str, sizeof(expected_str), "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", - lower, upper); // -V576 + lower, upper); fill_assert_error(&ga, &argvars[3], expected_str, NULL, &argvars[2], ASSERT_OTHER); assert_error(&ga); ga_clear(&ga); -- cgit From 1798a4b5e9f0ae56cd800095f79423fea5cae8ca Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: build: bump uncrustify version Biggest change is that uncrustify is silent during linting. --- src/nvim/testing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 4120da745f..f5609a3fb2 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -42,7 +42,8 @@ typedef enum { #endif static const char e_assert_fails_second_arg[] - = N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"); + = N_( + "E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"); static const char e_assert_fails_fourth_argument[] = N_("E1115: \"assert_fails()\" fourth argument must be a number"); static const char e_assert_fails_fifth_argument[] -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/testing.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index f5609a3fb2..d5bb5171fa 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -153,7 +153,6 @@ static void ga_concat_shorten_esc(garray_T *gap, const char *str) static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *exp_str, typval_T *exp_tv_arg, typval_T *got_tv_arg, assert_type_T atype) { - char *tofree; typval_T *exp_tv = exp_tv_arg; typval_T *got_tv = got_tv_arg; bool did_copy = false; @@ -163,7 +162,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e && !(opt_msg_tv->v_type == VAR_STRING && (opt_msg_tv->vval.v_string == NULL || *opt_msg_tv->vval.v_string == NUL))) { - tofree = encode_tv2echo(opt_msg_tv, NULL); + char *tofree = encode_tv2echo(opt_msg_tv, NULL); ga_concat(gap, tofree); xfree(tofree); ga_concat(gap, ": "); @@ -224,7 +223,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e } } - tofree = encode_tv2string(exp_tv, NULL); + char *tofree = encode_tv2string(exp_tv, NULL); ga_concat_shorten_esc(gap, tofree); xfree(tofree); } else { @@ -245,7 +244,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e } else { ga_concat(gap, " but got "); } - tofree = encode_tv2string(got_tv, NULL); + char *tofree = encode_tv2string(got_tv, NULL); ga_concat_shorten_esc(gap, tofree); xfree(tofree); -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/testing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index d5bb5171fa..3c78a1ab0e 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -20,7 +20,7 @@ #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/os/os.h" +#include "nvim/os/fs.h" #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/testing.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/testing.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 3c78a1ab0e..31addfc1e3 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -12,6 +12,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_docmd.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/testing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 31addfc1e3..5cc8e0c31d 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -25,7 +25,7 @@ #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/testing.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/vim.h" /// Type of assert_* check being performed -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/testing.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 5cc8e0c31d..cada04d276 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -6,7 +6,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/eval.h" #include "nvim/eval/encode.h" #include "nvim/eval/typval.h" @@ -17,7 +17,7 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/hashtab.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/message.h" @@ -26,7 +26,7 @@ #include "nvim/strings.h" #include "nvim/testing.h" #include "nvim/types_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" /// Type of assert_* check being performed typedef enum { -- cgit