Skip to content

Commit c4b3aef

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.1987: assert_equal() prepends unnecessary ':' when typed
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>
1 parent beeea8a commit c4b3aef

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/scriptfile.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ estack_sfile(estack_arg_T which UNUSED)
226226
ga_concat_len(&ga, type_name.string, type_name.length);
227227
// For class methods prepend "<class name>." to the function name.
228228
if (*class_name.string != NUL)
229-
ga.ga_len += vim_snprintf_safelen(
229+
ga.ga_len += (int)vim_snprintf_safelen(
230230
(char *)ga.ga_data + ga.ga_len,
231231
len - (size_t)ga.ga_len,
232232
"<SNR>%d_%s.",
@@ -236,7 +236,7 @@ estack_sfile(estack_arg_T which UNUSED)
236236
// For the bottom entry of <sfile>: do not add the line number, it is used in
237237
// <slnum>. Also leave it out when the number is not set.
238238
if (lnum != 0)
239-
ga.ga_len += vim_snprintf_safelen(
239+
ga.ga_len += (int)vim_snprintf_safelen(
240240
(char *)ga.ga_data + ga.ga_len,
241241
len - (size_t)ga.ga_len,
242242
"[%ld]",
@@ -246,7 +246,9 @@ estack_sfile(estack_arg_T which UNUSED)
246246
}
247247
}
248248

249-
ga_append(&ga, NUL);
249+
// Only NUL-terminate when not returning NULL.
250+
if (ga.ga_data != NULL)
251+
ga_append(&ga, NUL);
250252
return (char_u *)ga.ga_data;
251253
#endif
252254
}

src/testdir/test_assert.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ func Test_assert_fails_in_timer()
381381
call StopVimInTerminal(buf)
382382
endfunc
383383

384+
" Check that a typed assert_equal() doesn't prepend an unnecessary ':'.
385+
func Test_assert_equal_typed()
386+
let after =<< trim END
387+
call feedkeys(":call assert_equal(0, 1)\<CR>", 't')
388+
call feedkeys(":call writefile(v:errors, 'Xerrors')\<CR>", 't')
389+
call feedkeys(":qa!\<CR>", 't')
390+
END
391+
call assert_equal(1, RunVim([], after, ''))
392+
call assert_equal(['Expected 0 but got 1'], readfile('Xerrors'))
393+
394+
call delete('Xerrors')
395+
endfunc
396+
384397
func Test_assert_beeps()
385398
new
386399
call assert_equal(0, assert_beeps('normal h'))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
1987,
737739
/**/
738740
1986,
739741
/**/

0 commit comments

Comments
 (0)