aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt8
-rw-r--r--src/nvim/eval.c21
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--src/nvim/globals.h1
-rw-r--r--src/nvim/misc1.c7
-rw-r--r--src/nvim/testdir/test_normal.vim2
-rw-r--r--test/functional/legacy/assert_spec.lua9
7 files changed, 47 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 9e2994ae2e..454013ac73 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1966,6 +1966,7 @@ argidx() Number current index in the argument list
arglistid([{winnr} [, {tabnr}]]) Number argument list id
argv({nr} [, {winid}]) String {nr} entry of the argument list
argv([-1, {winid}]) 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}])
@@ -2479,6 +2480,11 @@ argv([{nr} [, {winid}])
The {winid} argument specifies the window ID, see |argc()|.
+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
@@ -2511,6 +2517,8 @@ assert_fails({cmd} [, {error} [, {msg}]]) *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
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 9f88f1e393..2685cf5cea 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6877,6 +6877,27 @@ static void assert_equal_common(typval_T *argvars, assert_type_T atype)
}
}
+static void f_assert_beeps(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ const char *const cmd = tv_get_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, (const char_u *)"command did not beep: ");
+ ga_concat(&ga, (const char_u *)cmd);
+ assert_error(&ga);
+ ga_clear(&ga);
+ }
+
+ suppress_errthrow = false;
+ emsg_on_display = false;
+}
+
// "assert_equal(expected, actual[, msg])" function
static void f_assert_equal(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 311897b3cd..b7525ee49b 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -25,6 +25,7 @@ return {
arglistid={args={0, 2}},
argv={args={0, 1}},
asin={args=1, func="float_op_wrapper", data="&asin"}, -- WJMc
+ assert_beeps={args={1, 2}},
assert_equal={args={2, 3}},
assert_exception={args={1, 2}},
assert_fails={args={1, 2}},
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 79af4a8ce3..ec14ada3d2 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -227,6 +227,7 @@ EXTERN dict_T vimvardict; /* Dictionary with v: variables */
EXTERN dict_T globvardict; /* Dictionary with g: variables */
EXTERN int did_emsg; /* set by emsg() when the message
is displayed or thrown */
+EXTERN bool called_vim_beep; // set if vim_beep() is called
EXTERN int did_emsg_syntax; /* did_emsg set because of a
syntax error */
EXTERN int called_emsg; /* always set by emsg() */
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index e5c22e5be3..57285fa252 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -2578,6 +2578,8 @@ void beep_flush(void)
// val is one of the BO_ values, e.g., BO_OPER
void vim_beep(unsigned val)
{
+ called_vim_beep = true;
+
if (emsg_silent == 0) {
if (!((bo_flags & val) || (bo_flags & BO_ALL))) {
if (p_vb) {
@@ -2587,8 +2589,9 @@ void vim_beep(unsigned val)
}
}
- /* 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));
msg_attr(_("Beep!"), HL_ATTR(HLF_W));
diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim
index d07b3fdbce..9c0f0ee501 100644
--- a/src/nvim/testdir/test_normal.vim
+++ b/src/nvim/testdir/test_normal.vim
@@ -2272,6 +2272,8 @@ endfunc
func! Test_normal45_drop()
if !has('dnd')
+ " The ~ register does not exist
+ call assert_beeps('norm! "~')
return
endif
diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua
index 10703465aa..8df2d89b70 100644
--- a/test/functional/legacy/assert_spec.lua
+++ b/test/functional/legacy/assert_spec.lua
@@ -18,6 +18,15 @@ describe('assert function:', function()
clear()
end)
+ describe('assert_beeps', function()
+ it('works', function()
+ call('assert_beeps', 'normal h')
+ expected_empty()
+ call('assert_beeps', 'normal 0')
+ expected_errors({'command did not beep: normal 0'})
+ end)
+ end)
+
-- assert_equal({expected}, {actual}, [, {msg}])
describe('assert_equal', function()
it('should not change v:errors when expected is equal to actual', function()