]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1987: assert_equal() prepends unnecessary ':' when typed v9.1.1987
authorzeertzjq <zeertzjq@outlook.com>
Tue, 16 Dec 2025 19:07:27 +0000 (20:07 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 16 Dec 2025 19:07:27 +0000 (20:07 +0100)
Problem:  assert_equal() prepends unnecessary ':' when typed
          (after 9.0.1758).
Solution: Don't change a NULL stacktrace to an empty string (zeertzjq).

closes: #18936

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/scriptfile.c
src/testdir/test_assert.vim
src/version.c

index 13bb8177cbb1c8226a603ca4b5e7b8b8a827ad88..b98c4e2952c9b10ec42819e9f8ac4102e3a0a9d3 100644 (file)
@@ -226,7 +226,7 @@ estack_sfile(estack_arg_T which UNUSED)
            ga_concat_len(&ga, type_name.string, type_name.length);
            // For class methods prepend "<class name>." to the function name.
            if (*class_name.string != NUL)
-               ga.ga_len += vim_snprintf_safelen(
+               ga.ga_len += (int)vim_snprintf_safelen(
                    (char *)ga.ga_data + ga.ga_len,
                    len - (size_t)ga.ga_len,
                    "<SNR>%d_%s.",
@@ -236,7 +236,7 @@ estack_sfile(estack_arg_T which UNUSED)
            // For the bottom entry of <sfile>: do not add the line number, it is used in
            // <slnum>.  Also leave it out when the number is not set.
            if (lnum != 0)
-               ga.ga_len += vim_snprintf_safelen(
+               ga.ga_len += (int)vim_snprintf_safelen(
                    (char *)ga.ga_data + ga.ga_len,
                    len - (size_t)ga.ga_len,
                    "[%ld]",
@@ -246,7 +246,9 @@ estack_sfile(estack_arg_T which UNUSED)
        }
     }
 
-    ga_append(&ga, NUL);
+    // Only NUL-terminate when not returning NULL.
+    if (ga.ga_data != NULL)
+       ga_append(&ga, NUL);
     return (char_u *)ga.ga_data;
 #endif
 }
index ad4e751c4b2e9fa52babdef6f4bf1190f24f7885..b3e640c11fcfe233df31ec5dcdf73721ae097b7f 100644 (file)
@@ -381,6 +381,19 @@ func Test_assert_fails_in_timer()
   call StopVimInTerminal(buf)
 endfunc
 
+" Check that a typed assert_equal() doesn't prepend an unnecessary ':'.
+func Test_assert_equal_typed()
+  let after =<< trim END
+    call feedkeys(":call assert_equal(0, 1)\<CR>", 't')
+    call feedkeys(":call writefile(v:errors, 'Xerrors')\<CR>", 't')
+    call feedkeys(":qa!\<CR>", 't')
+  END
+  call assert_equal(1, RunVim([], after, ''))
+  call assert_equal(['Expected 0 but got 1'], readfile('Xerrors'))
+
+  call delete('Xerrors')
+endfunc
+
 func Test_assert_beeps()
   new
   call assert_equal(0, assert_beeps('normal h'))
index 1343253f36aa327fd0fc5d2f93996c743f19285a..a4d7a1bf749d506377130f31151b55626f718868 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1987,
 /**/
     1986,
 /**/