mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
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().
1d634542cf
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -98,8 +98,9 @@ assert_exception({error} [, {msg}]) *assert_exception()*
|
|||||||
catch
|
catch
|
||||||
call assert_exception('E492:')
|
call assert_exception('E492:')
|
||||||
endtry
|
endtry
|
||||||
|
<
|
||||||
assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()*
|
*assert_fails()*
|
||||||
|
assert_fails({cmd} [, {error} [, {msg} [, {lnum}]]])
|
||||||
Run {cmd} and add an error message to |v:errors| if it does
|
Run {cmd} and add an error message to |v:errors| if it does
|
||||||
NOT produce an error or when {error} is not found in the
|
NOT produce an error or when {error} is not found in the
|
||||||
error message. Also see |assert-return|.
|
error message. Also see |assert-return|.
|
||||||
@@ -118,6 +119,14 @@ assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()*
|
|||||||
string for the first error: >
|
string for the first error: >
|
||||||
assert_fails('cmd', ['', 'E987:'])
|
assert_fails('cmd', ['', 'E987:'])
|
||||||
<
|
<
|
||||||
|
If {msg} is empty then it is not used. Do this to get the
|
||||||
|
default message when passing the {lnum} argument.
|
||||||
|
|
||||||
|
When {lnum} is present and not negative, and the {error}
|
||||||
|
argument is present and matches, then this is compared with
|
||||||
|
the line number at which the error was reported. That can be
|
||||||
|
the line number in a function or in a script.
|
||||||
|
|
||||||
Note that beeping is not considered an error, and some failing
|
Note that beeping is not considered an error, and some failing
|
||||||
commands only beep. Use |assert_beeps()| for those.
|
commands only beep. Use |assert_beeps()| for those.
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ return {
|
|||||||
assert_equal={args={2, 3}, base=2},
|
assert_equal={args={2, 3}, base=2},
|
||||||
assert_equalfile={args={2, 3}, base=1},
|
assert_equalfile={args={2, 3}, base=1},
|
||||||
assert_exception={args={1, 2}},
|
assert_exception={args={1, 2}},
|
||||||
assert_fails={args={1, 3}, base=1},
|
assert_fails={args={1, 4}, base=1},
|
||||||
assert_false={args={1, 2}, base=1},
|
assert_false={args={1, 2}, base=1},
|
||||||
assert_inrange={args={3, 4}, base=3},
|
assert_inrange={args={3, 4}, base=3},
|
||||||
assert_match={args={2, 3}, base=2},
|
assert_match={args={2, 3}, base=2},
|
||||||
|
@@ -197,6 +197,7 @@ EXTERN bool emsg_severe INIT(= false); // use message of next of several
|
|||||||
// used by assert_fails()
|
// used by assert_fails()
|
||||||
EXTERN bool emsg_assert_fails_used INIT(= false);
|
EXTERN bool emsg_assert_fails_used INIT(= false);
|
||||||
EXTERN char *emsg_assert_fails_msg INIT(= NULL);
|
EXTERN char *emsg_assert_fails_msg INIT(= NULL);
|
||||||
|
EXTERN long emsg_assert_fails_lnum INIT(= 0);
|
||||||
|
|
||||||
EXTERN bool did_endif INIT(= false); // just had ":endif"
|
EXTERN bool did_endif INIT(= false); // just had ":endif"
|
||||||
EXTERN dict_T vimvardict; // Dictionary with v: variables
|
EXTERN dict_T vimvardict; // Dictionary with v: variables
|
||||||
|
@@ -665,6 +665,7 @@ static bool emsg_multiline(const char *s, bool multiline)
|
|||||||
|
|
||||||
if (emsg_assert_fails_used && emsg_assert_fails_msg == NULL) {
|
if (emsg_assert_fails_used && emsg_assert_fails_msg == NULL) {
|
||||||
emsg_assert_fails_msg = xstrdup(s);
|
emsg_assert_fails_msg = xstrdup(s);
|
||||||
|
emsg_assert_fails_lnum = SOURCING_LNUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set "v:errmsg", also when using ":silent! cmd"
|
// set "v:errmsg", also when using ":silent! cmd"
|
||||||
|
@@ -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;
|
bool did_copy = false;
|
||||||
int omitted = 0;
|
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);
|
tofree = (char_u *)encode_tv2echo(opt_msg_tv, NULL);
|
||||||
ga_concat(gap, (char *)tofree);
|
ga_concat(gap, (char *)tofree);
|
||||||
xfree(tofree);
|
xfree(tofree);
|
||||||
@@ -497,6 +500,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
char buf[NUMBUFLEN];
|
char buf[NUMBUFLEN];
|
||||||
const char *expected;
|
const char *expected;
|
||||||
bool error_found = false;
|
bool error_found = false;
|
||||||
|
bool lnum_error_found = false;
|
||||||
char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg;
|
char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg;
|
||||||
|
|
||||||
if (argvars[1].v_type == VAR_STRING) {
|
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;
|
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) {
|
if (error_found) {
|
||||||
typval_T actual_tv;
|
typval_T actual_tv;
|
||||||
|
prepare_assert_error(&ga);
|
||||||
|
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.v_type = VAR_STRING;
|
||||||
actual_tv.vval.v_string = actual;
|
actual_tv.vval.v_string = actual;
|
||||||
prepare_assert_error(&ga);
|
}
|
||||||
fill_assert_error(&ga, &argvars[2], NULL, &argvars[1],
|
fill_assert_error(&ga, &argvars[2], NULL,
|
||||||
|
&argvars[lnum_error_found ? 3 : 1],
|
||||||
&actual_tv, ASSERT_OTHER);
|
&actual_tv, ASSERT_OTHER);
|
||||||
ga_concat(&ga, ": ");
|
ga_concat(&ga, ": ");
|
||||||
assert_append_cmd_or_arg(&ga, argvars, cmd);
|
assert_append_cmd_or_arg(&ga, argvars, cmd);
|
||||||
|
Reference in New Issue
Block a user