mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.0.1510: cannot test if a command causes a beep
Problem: Cannot test if a command causes a beep. Solution: Add assert_beeps().
This commit is contained in:
parent
294959528e
commit
b48e96f61c
@ -2017,6 +2017,7 @@ argidx() Number current index in the argument list
|
||||
arglistid([{winnr} [, {tabnr}]]) Number argument list id
|
||||
argv({nr}) String {nr} entry of the argument list
|
||||
argv() List the argument list
|
||||
assert_beeps({cmd}) none assert {cmd} causes a beep
|
||||
assert_equal({exp}, {act} [, {msg}])
|
||||
none assert {exp} is equal to {act}
|
||||
assert_exception({error} [, {msg}])
|
||||
@ -2568,6 +2569,11 @@ argv([{nr}]) The result is the {nr}th file in the argument list of the
|
||||
< Without the {nr} argument a |List| with the whole |arglist| is
|
||||
returned.
|
||||
|
||||
assert_beeps({cmd}) *assert_beeps()*
|
||||
Run {cmd} and add an error message to |v:errors| if it does
|
||||
NOT produce a beep or visual bell.
|
||||
Also see |assert_fails()|.
|
||||
|
||||
*assert_equal()*
|
||||
assert_equal({expected}, {actual} [, {msg}])
|
||||
When {expected} and {actual} are not equal an error message is
|
||||
@ -2600,6 +2606,8 @@ assert_fails({cmd} [, {error}]) *assert_fails()*
|
||||
Run {cmd} and add an error message to |v:errors| if it does
|
||||
NOT produce an error.
|
||||
When {error} is given it must match in |v:errmsg|.
|
||||
Note that beeping is not considered an error, and some failing
|
||||
commands only beep. Use |assert_beeps()| for those.
|
||||
|
||||
assert_false({actual} [, {msg}]) *assert_false()*
|
||||
When {actual} is not false an error message is added to
|
||||
|
23
src/eval.c
23
src/eval.c
@ -8941,6 +8941,29 @@ assert_exception(typval_T *argvars)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
assert_beeps(typval_T *argvars)
|
||||
{
|
||||
char_u *cmd = get_tv_string_chk(&argvars[0]);
|
||||
garray_T ga;
|
||||
|
||||
called_vim_beep = FALSE;
|
||||
suppress_errthrow = TRUE;
|
||||
emsg_silent = FALSE;
|
||||
do_cmdline_cmd(cmd);
|
||||
if (!called_vim_beep)
|
||||
{
|
||||
prepare_assert_error(&ga);
|
||||
ga_concat(&ga, (char_u *)"command did not beep: ");
|
||||
ga_concat(&ga, cmd);
|
||||
assert_error(&ga);
|
||||
ga_clear(&ga);
|
||||
}
|
||||
|
||||
suppress_errthrow = FALSE;
|
||||
emsg_on_display = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
assert_fails(typval_T *argvars)
|
||||
{
|
||||
|
@ -44,6 +44,7 @@ static void f_argc(typval_T *argvars, typval_T *rettv);
|
||||
static void f_argidx(typval_T *argvars, typval_T *rettv);
|
||||
static void f_arglistid(typval_T *argvars, typval_T *rettv);
|
||||
static void f_argv(typval_T *argvars, typval_T *rettv);
|
||||
static void f_assert_beeps(typval_T *argvars, typval_T *rettv);
|
||||
static void f_assert_equal(typval_T *argvars, typval_T *rettv);
|
||||
static void f_assert_exception(typval_T *argvars, typval_T *rettv);
|
||||
static void f_assert_fails(typval_T *argvars, typval_T *rettv);
|
||||
@ -483,6 +484,7 @@ static struct fst
|
||||
#ifdef FEAT_FLOAT
|
||||
{"asin", 1, 1, f_asin}, /* WJMc */
|
||||
#endif
|
||||
{"assert_beeps", 1, 2, f_assert_beeps},
|
||||
{"assert_equal", 2, 3, f_assert_equal},
|
||||
{"assert_exception", 1, 2, f_assert_exception},
|
||||
{"assert_fails", 1, 2, f_assert_fails},
|
||||
@ -1274,6 +1276,15 @@ f_argv(typval_T *argvars, typval_T *rettv)
|
||||
alist_name(&ARGLIST[idx]), -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* "assert_beeps(cmd [, error])" function
|
||||
*/
|
||||
static void
|
||||
f_assert_beeps(typval_T *argvars, typval_T *rettv UNUSED)
|
||||
{
|
||||
assert_beeps(argvars);
|
||||
}
|
||||
|
||||
/*
|
||||
* "assert_equal(expected, actual[, msg])" function
|
||||
*/
|
||||
|
@ -181,6 +181,7 @@ EXTERN dict_T globvardict; /* Dictionary with g: variables */
|
||||
EXTERN int did_emsg; /* set by emsg() when the message
|
||||
is displayed or thrown */
|
||||
#ifdef FEAT_EVAL
|
||||
EXTERN int called_vim_beep; /* set if vim_beep() is called */
|
||||
EXTERN int did_uncaught_emsg; /* emsg() was called and did not
|
||||
cause an exception */
|
||||
#endif
|
||||
|
@ -3688,6 +3688,10 @@ beep_flush(void)
|
||||
vim_beep(
|
||||
unsigned val) /* one of the BO_ values, e.g., BO_OPER */
|
||||
{
|
||||
#ifdef FEAT_EVAL
|
||||
called_vim_beep = TRUE;
|
||||
#endif
|
||||
|
||||
if (emsg_silent == 0)
|
||||
{
|
||||
if (!((bo_flags & val) || (bo_flags & BO_ALL)))
|
||||
@ -3718,8 +3722,9 @@ vim_beep(
|
||||
#endif
|
||||
}
|
||||
|
||||
/* When 'verbose' is set and we are sourcing a script or executing a
|
||||
* function give the user a hint where the beep comes from. */
|
||||
/* When 'debug' contains "beep" produce a message. If we are sourcing
|
||||
* a script or executing a function give the user a hint where the beep
|
||||
* comes from. */
|
||||
if (vim_strchr(p_debug, 'e') != NULL)
|
||||
{
|
||||
msg_source(HL_ATTR(HLF_W));
|
||||
|
@ -127,6 +127,7 @@ void assert_inrange(typval_T *argvars);
|
||||
void assert_bool(typval_T *argvars, int isTrue);
|
||||
void assert_report(typval_T *argvars);
|
||||
void assert_exception(typval_T *argvars);
|
||||
void assert_beeps(typval_T *argvars);
|
||||
void assert_fails(typval_T *argvars);
|
||||
void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv, typval_T *got_tv, assert_type_T atype);
|
||||
int typval_compare(typval_T *typ1, typval_T *typ2, exptype_T type, int type_is, int ic, int evaluate);
|
||||
|
@ -111,6 +111,16 @@ func Test_assert_fail_fails()
|
||||
call remove(v:errors, 0)
|
||||
endfunc
|
||||
|
||||
func Test_assert_beeps()
|
||||
new
|
||||
call assert_beeps('normal h')
|
||||
|
||||
call assert_beeps('normal 0')
|
||||
call assert_match("command did not beep: normal 0", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
bwipe
|
||||
endfunc
|
||||
|
||||
func Test_assert_inrange()
|
||||
call assert_inrange(7, 7, 7)
|
||||
call assert_inrange(5, 7, 5)
|
||||
|
@ -2177,6 +2177,8 @@ endfunc
|
||||
|
||||
func! Test_normal45_drop()
|
||||
if !has('dnd')
|
||||
" The ~ register does not exist
|
||||
call assert_beeps('norm! "~')
|
||||
return
|
||||
endif
|
||||
|
||||
|
@ -771,6 +771,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1510,
|
||||
/**/
|
||||
1509,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user