comparison src/testdir/test_terminal.vim @ 18170:4ac8161e92e0 v8.1.2080

patch 8.1.2080: the terminal API is limited and can't be disabled Commit: https://github.com/vim/vim/commit/d2842ea60bd608b7f9ec93c77d3f36a8e3bf5fe9 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 26 23:08:54 2019 +0200 patch 8.1.2080: the terminal API is limited and can't be disabled Problem: The terminal API is limited and can't be disabled. Solution: Add term_setapi() to set the function prefix. (Ozaki Kiichi, closes #2907)
author Bram Moolenaar <Bram@vim.org>
date Thu, 26 Sep 2019 23:15:05 +0200
parents 2416e1a887ca
children f6dcf7eabd26
comparison
equal deleted inserted replaced
18169:6ad8949a205d 18170:4ac8161e92e0
1351 endfunc 1351 endfunc
1352 1352
1353 func Test_terminal_api_call() 1353 func Test_terminal_api_call()
1354 CheckRunVimInTerminal 1354 CheckRunVimInTerminal
1355 1355
1356 call ch_logfile('logfile', 'w')
1357 unlet! g:called_bufnum
1358 unlet! g:called_arg
1359
1356 call WriteApiCall('Tapi_TryThis') 1360 call WriteApiCall('Tapi_TryThis')
1361
1362 " Default
1357 let buf = RunVimInTerminal('-S Xscript', {}) 1363 let buf = RunVimInTerminal('-S Xscript', {})
1358 call WaitFor({-> exists('g:called_bufnum')}) 1364 call WaitFor({-> exists('g:called_bufnum')})
1359 call assert_equal(buf, g:called_bufnum) 1365 call assert_equal(buf, g:called_bufnum)
1360 call assert_equal(['hello', 123], g:called_arg) 1366 call assert_equal(['hello', 123], g:called_arg)
1361
1362 call StopVimInTerminal(buf) 1367 call StopVimInTerminal(buf)
1368
1369 unlet! g:called_bufnum
1370 unlet! g:called_arg
1371
1372 " Enable explicitly
1373 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'Tapi_Try'})
1374 call WaitFor({-> exists('g:called_bufnum')})
1375 call assert_equal(buf, g:called_bufnum)
1376 call assert_equal(['hello', 123], g:called_arg)
1377 call StopVimInTerminal(buf)
1378
1379 unlet! g:called_bufnum
1380 unlet! g:called_arg
1381
1382 func! ApiCall_TryThis(bufnum, arg)
1383 let g:called_bufnum2 = a:bufnum
1384 let g:called_arg2 = a:arg
1385 endfunc
1386
1387 call WriteApiCall('ApiCall_TryThis')
1388
1389 " Use prefix match
1390 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'ApiCall_'})
1391 call WaitFor({-> exists('g:called_bufnum2')})
1392 call assert_equal(buf, g:called_bufnum2)
1393 call assert_equal(['hello', 123], g:called_arg2)
1394 call StopVimInTerminal(buf)
1395
1396 unlet! g:called_bufnum2
1397 unlet! g:called_arg2
1398
1363 call delete('Xscript') 1399 call delete('Xscript')
1364 unlet g:called_bufnum 1400 delfunction! ApiCall_TryThis
1365 unlet g:called_arg 1401 unlet! g:called_bufnum2
1402 unlet! g:called_arg2
1366 endfunc 1403 endfunc
1367 1404
1368 func Test_terminal_api_call_fails() 1405 func Test_terminal_api_call_fails()
1369 CheckRunVimInTerminal 1406 CheckRunVimInTerminal
1370 1407
1408 func! TryThis(bufnum, arg)
1409 let g:called_bufnum3 = a:bufnum
1410 let g:called_arg3 = a:arg
1411 endfunc
1412
1371 call WriteApiCall('TryThis') 1413 call WriteApiCall('TryThis')
1414
1415 unlet! g:called_bufnum3
1416 unlet! g:called_arg3
1417
1418 " Not permitted
1372 call ch_logfile('Xlog', 'w') 1419 call ch_logfile('Xlog', 'w')
1373 let buf = RunVimInTerminal('-S Xscript', {}) 1420 let buf = RunVimInTerminal('-S Xscript', {'term_api': ''})
1374 call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) 1421 call WaitForAssert({-> assert_match('Unpermitted function: TryThis', string(readfile('Xlog')))})
1375 1422 call assert_false(exists('g:called_bufnum3'))
1423 call assert_false(exists('g:called_arg3'))
1376 call StopVimInTerminal(buf) 1424 call StopVimInTerminal(buf)
1425
1426 " No match
1427 call ch_logfile('Xlog', 'w')
1428 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'TryThat'})
1429 call WaitFor({-> string(readfile('Xlog')) =~ 'Unpermitted function: TryThis'})
1430 call assert_false(exists('g:called_bufnum3'))
1431 call assert_false(exists('g:called_arg3'))
1432 call StopVimInTerminal(buf)
1433
1377 call delete('Xscript') 1434 call delete('Xscript')
1378 call ch_logfile('', '') 1435 call ch_logfile('')
1379 call delete('Xlog') 1436 call delete('Xlog')
1437 delfunction! TryThis
1438 unlet! g:called_bufnum3
1439 unlet! g:called_arg3
1380 endfunc 1440 endfunc
1381 1441
1382 let s:caught_e937 = 0 1442 let s:caught_e937 = 0
1383 1443
1384 func Tapi_Delete(bufnum, arg) 1444 func Tapi_Delete(bufnum, arg)
2059 2119
2060 call term_sendkeys(buf, "exit\r") 2120 call term_sendkeys(buf, "exit\r")
2061 exe buf . "bwipe!" 2121 exe buf . "bwipe!"
2062 call delete('Xtext') 2122 call delete('Xtext')
2063 endfunc 2123 endfunc
2124
2125 func Test_terminal_setapi_and_call()
2126 if !CanRunVimInTerminal()
2127 return
2128 endif
2129
2130 call WriteApiCall('Tapi_TryThis')
2131 call ch_logfile('Xlog', 'w')
2132
2133 unlet! g:called_bufnum
2134 unlet! g:called_arg
2135
2136 let buf = RunVimInTerminal('-S Xscript', {'term_api': 0})
2137 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
2138 call assert_false(exists('g:called_bufnum'))
2139 call assert_false(exists('g:called_arg'))
2140
2141 call term_setapi(buf, 'Tapi_TryThis')
2142 call term_sendkeys(buf, ":set notitle\<CR>")
2143 call term_sendkeys(buf, ":source Xscript\<CR>")
2144 call WaitFor({-> exists('g:called_bufnum')})
2145 call assert_equal(buf, g:called_bufnum)
2146 call assert_equal(['hello', 123], g:called_arg)
2147 call StopVimInTerminal(buf)
2148
2149 call delete('Xscript')
2150 call ch_logfile('')
2151 call delete('Xlog')
2152 unlet! g:called_bufnum
2153 unlet! g:called_arg
2154 endfunc