]> granicus.if.org Git - vim/commitdiff
patch 8.1.0086: no tests for libcall() and libcallnr() v8.1.0086
authorBram Moolenaar <Bram@vim.org>
Tue, 19 Jun 2018 17:46:06 +0000 (19:46 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Jun 2018 17:46:06 +0000 (19:46 +0200)
Problem:    No tests for libcall() and libcallnr().
Solution:   Add tests. (Dominique Pelle, closes #2982)

src/testdir/test_functions.vim
src/version.c

index b76bc78e79dbb74e934f7f4e19e5ba146d6b26d7..7efbbe8829c571a98b61cdaef446416799657299 100644 (file)
@@ -948,3 +948,39 @@ func Test_reg_executing_and_recording()
   delfunc s:save_reg_stat
   unlet s:reg_stat
 endfunc
+
+func Test_libcall_libcallnr()
+  if !has('libcall')
+    return
+  endif
+
+  if has('win32')
+    let libc = 'msvcrt.dll'
+  elseif has('mac')
+    let libc = 'libSystem.B.dylib'
+  else
+    " On Unix, libc.so can be in various places.
+    " Interestingly, using an empty string for the 1st argument of libcall
+    " allows to call functions from libc which is not documented.
+    let libc = ''
+  endif
+
+  if has('win32')
+    call assert_equal($USERPROFILE, libcall(libc, 'getenv', 'USERPROFILE'))
+  else
+    call assert_equal($HOME, libcall(libc, 'getenv', 'HOME'))
+  endif
+
+  " If function returns NULL, libcall() should return an empty string.
+  call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT'))
+
+  " Test libcallnr() with string and integer argument.
+  call assert_equal(4, libcallnr(libc, 'strlen', 'abcd'))
+  call assert_equal(char2nr('A'), libcallnr(libc, 'toupper', char2nr('a')))
+
+  call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:')
+  call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:')
+
+  call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:')
+  call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:')
+endfunc
index 12ba8c41cd9267c269e7aebab7adce1a0356861f..bd3bca11cb8b723b037783fa9e12ca2b46bd4c12 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    86,
 /**/
     85,
 /**/