From 762ca67091d13336f90350a15e0a1b965d6d5c01 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 13:08:01 +0800 Subject: vim-patch:8.2.4234: test_garbagecollect_now() does not check v:testing Problem: test_garbagecollect_now() does not check v:testing as documented. Solution: Give an error if v:testing is not set. https://github.com/vim/vim/commit/b3d83980d2ac0f7a25314270416f17af874ca269 Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 348d5c6e29..45134db14f 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -14,6 +14,9 @@ # include "testing.c.generated.h" #endif +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"); + /// Prepare "gap" for an assert error and add the sourcing position. static void prepare_assert_error(garray_T *gap) { @@ -614,7 +617,11 @@ void f_test_garbagecollect_now(typval_T *argvars, typval_T *rettv, EvalFuncData { // This is dangerous, any Lists and Dicts used internally may be freed // while still in use. - garbage_collect(true); + if (!get_vim_var_nr(VV_TESTING)) { + emsg(_(e_calling_test_garbagecollect_now_while_v_testing_is_not_set)); + } else { + garbage_collect(true); + } } /// "test_write_list_log()" function -- cgit From 8b0c5de4e0964109326a0befb1b3bff6aac4d0db Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 07:24:06 +0800 Subject: vim-patch:partial:8.2.1183: assert_fails() checks the last error message Problem: assert_fails() checks the last error message. Solution: Check the first error, it is more relevant. Fix all the tests that rely on the old behavior. https://github.com/vim/vim/commit/9b7bf9e98f06ece595fed7a3ff53ecce89797a53 Skip test_listener.vim, test_textprop.vim, test_viminfo.vim. Skip test_python2.vim: affected line fails and hasn't been ported. Skip test_python3.vim: affected lines fail and haven't been ported. Skip CHECK_LIST_MATERIALIZE. Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 45134db14f..5c0e757ccf 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -249,8 +249,7 @@ static int assert_match_common(typval_T *argvars, assert_type_T atype) if (pat == NULL || text == NULL) { emsg(_(e_invarg)); - } else if (pattern_match((char *)pat, (char *)text, false) - != (atype == ASSERT_MATCH)) { + } else if (pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { garray_T ga; prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], atype); @@ -477,11 +476,13 @@ 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; // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; suppress_errthrow = true; emsg_silent = true; + emsg_assert_fails_used = true; do_cmdline_cmd(cmd); if (called_emsg == called_emsg_before) { @@ -493,13 +494,43 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->vval.v_number = 1; } else if (argvars[1].v_type != VAR_UNKNOWN) { char buf[NUMBUFLEN]; - const char *const error = tv_get_string_buf_chk(&argvars[1], buf); + const char *expected; + bool error_found = false; + char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg; + + if (argvars[1].v_type == VAR_STRING) { + expected = tv_get_string_buf_chk(&argvars[1], buf); + error_found = expected == NULL || strstr(actual, expected) == NULL; + } 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; + goto theend; + } + const typval_T *tv = TV_LIST_ITEM_TV(tv_list_first(list)); + expected = tv_get_string_buf_chk(tv, buf); + if (!pattern_match(expected, actual, false)) { + error_found = true; + } 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; + } + } + } else { + wrong_arg = true; + goto theend; + } - if (error == NULL - || strstr(get_vim_var_str(VV_ERRMSG), error) == NULL) { + if (error_found) { + typval_T actual_tv; + actual_tv.v_type = VAR_STRING; + actual_tv.vval.v_string = actual; prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], - get_vim_var_tv(VV_ERRMSG), ASSERT_OTHER); + &actual_tv, ASSERT_OTHER); ga_concat(&ga, ": "); assert_append_cmd_or_arg(&ga, argvars, cmd); assert_error(&ga); @@ -508,11 +539,18 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } +theend: trylevel = save_trylevel; suppress_errthrow = false; emsg_silent = false; emsg_on_display = false; + 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")); + } } // "assert_false(actual[, msg])" function -- cgit From b33de61cc3e14cc6160a972205f6543e82b843aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:28:19 +0800 Subject: vim-patch:8.2.1199: not all assert functions are fully tested Problem: Not all assert functions are fully tested. Solution: Test more assert functions. https://github.com/vim/vim/commit/7177da9dd4d9a521c6141c6fbf7e9a4d6296ab05 Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 5c0e757ccf..e1a28fbde3 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -68,7 +68,7 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) case '\\': ga_concat(gap, "\\\\"); break; default: - if (*p < ' ') { + if (*p < ' ' || *p == 0x7f) { vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); ga_concat(gap, (char *)buf); } else { @@ -244,12 +244,12 @@ 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 (pat == NULL || text == NULL) { - emsg(_(e_invarg)); - } else if (pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { + if (called_emsg == called_emsg_before + && pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { garray_T ga; prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], atype); @@ -350,11 +350,12 @@ 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 (fname1 == NULL || fname2 == NULL) { + if (called_emsg > called_emsg_before) { return 0; } -- cgit From 0d8293364f78237afb83d4822611d6fd8add66f8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:37:28 +0800 Subject: vim-patch:8.2.1479: Vim9: error for list index uses wrong line number Problem: Vim9: error for list index uses wrong line number. Solution: Set source line number. (closes vim/vim#6724) Add a way to assert the line number of the error with assert_fails(). https://github.com/vim/vim/commit/1d634542cf5ebcd1d5d83bd124b3e1d5e7c96c58 Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index e1a28fbde3..7651122cce 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -124,7 +124,10 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s bool did_copy = false; int omitted = 0; - if (opt_msg_tv->v_type != VAR_UNKNOWN) { + if (opt_msg_tv->v_type != VAR_UNKNOWN + && !(opt_msg_tv->v_type == VAR_STRING + && (opt_msg_tv->vval.v_string == NULL + || *opt_msg_tv->vval.v_string == NUL))) { tofree = (char_u *)encode_tv2echo(opt_msg_tv, NULL); ga_concat(gap, (char *)tofree); xfree(tofree); @@ -497,6 +500,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char buf[NUMBUFLEN]; const char *expected; bool error_found = false; + bool lnum_error_found = false; char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg; if (argvars[1].v_type == VAR_STRING) { @@ -525,12 +529,25 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) goto theend; } + if (!error_found && argvars[3].v_type == VAR_NUMBER + && argvars[3].vval.v_number >= 0 + && argvars[3].vval.v_number != emsg_assert_fails_lnum) { + error_found = true; + lnum_error_found = true; + } + if (error_found) { typval_T actual_tv; - actual_tv.v_type = VAR_STRING; - actual_tv.vval.v_string = actual; prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], + if (lnum_error_found) { + actual_tv.v_type = VAR_NUMBER; + actual_tv.vval.v_number = emsg_assert_fails_lnum; + } else { + actual_tv.v_type = VAR_STRING; + actual_tv.vval.v_string = actual; + } + fill_assert_error(&ga, &argvars[2], NULL, + &argvars[lnum_error_found ? 3 : 1], &actual_tv, ASSERT_OTHER); ga_concat(&ga, ": "); assert_append_cmd_or_arg(&ga, argvars, cmd); -- cgit From 8ba7a966a1339767b19a5ca4449b38ef0cae49c7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:40:46 +0800 Subject: vim-patch:8.2.1484: flaky failure in assert_fails() Problem: Flaky failure in assert_fails(). Solution: Only used fourth argument if there is a third argument. https://github.com/vim/vim/commit/9b02d64cff7664b9643205d6e23b08da688fe87a Co-authored-by: Bram Moolenaar --- 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 7651122cce..4ab1367f26 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -529,7 +529,8 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) goto theend; } - if (!error_found && argvars[3].v_type == VAR_NUMBER + if (!error_found && argvars[2].v_type != VAR_UNKNOWN + && argvars[3].v_type == VAR_NUMBER && argvars[3].vval.v_number >= 0 && argvars[3].vval.v_number != emsg_assert_fails_lnum) { error_found = true; -- cgit From 02f80d9a8a560a93142bcebf324ba14cde4dd1b5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:41:36 +0800 Subject: vim-patch:8.2.1631: test_fails() does not check the context of the line number Problem: test_fails() does not check the context of the line number. Solution: Use another argument to specify the context of the line number. https://github.com/vim/vim/commit/9bd5d879c2ecfbdbb168b090e12f4b89724a302e Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 4ab1367f26..9dfd828a67 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -500,7 +500,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char buf[NUMBUFLEN]; const char *expected; bool error_found = false; - bool lnum_error_found = false; + int error_found_index = 1; char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg; if (argvars[1].v_type == VAR_STRING) { @@ -530,26 +530,36 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (!error_found && argvars[2].v_type != VAR_UNKNOWN - && argvars[3].v_type == VAR_NUMBER - && argvars[3].vval.v_number >= 0 - && argvars[3].vval.v_number != emsg_assert_fails_lnum) { - error_found = true; - lnum_error_found = true; + && argvars[3].v_type == VAR_NUMBER) { + 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) { typval_T actual_tv; prepare_assert_error(&ga); - if (lnum_error_found) { + if (error_found_index == 3) { actual_tv.v_type = VAR_NUMBER; actual_tv.vval.v_number = emsg_assert_fails_lnum; + } else if (error_found_index == 4) { + actual_tv.v_type = VAR_STRING; + actual_tv.vval.v_string = emsg_assert_fails_context; } else { actual_tv.v_type = VAR_STRING; actual_tv.vval.v_string = actual; } fill_assert_error(&ga, &argvars[2], NULL, - &argvars[lnum_error_found ? 3 : 1], - &actual_tv, ASSERT_OTHER); + &argvars[error_found_index], &actual_tv, ASSERT_OTHER); ga_concat(&ga, ": "); assert_append_cmd_or_arg(&ga, argvars, cmd); assert_error(&ga); -- cgit From 6956971ec790e636b16eeaec798c826515da9834 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:33:10 +0800 Subject: 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 --- src/nvim/testing.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'src/nvim/testing.c') 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)); } } -- cgit From 0d8e8d36ec7d3f4967f27389b4b94edf3ba57433 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 11 Nov 2022 17:50:52 +0800 Subject: vim-patch:8.2.1919: assert_fails() setting emsg_silent changes normal execution (#20998) Problem: Assert_fails() setting emsg_silent changes normal execution. Solution: Use a separate flag in_assert_fails. https://github.com/vim/vim/commit/28ee892ac4197421b3317f195512ca64cc56a5b4 Cherry-pick no_wait_return from patch 9.0.0846. Co-authored-by: Bram Moolenaar --- src/nvim/testing.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 9dd41224da..a37ceeb86b 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -6,6 +6,8 @@ #include "nvim/eval.h" #include "nvim/eval/encode.h" #include "nvim/ex_docmd.h" +#include "nvim/globals.h" +#include "nvim/message.h" #include "nvim/os/os.h" #include "nvim/runtime.h" #include "nvim/testing.h" @@ -491,8 +493,8 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; suppress_errthrow = true; - emsg_silent = true; - emsg_assert_fails_used = true; + in_assert_fails = true; + no_wait_return++; do_cmdline_cmd(cmd); if (called_emsg == called_emsg_before) { @@ -584,9 +586,14 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) theend: trylevel = save_trylevel; suppress_errthrow = false; - emsg_silent = false; + in_assert_fails = false; + did_emsg = false; + msg_col = 0; + no_wait_return--; + need_wait_return = false; emsg_on_display = false; - emsg_assert_fails_used = false; + msg_reset_scroll(); + lines_left = Rows; XFREE_CLEAR(emsg_assert_fails_msg); set_vim_var_string(VV_ERRMSG, NULL, 0); if (wrong_arg_msg != NULL) { -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/testing.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index a37ceeb86b..f4ff27c9bc 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -3,14 +3,32 @@ // testing.c: Support for tests +#include +#include +#include +#include +#include + +#include "nvim/ascii.h" #include "nvim/eval.h" #include "nvim/eval/encode.h" +#include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/ex_docmd.h" +#include "nvim/garray.h" +#include "nvim/gettext.h" #include "nvim/globals.h" +#include "nvim/hashtab.h" +#include "nvim/macros.h" +#include "nvim/mbyte.h" +#include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/os.h" #include "nvim/runtime.h" +#include "nvim/strings.h" #include "nvim/testing.h" +#include "nvim/types.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "testing.c.generated.h" -- cgit From bd22585061b66d7f71d4832b4a81e950b3c9d19d Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: 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 f4ff27c9bc..3617670da9 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -188,7 +188,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s 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); + 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); if (item2 != NULL) { @@ -209,7 +209,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s dictitem_T *item2 = tv_dict_find(exp_d, (const char *)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); + 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); } -- cgit From a7dc48f19dcd6341cf5e9e199b3ad30e1b9f7327 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 09:48:10 +0800 Subject: vim-patch:8.2.5102: interrupt not caught in test Problem: Interrupt not caught in test. Solution: Consider an exception thrown in the current try/catch when got_int is set. Also catch early exit when not using try/catch. https://github.com/vim/vim/commit/8bea171f154845046239c61bdef50a8e0f12f643 Cherry-pick test changes from patch 8.2.0557. https://github.com/vim/vim/commit/bfe13ccc58ccb96f243a58309800410db1ccb52c Co-authored-by: Bram Moolenaar --- 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 3617670da9..8c54d9ad32 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -606,6 +606,7 @@ theend: suppress_errthrow = false; in_assert_fails = false; did_emsg = false; + got_int = false; msg_col = 0; no_wait_return--; need_wait_return = false; -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/testing.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 8c54d9ad32..edb24c6dc5 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -394,12 +394,12 @@ static int assert_equalfile(typval_T *argvars) char line2[200]; ptrdiff_t lineidx = 0; if (fd1 == NULL) { - snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname1); + snprintf(IObuff, IOSIZE, (char *)e_notread, fname1); } else { FILE *const fd2 = os_fopen(fname2, READBIN); if (fd2 == NULL) { fclose(fd1); - snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname2); + snprintf(IObuff, IOSIZE, (char *)e_notread, fname2); } else { int64_t linecount = 1; for (int64_t count = 0;; count++) { @@ -418,7 +418,7 @@ static int assert_equalfile(typval_T *argvars) line2[lineidx] = (char)c2; lineidx++; if (c1 != c2) { - snprintf((char *)IObuff, IOSIZE, + snprintf(IObuff, IOSIZE, "difference at byte %" PRId64 ", line %" PRId64, count, linecount); break; @@ -445,7 +445,7 @@ static int assert_equalfile(typval_T *argvars) xfree(tofree); ga_concat(&ga, ": "); } - ga_concat(&ga, (char *)IObuff); + ga_concat(&ga, IObuff); if (lineidx > 0) { line1[lineidx] = NUL; line2[lineidx] = NUL; -- cgit From 0344bfad0fc87d2e256ea2b80de7abd069ba1dd2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:17:40 +0100 Subject: refactor: replace char_u with char 22 (#21786) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/testing.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index edb24c6dc5..e9bad2a0b3 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -119,10 +119,10 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) for (const char_u *p = str; *p != NUL; p++) { int same_len = 1; - const char_u *s = p; + const char *s = (char *)p; const int c = mb_ptr2char_adv(&s); - const int clen = (int)(s - p); - while (*s != NUL && c == utf_ptr2char((char *)s)) { + const int clen = (int)((char_u *)s - p); + while (*s != NUL && c == utf_ptr2char(s)) { same_len++; s += clen; } @@ -133,7 +133,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len); ga_concat(gap, (char *)buf); ga_concat(gap, " times]"); - p = s - 1; + p = (char_u *)s - 1; } else { ga_concat_esc(gap, p, clen); } -- cgit From 4c531714ff24d82bf1a85decf0e0c63c5785e686 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:25:56 +0100 Subject: refactor: replace char_u with char 25 (#21838) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/testing.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/nvim/testing.c') diff --git a/src/nvim/testing.c b/src/nvim/testing.c index e9bad2a0b3..d168e67957 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -68,15 +68,15 @@ static void prepare_assert_error(garray_T *gap) /// Append "p[clen]" to "gap", escaping unprintable characters. /// Changes NL to \n, CR to \r, etc. -static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) +static void ga_concat_esc(garray_T *gap, const char *p, int clen) FUNC_ATTR_NONNULL_ALL { - char_u buf[NUMBUFLEN]; + char buf[NUMBUFLEN]; if (clen > 1) { memmove(buf, p, (size_t)clen); buf[clen] = NUL; - ga_concat(gap, (char *)buf); + ga_concat(gap, buf); } else { switch (*p) { case BS: @@ -94,11 +94,11 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) case '\\': ga_concat(gap, "\\\\"); break; default: - if (*p < ' ' || *p == 0x7f) { - vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); - ga_concat(gap, (char *)buf); + if ((uint8_t)(*p) < ' ' || *p == 0x7f) { + vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p); + ga_concat(gap, buf); } else { - ga_append(gap, (char)(*p)); + ga_append(gap, *p); } break; } @@ -107,21 +107,21 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) /// Append "str" to "gap", escaping unprintable characters. /// Changes NL to \n, CR to \r, etc. -static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) +static void ga_concat_shorten_esc(garray_T *gap, const char *str) FUNC_ATTR_NONNULL_ARG(1) { - char_u buf[NUMBUFLEN]; + char buf[NUMBUFLEN]; if (str == NULL) { ga_concat(gap, "NULL"); return; } - for (const char_u *p = str; *p != NUL; p++) { + for (const char *p = str; *p != NUL; p++) { int same_len = 1; - const char *s = (char *)p; + const char *s = p; const int c = mb_ptr2char_adv(&s); - const int clen = (int)((char_u *)s - p); + const int clen = (int)(s - p); while (*s != NUL && c == utf_ptr2char(s)) { same_len++; s += clen; @@ -130,10 +130,10 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) ga_concat(gap, "\\["); ga_concat_esc(gap, p, clen); ga_concat(gap, " occurs "); - vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len); - ga_concat(gap, (char *)buf); + vim_snprintf(buf, NUMBUFLEN, "%d", same_len); + ga_concat(gap, buf); ga_concat(gap, " times]"); - p = (char_u *)s - 1; + p = s - 1; } else { ga_concat_esc(gap, p, clen); } @@ -141,10 +141,10 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) } /// Fill "gap" with information about an assert error. -static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, +static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str, typval_T *exp_tv_arg, typval_T *got_tv_arg, assert_type_T atype) { - char_u *tofree; + char *tofree; typval_T *exp_tv = exp_tv_arg; typval_T *got_tv = got_tv_arg; bool did_copy = false; @@ -154,8 +154,8 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s && !(opt_msg_tv->v_type == VAR_STRING && (opt_msg_tv->vval.v_string == NULL || *opt_msg_tv->vval.v_string == NUL))) { - tofree = (char_u *)encode_tv2echo(opt_msg_tv, NULL); - ga_concat(gap, (char *)tofree); + tofree = encode_tv2echo(opt_msg_tv, NULL); + ga_concat(gap, tofree); xfree(tofree); ga_concat(gap, ": "); } @@ -218,7 +218,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s } } - tofree = (char_u *)encode_tv2string(exp_tv, NULL); + tofree = encode_tv2string(exp_tv, NULL); ga_concat_shorten_esc(gap, tofree); xfree(tofree); } else { @@ -233,7 +233,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s } else { ga_concat(gap, " but got "); } - tofree = (char_u *)encode_tv2string(got_tv, NULL); + tofree = encode_tv2string(got_tv, NULL); ga_concat_shorten_esc(gap, tofree); xfree(tofree); @@ -306,7 +306,7 @@ static int assert_bool(typval_T *argvars, bool is_true) : kBoolVarFalse)))) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[1], - (char_u *)(is_true ? "True" : "False"), + is_true ? "True" : "False", NULL, &argvars[0], ASSERT_OTHER); assert_error(&ga); ga_clear(&ga); @@ -642,8 +642,8 @@ static int assert_inrange(typval_T *argvars) garray_T ga; prepare_assert_error(&ga); if (argvars[3].v_type != VAR_UNKNOWN) { - char_u *const tofree = (char_u *)encode_tv2string(&argvars[3], NULL); - ga_concat(&ga, (char *)tofree); + char *const tofree = encode_tv2string(&argvars[3], NULL); + ga_concat(&ga, tofree); xfree(tofree); } else { char msg[80]; @@ -671,7 +671,7 @@ static int assert_inrange(typval_T *argvars) vim_snprintf(msg, sizeof(msg), "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", lower, upper); // -V576 - fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2], + fill_assert_error(&ga, &argvars[3], msg, NULL, &argvars[2], ASSERT_INRANGE); assert_error(&ga); ga_clear(&ga); -- cgit From e86d2734a93e159d44df8132dee6b994e5922d18 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 21 Jan 2023 09:24:09 +0800 Subject: refactor: use uint8_t for blobs and ga_append() (#21916) A blob is used as a sequence of bytes and usually accessed individually, not as as a NUL-terminuated string, so uint8_t should be better. Not sure about ga_append(), but using uint8_t leads to fewer casts. --- 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 d168e67957..edf92c78ac 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -98,7 +98,7 @@ static void ga_concat_esc(garray_T *gap, const char *p, int clen) vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p); ga_concat(gap, buf); } else { - ga_append(gap, *p); + ga_append(gap, (uint8_t)(*p)); } break; } -- cgit