aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd/termclose_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/autocmd/termclose_spec.lua')
-rw-r--r--test/functional/autocmd/termclose_spec.lua55
1 files changed, 53 insertions, 2 deletions
diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua
index d4beab22e4..0804579a4f 100644
--- a/test/functional/autocmd/termclose_spec.lua
+++ b/test/functional/autocmd/termclose_spec.lua
@@ -1,11 +1,13 @@
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
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
+local ok = helpers.ok
+local iswin = helpers.iswin
-if helpers.pending_win32(pending) then return end
describe('TermClose event', function()
before_each(function()
@@ -14,13 +16,62 @@ describe('TermClose event', function()
nvim('set_option', 'shellcmdflag', 'EXE')
end)
- it('triggers when terminal job ends', function()
+ it('triggers when fast-exiting terminal job stops', function()
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('triggers when long-running terminal job gets stopped', function()
+ nvim('set_option', 'shell', iswin() and 'cmd.exe' or 'sh')
+ 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()
+ if helpers.pending_win32(pending) then return end
+ 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)
+
+ luv.update_time()
+ local start = luv.now()
+ command('call jobstop(g:test_job)')
+ retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
+ 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
+ end)
+
+ it('kills pty job trapping SIGHUP and SIGTERM', function()
+ if helpers.pending_win32(pending) then return end
+ 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)
+
+ luv.update_time()
+ local start = luv.now()
+ command('call jobstop(g:test_job)')
+ retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
+ 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
+ end)
+
it('reports the correct <abuf>', function()
command('set hidden')
command('autocmd TermClose * let g:abuf = expand("<abuf>")')