Skip to content

Commit 1ceebb4

Browse files
committed
patch 8.1.0086: no tests for libcall() and libcallnr()
Problem: No tests for libcall() and libcallnr(). Solution: Add tests. (Dominique Pelle, closes #2982)
1 parent 5f8f2d3 commit 1ceebb4

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/testdir/test_functions.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,3 +948,39 @@ func Test_reg_executing_and_recording()
948948
delfunc s:save_reg_stat
949949
unlet s:reg_stat
950950
endfunc
951+
952+
func Test_libcall_libcallnr()
953+
if !has('libcall')
954+
return
955+
endif
956+
957+
if has('win32')
958+
let libc = 'msvcrt.dll'
959+
elseif has('mac')
960+
let libc = 'libSystem.B.dylib'
961+
else
962+
" On Unix, libc.so can be in various places.
963+
" Interestingly, using an empty string for the 1st argument of libcall
964+
" allows to call functions from libc which is not documented.
965+
let libc = ''
966+
endif
967+
968+
if has('win32')
969+
call assert_equal($USERPROFILE, libcall(libc, 'getenv', 'USERPROFILE'))
970+
else
971+
call assert_equal($HOME, libcall(libc, 'getenv', 'HOME'))
972+
endif
973+
974+
" If function returns NULL, libcall() should return an empty string.
975+
call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT'))
976+
977+
" Test libcallnr() with string and integer argument.
978+
call assert_equal(4, libcallnr(libc, 'strlen', 'abcd'))
979+
call assert_equal(char2nr('A'), libcallnr(libc, 'toupper', char2nr('a')))
980+
981+
call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:')
982+
call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:')
983+
984+
call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:')
985+
call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:')
986+
endfunc

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
86,
764766
/**/
765767
85,
766768
/**/

0 commit comments

Comments
 (0)