aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd/termxx_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/autocmd/termxx_spec.lua')
-rw-r--r--test/functional/autocmd/termxx_spec.lua158
1 files changed, 97 insertions, 61 deletions
diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua
index 332a936e3f..982edfa06a 100644
--- a/test/functional/autocmd/termxx_spec.lua
+++ b/test/functional/autocmd/termxx_spec.lua
@@ -1,15 +1,13 @@
-local luv = require('luv')
+local uv = vim.uv
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
-local clear, command, nvim, testprg =
- helpers.clear, helpers.command, helpers.nvim, helpers.testprg
-local eval, eq, neq, retry =
- helpers.eval, helpers.eq, helpers.neq, helpers.retry
+local clear, command, testprg = helpers.clear, helpers.command, helpers.testprg
+local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry
local matches = helpers.matches
local ok = helpers.ok
local feed = helpers.feed
-local meths = helpers.meths
+local api = helpers.api
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
local skip = helpers.skip
@@ -18,17 +16,19 @@ local is_os = helpers.is_os
describe('autocmd TermClose', function()
before_each(function()
clear()
- nvim('set_option_value', 'shell', testprg('shell-test'), {})
+ api.nvim_set_option_value('shell', testprg('shell-test'), {})
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
end)
local function test_termclose_delete_own_buf()
-- The terminal process needs to keep running so that TermClose isn't triggered immediately.
- nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
+ api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('autocmd TermClose * bdelete!')
command('terminal')
- matches('^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://',
- pcall_err(command, 'bdelete!'))
+ matches(
+ '^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://',
+ pcall_err(command, 'bdelete!')
+ )
assert_alive()
end
@@ -46,58 +46,76 @@ describe('autocmd TermClose', function()
command('autocmd TermClose * let g:test_termclose = 23')
command('terminal')
-- shell-test exits immediately.
- retry(nil, nil, function() neq(-1, eval('jobwait([&channel], 0)[0]')) end)
- retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
+ retry(nil, nil, function()
+ neq(-1, eval('jobwait([&channel], 0)[0]'))
+ end)
+ retry(nil, nil, function()
+ eq(23, eval('g:test_termclose'))
+ end)
end)
it('triggers when long-running terminal job gets stopped', function()
skip(is_os('win'))
- nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {})
+ api.nvim_set_option_value('shell', is_os('win') 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)
+ retry(nil, nil, function()
+ eq(23, eval('g:test_termclose'))
+ end)
end)
it('kills job trapping SIGTERM', function()
skip(is_os('win'))
- nvim('set_option_value', 'shell', 'sh', {})
- nvim('set_option_value', '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()
+ api.nvim_set_option_value('shell', 'sh', {})
+ api.nvim_set_option_value('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)
+
+ uv.update_time()
+ local start = uv.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
+ retry(nil, nil, function()
+ eq(1, eval('get(g:, "test_job_exited", 0)'))
+ end)
+ uv.update_time()
+ local duration = uv.now() - start
-- Nvim begins SIGTERM after KILL_TIMEOUT_MS.
ok(duration >= 2000)
- ok(duration <= 4000) -- Epsilon for slow CI
+ ok(duration <= 4000) -- Epsilon for slow CI
end)
it('kills PTY job trapping SIGHUP and SIGTERM', function()
skip(is_os('win'))
- nvim('set_option_value', 'shell', 'sh', {})
- nvim('set_option_value', '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()
+ api.nvim_set_option_value('shell', 'sh', {})
+ api.nvim_set_option_value('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)
+
+ uv.update_time()
+ local start = uv.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
+ retry(nil, nil, function()
+ eq(1, eval('get(g:, "test_job_exited", 0)'))
+ end)
+ uv.update_time()
+ local duration = uv.now() - start
-- Nvim begins SIGKILL after (2 * KILL_TIMEOUT_MS).
ok(duration >= 4000)
- ok(duration <= 7000) -- Epsilon for slow CI
+ ok(duration <= 7000) -- Epsilon for slow CI
end)
it('reports the correct <abuf>', function()
@@ -109,13 +127,19 @@ describe('autocmd TermClose', function()
eq(2, eval('bufnr("%")'))
command('terminal ls')
- retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
+ retry(nil, nil, function()
+ eq(3, eval('bufnr("%")'))
+ end)
command('buffer 1')
- retry(nil, nil, function() eq(1, eval('bufnr("%")')) end)
+ retry(nil, nil, function()
+ eq(1, eval('bufnr("%")'))
+ end)
command('3bdelete!')
- retry(nil, nil, function() eq('3', eval('g:abuf')) end)
+ retry(nil, nil, function()
+ eq('3', eval('g:abuf'))
+ end)
feed('<c-c>:qa!<cr>')
end)
@@ -124,10 +148,14 @@ describe('autocmd TermClose', function()
command('autocmd TermClose * let g:status = v:event.status')
command('terminal 0')
- retry(nil, nil, function() eq(0, eval('g:status')) end)
+ retry(nil, nil, function()
+ eq(0, eval('g:status'))
+ end)
command('terminal 42')
- retry(nil, nil, function() eq(42, eval('g:status')) end)
+ retry(nil, nil, function()
+ eq(42, eval('g:status'))
+ end)
end)
end)
@@ -141,27 +169,30 @@ it('autocmd TermEnter, TermLeave', function()
command('terminal')
feed('i')
- eq({ {'TermOpen', 'n'}, {'TermEnter', 't'}, }, eval('g:evs'))
+ eq({ { 'TermOpen', 'n' }, { 'TermEnter', 't' } }, eval('g:evs'))
feed([[<C-\><C-n>]])
feed('A')
- eq({ {'TermOpen', 'n'}, {'TermEnter', 't'}, {'TermLeave', 'n'}, {'TermEnter', 't'}, }, eval('g:evs'))
+ eq(
+ { { 'TermOpen', 'n' }, { 'TermEnter', 't' }, { 'TermLeave', 'n' }, { 'TermEnter', 't' } },
+ eval('g:evs')
+ )
-- TermLeave is also triggered by :quit.
command('split foo')
- feed('<Ignore>') -- Add input to separate two RPC requests
+ feed('<Ignore>') -- Add input to separate two RPC requests
command('wincmd w')
feed('i')
command('q!')
- feed('<Ignore>') -- Add input to separate two RPC requests
+ feed('<Ignore>') -- Add input to separate two RPC requests
eq({
- {'TermOpen', 'n'},
- {'TermEnter', 't'},
- {'TermLeave', 'n'},
- {'TermEnter', 't'},
- {'TermLeave', 'n'},
- {'TermEnter', 't'},
- {'TermClose', 't'},
- {'TermLeave', 'n'},
+ { 'TermOpen', 'n' },
+ { 'TermEnter', 't' },
+ { 'TermLeave', 'n' },
+ { 'TermEnter', 't' },
+ { 'TermLeave', 'n' },
+ { 'TermEnter', 't' },
+ { 'TermClose', 't' },
+ { 'TermLeave', 'n' },
}, eval('g:evs'))
end)
@@ -172,13 +203,18 @@ describe('autocmd TextChangedT', function()
it('works', function()
command('autocmd TextChangedT * ++once let g:called = 1')
thelpers.feed_data('a')
- retry(nil, nil, function() eq(1, meths.get_var('called')) end)
+ retry(nil, nil, function()
+ eq(1, api.nvim_get_var('called'))
+ end)
end)
it('cannot delete terminal buffer', function()
command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]])
thelpers.feed_data('a')
- screen:expect({any = 'E937: '})
- matches('^E937: Attempt to delete a buffer that is in use: term://', meths.get_vvar('errmsg'))
+ screen:expect({ any = 'E937: ' })
+ matches(
+ '^E937: Attempt to delete a buffer that is in use: term://',
+ api.nvim_get_vvar('errmsg')
+ )
end)
end)