2018-03-05 21:22:48 -07:00
|
|
|
local luv = require('luv')
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-11-15 07:45:23 -07:00
|
|
|
|
2017-03-15 15:28:37 -07:00
|
|
|
local clear, command, nvim, nvim_dir =
|
|
|
|
helpers.clear, helpers.command, helpers.nvim, helpers.nvim_dir
|
|
|
|
local eval, eq, retry =
|
|
|
|
helpers.eval, helpers.eq, helpers.retry
|
2017-12-29 13:13:21 -07:00
|
|
|
local ok = helpers.ok
|
2018-02-15 12:13:47 -07:00
|
|
|
local iswin = helpers.iswin
|
2015-11-15 07:45:23 -07:00
|
|
|
|
2016-08-15 16:42:12 -07:00
|
|
|
|
2015-11-15 07:45:23 -07:00
|
|
|
describe('TermClose event', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
nvim('set_option', 'shell', nvim_dir .. '/shell-test')
|
|
|
|
nvim('set_option', 'shellcmdflag', 'EXE')
|
|
|
|
end)
|
|
|
|
|
2017-05-28 18:17:12 -07:00
|
|
|
it('triggers when fast-exiting terminal job stops', function()
|
2017-03-15 15:28:37 -07:00
|
|
|
command('autocmd TermClose * let g:test_termclose = 23')
|
|
|
|
command('terminal')
|
|
|
|
command('call jobstop(b:terminal_job_id)')
|
2017-04-05 15:16:15 -07:00
|
|
|
retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
|
2015-11-15 07:45:23 -07:00
|
|
|
end)
|
2016-02-19 19:51:50 -07:00
|
|
|
|
2017-05-28 18:17:12 -07:00
|
|
|
it('triggers when long-running terminal job gets stopped', function()
|
2018-02-15 12:13:47 -07:00
|
|
|
nvim('set_option', 'shell', iswin() and 'cmd.exe' or 'sh')
|
2017-05-28 18:17:12 -07:00
|
|
|
command('autocmd TermClose * let g:test_termclose = 23')
|
|
|
|
command('terminal')
|
|
|
|
command('call jobstop(b:terminal_job_id)')
|
|
|
|
retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('kills job trapping SIGTERM', function()
|
2018-02-15 12:13:47 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
2017-05-28 18:17:12 -07:00
|
|
|
nvim('set_option', 'shell', 'sh')
|
|
|
|
nvim('set_option', 'shellcmdflag', '-c')
|
|
|
|
command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
|
|
|
|
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
|
|
|
|
.. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]])
|
|
|
|
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end)
|
|
|
|
|
2018-03-05 21:22:48 -07:00
|
|
|
luv.update_time()
|
|
|
|
local start = luv.now()
|
2017-05-28 18:17:12 -07:00
|
|
|
command('call jobstop(g:test_job)')
|
|
|
|
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
|
2018-03-05 21:22:48 -07:00
|
|
|
luv.update_time()
|
|
|
|
local duration = luv.now() - start
|
|
|
|
-- Nvim begins SIGTERM after KILL_TIMEOUT_MS.
|
|
|
|
ok(duration >= 2000)
|
|
|
|
ok(duration <= 4000) -- Epsilon for slow CI
|
2017-05-28 18:17:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('kills pty job trapping SIGHUP and SIGTERM', function()
|
2018-02-15 12:13:47 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
2017-05-28 18:17:12 -07:00
|
|
|
nvim('set_option', 'shell', 'sh')
|
|
|
|
nvim('set_option', 'shellcmdflag', '-c')
|
|
|
|
command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
|
|
|
|
.. [[ 'pty': 1,]]
|
|
|
|
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
|
|
|
|
.. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]])
|
|
|
|
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end)
|
|
|
|
|
2018-03-05 21:22:48 -07:00
|
|
|
luv.update_time()
|
|
|
|
local start = luv.now()
|
2017-05-28 18:17:12 -07:00
|
|
|
command('call jobstop(g:test_job)')
|
|
|
|
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
|
2018-03-05 21:22:48 -07:00
|
|
|
luv.update_time()
|
|
|
|
local duration = luv.now() - start
|
|
|
|
-- Nvim begins SIGKILL after (2 * KILL_TIMEOUT_MS).
|
|
|
|
ok(duration >= 4000)
|
|
|
|
ok(duration <= 7000) -- Epsilon for slow CI
|
2017-05-28 18:17:12 -07:00
|
|
|
end)
|
|
|
|
|
2016-02-19 19:51:50 -07:00
|
|
|
it('reports the correct <abuf>', function()
|
2017-03-15 15:28:37 -07:00
|
|
|
command('set hidden')
|
|
|
|
command('autocmd TermClose * let g:abuf = expand("<abuf>")')
|
|
|
|
command('edit foo')
|
|
|
|
command('edit bar')
|
2016-02-19 19:51:50 -07:00
|
|
|
eq(2, eval('bufnr("%")'))
|
2017-03-15 15:28:37 -07:00
|
|
|
|
|
|
|
command('terminal')
|
2017-04-05 15:16:15 -07:00
|
|
|
retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
|
2017-03-15 15:28:37 -07:00
|
|
|
|
|
|
|
command('buffer 1')
|
2017-04-05 15:16:15 -07:00
|
|
|
retry(nil, nil, function() eq(1, eval('bufnr("%")')) end)
|
2017-03-15 15:28:37 -07:00
|
|
|
|
|
|
|
command('3bdelete!')
|
2017-04-05 15:16:15 -07:00
|
|
|
retry(nil, nil, function() eq('3', eval('g:abuf')) end)
|
2016-02-19 19:51:50 -07:00
|
|
|
end)
|
2015-11-15 07:45:23 -07:00
|
|
|
end)
|