diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-02-13 12:26:14 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-02-13 12:26:14 +0100 |
commit | b48e96f61c87a64e38e3ac50732c92a84a4833b8 (patch) | |
tree | 170cf91f5865fda3f985328c50b5d009e5296a3b /src | |
parent | 294959528e02403cd7ef6541208835f0c621c63b (diff) |
patch 8.0.1510: cannot test if a command causes a beepv8.0.1510
Problem: Cannot test if a command causes a beep.
Solution: Add assert_beeps().
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 23 | ||||
-rw-r--r-- | src/evalfunc.c | 11 | ||||
-rw-r--r-- | src/globals.h | 1 | ||||
-rw-r--r-- | src/misc1.c | 9 | ||||
-rw-r--r-- | src/proto/eval.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_assert.vim | 10 | ||||
-rw-r--r-- | src/testdir/test_normal.vim | 2 | ||||
-rw-r--r-- | src/version.c | 2 |
8 files changed, 57 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c index 2c93e4ec4b..b1f7a86061 100644 --- a/src/eval.c +++ b/src/eval.c @@ -8942,6 +8942,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) { char_u *cmd = get_tv_string_chk(&argvars[0]); diff --git a/src/evalfunc.c b/src/evalfunc.c index 3977944ca3..959be0cf8e 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -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}, @@ -1275,6 +1277,15 @@ f_argv(typval_T *argvars, typval_T *rettv) } /* + * "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 */ static void diff --git a/src/globals.h b/src/globals.h index 1b2b1e8bf1..2504d2ec4b 100644 --- a/src/globals.h +++ b/src/globals.h @@ -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 diff --git a/src/misc1.c b/src/misc1.c index 821869aa32..e639fbe41b 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -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)); diff --git a/src/proto/eval.pro b/src/proto/eval.pro index 855946ce29..e3e4a532bc 100644 --- a/src/proto/eval.pro +++ b/src/proto/eval.pro @@ -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); diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim index 8359eb11c8..29c853409e 100644 --- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -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) diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim index 27c589783a..2d1446bfd6 100644 --- a/src/testdir/test_normal.vim +++ b/src/testdir/test_normal.vim @@ -2177,6 +2177,8 @@ endfunc func! Test_normal45_drop() if !has('dnd') + " The ~ register does not exist + call assert_beeps('norm! "~') return endif diff --git a/src/version.c b/src/version.c index beffe2a861..7028ad39c4 100644 --- a/src/version.c +++ b/src/version.c @@ -772,6 +772,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1510, +/**/ 1509, /**/ 1508, |