Patch 8.0.1510
Problem:    Cannot test if a command causes a beep.
Solution:   Add assert_beeps().
Files:      runtime/doc/eval.txt, src/evalfunc.c, src/eval.c,
            src/proto/eval.pro, src/misc1.c, src/globals.h,
            src/testdir/test_normal.vim, src/testdir/test_assert.vim


*** ../vim-8.0.1509/runtime/doc/eval.txt        2018-02-10 21:05:52.638858238 
+0100
--- runtime/doc/eval.txt        2018-02-13 12:01:49.224402155 +0100
***************
*** 2017,2022 ****
--- 2017,2023 ----
  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}])
***************
*** 2566,2571 ****
--- 2569,2579 ----
  <             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
***************
*** 2598,2603 ****
--- 2606,2613 ----
                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
*** ../vim-8.0.1509/src/evalfunc.c      2018-02-11 19:06:20.261418967 +0100
--- src/evalfunc.c      2018-02-13 11:57:49.386204817 +0100
***************
*** 44,49 ****
--- 44,50 ----
  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,488 ****
--- 484,490 ----
  #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,1280 ****
--- 1277,1291 ----
  }
  
  /*
+  * "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
*** ../vim-8.0.1509/src/eval.c  2018-02-11 19:06:20.257418995 +0100
--- src/eval.c  2018-02-13 12:15:59.990866561 +0100
***************
*** 8942,8947 ****
--- 8942,8970 ----
  }
  
      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]);
*** ../vim-8.0.1509/src/proto/eval.pro  2018-02-11 19:06:20.269418910 +0100
--- src/proto/eval.pro  2018-02-13 12:04:55.735022276 +0100
***************
*** 127,132 ****
--- 127,133 ----
  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);
*** ../vim-8.0.1509/src/misc1.c 2018-02-10 18:45:21.072822129 +0100
--- src/misc1.c 2018-02-13 12:06:19.947312274 +0100
***************
*** 3688,3693 ****
--- 3688,3697 ----
  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,3725 ****
  #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. */
        if (vim_strchr(p_debug, 'e') != NULL)
        {
            msg_source(HL_ATTR(HLF_W));
--- 3722,3730 ----
  #endif
        }
  
!       /* 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));
*** ../vim-8.0.1509/src/globals.h       2018-02-10 18:15:00.754098808 +0100
--- src/globals.h       2018-02-13 12:05:55.699241920 +0100
***************
*** 181,186 ****
--- 181,187 ----
  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
*** ../vim-8.0.1509/src/testdir/test_normal.vim 2018-02-12 22:48:55.974961343 
+0100
--- src/testdir/test_normal.vim 2018-02-13 12:08:48.271543254 +0100
***************
*** 2177,2182 ****
--- 2177,2184 ----
  
  func! Test_normal45_drop()
    if !has('dnd')
+     " The ~ register does not exist
+     call assert_beeps('norm! "~')
      return
    endif
  
*** ../vim-8.0.1509/src/testdir/test_assert.vim 2017-03-18 20:18:42.067950195 
+0100
--- src/testdir/test_assert.vim 2018-02-13 12:11:01.971510052 +0100
***************
*** 111,116 ****
--- 111,126 ----
    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)
*** ../vim-8.0.1509/src/version.c       2018-02-12 22:48:55.974961343 +0100
--- src/version.c       2018-02-13 12:25:14.328522359 +0100
***************
*** 773,774 ****
--- 773,776 ----
  {   /* Add new patch number below this line */
+ /**/
+     1510,
  /**/

-- 
BLACK KNIGHT:  I move for no man.
ARTHUR:        So be it!
    [hah] [parry thrust]
    [ARTHUR chops the BLACK KNIGHT's left arm off]
ARTHUR:        Now stand aside, worthy adversary.
BLACK KNIGHT:  'Tis but a scratch.
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui