diff src/testdir/test_terminal.vim @ 13547:87a9c1be0ae3 v8.0.1647

patch 8.0.1647: terminal API may call any user function commit https://github.com/vim/vim/commit/2a77d21f7893ba14e682a3c5891d606f117a3f36 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 26 21:38:52 2018 +0200 patch 8.0.1647: terminal API may call any user function Problem: Terminal API may call a function not meant to be called by this API. Solution: Require the function to start with Tapi_.
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Mar 2018 21:45:07 +0200
parents 98d832e4e394
children 78ead137b2ad
line wrap: on
line diff
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -1072,24 +1072,28 @@ func Test_terminal_api_drop_oldwin()
   bwipe Xtextfile
 endfunc
 
-func TryThis(bufnum, arg)
+func Tapi_TryThis(bufnum, arg)
   let g:called_bufnum = a:bufnum
   let g:called_arg = a:arg
 endfunc
 
+func WriteApiCall(funcname)
+  " Use the title termcap entries to output the escape sequence.
+  call writefile([
+	\ 'set title',
+	\ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
+	\ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''',
+	\ 'redraw',
+	\ "set t_ts=",
+	\ ], 'Xscript')
+endfunc
+
 func Test_terminal_api_call()
   if !CanRunVimInTerminal()
     return
   endif
 
-  " Use the title termcap entries to output the escape sequence.
-  call writefile([
-	\ 'set title',
-	\ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
-	\ 'let &titlestring = ''["call","TryThis",["hello",123]]''',
-	\ 'redraw',
-	\ "set t_ts=",
-	\ ], 'Xscript')
+  call WriteApiCall('Tapi_TryThis')
   let buf = RunVimInTerminal('-S Xscript', {})
   call WaitFor({-> exists('g:called_bufnum')})
   call assert_equal(buf, g:called_bufnum)
@@ -1100,3 +1104,19 @@ func Test_terminal_api_call()
   unlet g:called_bufnum
   unlet g:called_arg
 endfunc
+
+func Test_terminal_api_call_fails()
+  if !CanRunVimInTerminal()
+    return
+  endif
+
+  call WriteApiCall('TryThis')
+  call ch_logfile('Xlog', 'w')
+  let buf = RunVimInTerminal('-S Xscript', {})
+  call WaitFor({-> string(readfile('Xlog')) =~ 'Invalid function name: TryThis'})
+
+  call StopVimInTerminal(buf)
+  call delete('Xscript')
+  call ch_logfile('', '')
+  call delete('Xlog')
+endfunc