Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
13546:dd1b0d2a49ae | 13547:87a9c1be0ae3 |
---|---|
1070 call StopVimInTerminal(buf) | 1070 call StopVimInTerminal(buf) |
1071 call delete('Xscript') | 1071 call delete('Xscript') |
1072 bwipe Xtextfile | 1072 bwipe Xtextfile |
1073 endfunc | 1073 endfunc |
1074 | 1074 |
1075 func TryThis(bufnum, arg) | 1075 func Tapi_TryThis(bufnum, arg) |
1076 let g:called_bufnum = a:bufnum | 1076 let g:called_bufnum = a:bufnum |
1077 let g:called_arg = a:arg | 1077 let g:called_arg = a:arg |
1078 endfunc | 1078 endfunc |
1079 | 1079 |
1080 func Test_terminal_api_call() | 1080 func WriteApiCall(funcname) |
1081 if !CanRunVimInTerminal() | |
1082 return | |
1083 endif | |
1084 | |
1085 " Use the title termcap entries to output the escape sequence. | 1081 " Use the title termcap entries to output the escape sequence. |
1086 call writefile([ | 1082 call writefile([ |
1087 \ 'set title', | 1083 \ 'set title', |
1088 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', | 1084 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
1089 \ 'let &titlestring = ''["call","TryThis",["hello",123]]''', | 1085 \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''', |
1090 \ 'redraw', | 1086 \ 'redraw', |
1091 \ "set t_ts=", | 1087 \ "set t_ts=", |
1092 \ ], 'Xscript') | 1088 \ ], 'Xscript') |
1089 endfunc | |
1090 | |
1091 func Test_terminal_api_call() | |
1092 if !CanRunVimInTerminal() | |
1093 return | |
1094 endif | |
1095 | |
1096 call WriteApiCall('Tapi_TryThis') | |
1093 let buf = RunVimInTerminal('-S Xscript', {}) | 1097 let buf = RunVimInTerminal('-S Xscript', {}) |
1094 call WaitFor({-> exists('g:called_bufnum')}) | 1098 call WaitFor({-> exists('g:called_bufnum')}) |
1095 call assert_equal(buf, g:called_bufnum) | 1099 call assert_equal(buf, g:called_bufnum) |
1096 call assert_equal(['hello', 123], g:called_arg) | 1100 call assert_equal(['hello', 123], g:called_arg) |
1097 | 1101 |
1098 call StopVimInTerminal(buf) | 1102 call StopVimInTerminal(buf) |
1099 call delete('Xscript') | 1103 call delete('Xscript') |
1100 unlet g:called_bufnum | 1104 unlet g:called_bufnum |
1101 unlet g:called_arg | 1105 unlet g:called_arg |
1102 endfunc | 1106 endfunc |
1107 | |
1108 func Test_terminal_api_call_fails() | |
1109 if !CanRunVimInTerminal() | |
1110 return | |
1111 endif | |
1112 | |
1113 call WriteApiCall('TryThis') | |
1114 call ch_logfile('Xlog', 'w') | |
1115 let buf = RunVimInTerminal('-S Xscript', {}) | |
1116 call WaitFor({-> string(readfile('Xlog')) =~ 'Invalid function name: TryThis'}) | |
1117 | |
1118 call StopVimInTerminal(buf) | |
1119 call delete('Xscript') | |
1120 call ch_logfile('', '') | |
1121 call delete('Xlog') | |
1122 endfunc |