]> granicus.if.org Git - vim/commitdiff
patch 8.1.0460: assert_fails() does not take a message argument v8.1.0460
authorBram Moolenaar <Bram@vim.org>
Sun, 7 Oct 2018 18:16:49 +0000 (20:16 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 7 Oct 2018 18:16:49 +0000 (20:16 +0200)
Problem:    assert_fails() does not take a message argument
Solution:   Add the argument.

src/eval.c
src/evalfunc.c
src/testdir/test_assert.vim
src/version.c

index 4f457a457b6ef0897b0a5a68c3a2e88d30c6e4b1..8746d5556340aa627cc6d9c4ddf4be83457540f8 100644 (file)
@@ -9041,6 +9041,8 @@ assert_fails(typval_T *argvars)
     char_u     *cmd = get_tv_string_chk(&argvars[0]);
     garray_T   ga;
     int                ret = 0;
+    char_u     numbuf[NUMBUFLEN];
+    char_u     *tofree;
 
     called_emsg = FALSE;
     suppress_errthrow = TRUE;
@@ -9050,7 +9052,14 @@ assert_fails(typval_T *argvars)
     {
        prepare_assert_error(&ga);
        ga_concat(&ga, (char_u *)"command did not fail: ");
-       ga_concat(&ga, cmd);
+       if (argvars[1].v_type != VAR_UNKNOWN
+                                          && argvars[2].v_type != VAR_UNKNOWN)
+       {
+           ga_concat(&ga, echo_string(&argvars[2], &tofree, numbuf, 0));
+           vim_free(tofree);
+       }
+       else
+           ga_concat(&ga, cmd);
        assert_error(&ga);
        ga_clear(&ga);
        ret = 1;
index c9f4c4581c4311f5df95b6669a5c8049e7f6deec..0d799964ff0d28ebe0ef7575b931a273a0e1a5b8 100644 (file)
@@ -512,7 +512,7 @@ static struct fst
     {"assert_equal",   2, 3, f_assert_equal},
     {"assert_equalfile", 2, 2, f_assert_equalfile},
     {"assert_exception", 1, 2, f_assert_exception},
-    {"assert_fails",   1, 2, f_assert_fails},
+    {"assert_fails",   1, 3, f_assert_fails},
     {"assert_false",   1, 2, f_assert_false},
     {"assert_inrange", 3, 4, f_assert_inrange},
     {"assert_match",   2, 3, f_assert_match},
@@ -1507,7 +1507,7 @@ f_assert_exception(typval_T *argvars, typval_T *rettv)
 }
 
 /*
- * "assert_fails(cmd [, error])" function
+ * "assert_fails(cmd [, error[, msg]])" function
  */
     static void
 f_assert_fails(typval_T *argvars, typval_T *rettv)
index 28db289b2af54835c6da59c656e03579dd95d22c..fb31478aa4e31e951ac1fd8b9b6260a268c67d26 100644 (file)
@@ -152,6 +152,14 @@ func Test_assert_fail_fails()
   call assert_equal(1, assert_fails('xxx', {}))
   call assert_match("Expected {} but got 'E731:", v:errors[0])
   call remove(v:errors, 0)
+
+  call assert_equal(1, assert_fails('xxx', {}, 'stupid'))
+  call assert_match("stupid: Expected {} but got 'E731:", v:errors[0])
+  call remove(v:errors, 0)
+
+  call assert_equal(1, assert_fails('echo', '', 'echo command'))
+  call assert_match("command did not fail: echo command", v:errors[0])
+  call remove(v:errors, 0)
 endfunc
 
 func Test_assert_beeps()
index c868496700f8b369f27f69ee3bd92ca2a280bafb..7a2e94a1127fe5adc0682025786c4f8e95abc42e 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    460,
 /**/
     459,
 /**/