mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
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.
9bd5d879c2
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -100,7 +100,7 @@ assert_exception({error} [, {msg}]) *assert_exception()*
|
|||||||
endtry
|
endtry
|
||||||
<
|
<
|
||||||
*assert_fails()*
|
*assert_fails()*
|
||||||
assert_fails({cmd} [, {error} [, {msg} [, {lnum}]]])
|
assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
|
||||||
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|.
|
||||||
@@ -127,6 +127,10 @@ assert_fails({cmd} [, {error} [, {msg} [, {lnum}]]])
|
|||||||
the line number at which the error was reported. That can be
|
the line number at which the error was reported. That can be
|
||||||
the line number in a function or in a script.
|
the line number in a function or in a script.
|
||||||
|
|
||||||
|
When {context} is present it is used as a pattern and matched
|
||||||
|
against the context (script name or function name) where
|
||||||
|
{lnum} is located in.
|
||||||
|
|
||||||
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, 4}, base=1},
|
assert_fails={args={1, 5}, 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},
|
||||||
|
@@ -198,6 +198,7 @@ EXTERN bool emsg_severe INIT(= false); // use message of next of several
|
|||||||
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 long emsg_assert_fails_lnum INIT(= 0);
|
||||||
|
EXTERN char *emsg_assert_fails_context INIT(= NULL);
|
||||||
|
|
||||||
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
|
||||||
|
@@ -666,6 +666,8 @@ 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;
|
emsg_assert_fails_lnum = SOURCING_LNUM;
|
||||||
|
xfree(emsg_assert_fails_context);
|
||||||
|
emsg_assert_fails_context = xstrdup(SOURCING_NAME == NULL ? "" : SOURCING_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set "v:errmsg", also when using ":silent! cmd"
|
// set "v:errmsg", also when using ":silent! cmd"
|
||||||
|
@@ -500,7 +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;
|
int error_found_index = 1;
|
||||||
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) {
|
||||||
@@ -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
|
if (!error_found && argvars[2].v_type != VAR_UNKNOWN
|
||||||
&& argvars[3].v_type == VAR_NUMBER
|
&& argvars[3].v_type == VAR_NUMBER) {
|
||||||
&& argvars[3].vval.v_number >= 0
|
if (argvars[3].vval.v_number >= 0
|
||||||
&& argvars[3].vval.v_number != emsg_assert_fails_lnum) {
|
&& argvars[3].vval.v_number != emsg_assert_fails_lnum) {
|
||||||
error_found = true;
|
error_found = true;
|
||||||
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) {
|
if (error_found) {
|
||||||
typval_T actual_tv;
|
typval_T actual_tv;
|
||||||
prepare_assert_error(&ga);
|
prepare_assert_error(&ga);
|
||||||
if (lnum_error_found) {
|
if (error_found_index == 3) {
|
||||||
actual_tv.v_type = VAR_NUMBER;
|
actual_tv.v_type = VAR_NUMBER;
|
||||||
actual_tv.vval.v_number = emsg_assert_fails_lnum;
|
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 {
|
} 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;
|
||||||
}
|
}
|
||||||
fill_assert_error(&ga, &argvars[2], NULL,
|
fill_assert_error(&ga, &argvars[2], NULL,
|
||||||
&argvars[lnum_error_found ? 3 : 1],
|
&argvars[error_found_index], &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);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
|
Reference in New Issue
Block a user