Patch 9.0.1507
Problem:    Assert message is confusing with boolean result.  assert_inrange()
            replaces message instead of adding it.
Solution:   Don't put quotes around expected boolean value.  Append message
            for assert_inrange(). (closes #12342, closes #12341)
Files:      src/testing.c, src/vim.h, src/testdir/test_assert.vim


*** ../vim-9.0.1506/src/testing.c       2023-03-07 17:13:47.317107770 +0000
--- src/testing.c       2023-05-04 18:43:43.617143115 +0100
***************
*** 223,231 ****
      }
      else
      {
!       ga_concat(gap, (char_u *)"'");
        ga_concat_shorten_esc(gap, exp_str);
!       ga_concat(gap, (char_u *)"'");
      }
      if (atype != ASSERT_NOTEQUAL)
      {
--- 223,233 ----
      }
      else
      {
!       if (atype == ASSERT_FAILS)
!           ga_concat(gap, (char_u *)"'");
        ga_concat_shorten_esc(gap, exp_str);
!       if (atype == ASSERT_FAILS)
!           ga_concat(gap, (char_u *)"'");
      }
      if (atype != ASSERT_NOTEQUAL)
      {
***************
*** 743,749 ****
                actual_tv.vval.v_string = actual;
            }
            fill_assert_error(&ga, &argvars[2], expected_str,
!                       &argvars[error_found_index], &actual_tv, ASSERT_OTHER);
            ga_concat(&ga, (char_u *)": ");
            assert_append_cmd_or_arg(&ga, argvars, cmd);
            assert_error(&ga);
--- 745,751 ----
                actual_tv.vval.v_string = actual;
            }
            fill_assert_error(&ga, &argvars[2], expected_str,
!                       &argvars[error_found_index], &actual_tv, ASSERT_FAILS);
            ga_concat(&ga, (char_u *)": ");
            assert_append_cmd_or_arg(&ga, argvars, cmd);
            assert_error(&ga);
***************
*** 785,793 ****
  {
      garray_T  ga;
      int               error = FALSE;
!     char_u    *tofree;
!     char      msg[200];
!     char_u    numbuf[NUMBUFLEN];
  
      if (argvars[0].v_type == VAR_FLOAT
            || argvars[1].v_type == VAR_FLOAT
--- 787,793 ----
  {
      garray_T  ga;
      int               error = FALSE;
!     char_u    expected_str[200];
  
      if (argvars[0].v_type == VAR_FLOAT
            || argvars[1].v_type == VAR_FLOAT
***************
*** 800,816 ****
        if (factual < flower || factual > fupper)
        {
            prepare_assert_error(&ga);
!           if (argvars[3].v_type != VAR_UNKNOWN)
!           {
!               ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0));
!               vim_free(tofree);
!           }
!           else
!           {
!               vim_snprintf(msg, 200, "Expected range %g - %g, but got %g",
!                                                     flower, fupper, factual);
!               ga_concat(&ga, (char_u *)msg);
!           }
            assert_error(&ga);
            ga_clear(&ga);
            return 1;
--- 800,809 ----
        if (factual < flower || factual > fupper)
        {
            prepare_assert_error(&ga);
!           vim_snprintf((char *)expected_str, 200, "range %g - %g,",
!                                                              flower, fupper);
!           fill_assert_error(&ga, &argvars[3], expected_str, NULL,
!                                                   &argvars[2], ASSERT_OTHER);
            assert_error(&ga);
            ga_clear(&ga);
            return 1;
***************
*** 827,843 ****
        if (actual < lower || actual > upper)
        {
            prepare_assert_error(&ga);
!           if (argvars[3].v_type != VAR_UNKNOWN)
!           {
!               ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0));
!               vim_free(tofree);
!           }
!           else
!           {
!               vim_snprintf(msg, 200, "Expected range %ld - %ld, but got %ld",
!                                      (long)lower, (long)upper, (long)actual);
!               ga_concat(&ga, (char_u *)msg);
!           }
            assert_error(&ga);
            ga_clear(&ga);
            return 1;
--- 820,829 ----
        if (actual < lower || actual > upper)
        {
            prepare_assert_error(&ga);
!           vim_snprintf((char *)expected_str, 200, "range %ld - %ld,",
!                                                    (long)lower, (long)upper);
!           fill_assert_error(&ga, &argvars[3], expected_str, NULL,
!                                                   &argvars[2], ASSERT_OTHER);
            assert_error(&ga);
            ga_clear(&ga);
            return 1;
*** ../vim-9.0.1506/src/vim.h   2023-05-02 16:25:35.630819728 +0100
--- src/vim.h   2023-05-04 18:43:43.617143115 +0100
***************
*** 2254,2259 ****
--- 2254,2260 ----
      ASSERT_NOTEQUAL,
      ASSERT_MATCH,
      ASSERT_NOTMATCH,
+     ASSERT_FAILS,
      ASSERT_OTHER
  } assert_type_T;
  
*** ../vim-9.0.1506/src/testdir/test_assert.vim 2023-01-28 19:18:56.725720605 
+0000
--- src/testdir/test_assert.vim 2023-05-04 18:43:43.617143115 +0100
***************
*** 9,19 ****
    call assert_equal(0, v:false->assert_false())
  
    call assert_equal(1, assert_false(123))
!   call assert_match("Expected 'False' but got 123", v:errors[0])
    call remove(v:errors, 0)
  
    call assert_equal(1, 123->assert_false())
!   call assert_match("Expected 'False' but got 123", v:errors[0])
    call remove(v:errors, 0)
  endfunc
  
--- 9,19 ----
    call assert_equal(0, v:false->assert_false())
  
    call assert_equal(1, assert_false(123))
!   call assert_match("Expected False but got 123", v:errors[0])
    call remove(v:errors, 0)
  
    call assert_equal(1, 123->assert_false())
!   call assert_match("Expected False but got 123", v:errors[0])
    call remove(v:errors, 0)
  endfunc
  
***************
*** 24,34 ****
    call assert_equal(0, v:true->assert_true())
  
    call assert_equal(1, assert_true(0))
!   call assert_match("Expected 'True' but got 0", v:errors[0])
    call remove(v:errors, 0)
  
    call assert_equal(1, 0->assert_true())
!   call assert_match("Expected 'True' but got 0", v:errors[0])
    call remove(v:errors, 0)
  endfunc
  
--- 24,34 ----
    call assert_equal(0, v:true->assert_true())
  
    call assert_equal(1, assert_true(0))
!   call assert_match("Expected True but got 0", v:errors[0])
    call remove(v:errors, 0)
  
    call assert_equal(1, 0->assert_true())
!   call assert_match("Expected True but got 0", v:errors[0])
    call remove(v:errors, 0)
  endfunc
  
***************
*** 416,423 ****
    call remove(v:errors, 0)
  
    " Use a custom message
    call assert_equal(1, assert_inrange(5, 7, 8.0, "Higher"))
!   call assert_match("Higher", v:errors[0])
    call remove(v:errors, 0)
  
    " Invalid arguments
--- 416,426 ----
    call remove(v:errors, 0)
  
    " Use a custom message
+   call assert_equal(1, assert_inrange(5, 7, 8, "Higher"))
+   call assert_match("Higher: Expected range 5 - 7, but got 8", v:errors[0])
+   call remove(v:errors, 0)
    call assert_equal(1, assert_inrange(5, 7, 8.0, "Higher"))
!   call assert_match("Higher: Expected range 5.0 - 7.0, but got 8.0", 
v:errors[0])
    call remove(v:errors, 0)
  
    " Invalid arguments
*** ../vim-9.0.1506/src/version.c       2023-05-02 20:52:32.047787527 +0100
--- src/version.c       2023-05-04 18:45:53.838320376 +0100
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1507,
  /**/

-- 
Female engineers become irresistible at the age of consent and remain that
way until about thirty minutes after their clinical death.  Longer if it's a
warm day.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230504175848.6316C1C1072%40moolenaar.net.

Raspunde prin e-mail lui