aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
committerZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
commitc49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch)
treeb7e59c416d1435725c65f8952b6e55c70544d97e /test/functional/autocmd
parent62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff)
parent27a577586eace687c47e7398845178208cae524a (diff)
downloadrneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'test/functional/autocmd')
-rw-r--r--test/functional/autocmd/autocmd_spec.lua26
-rw-r--r--test/functional/autocmd/bufenter_spec.lua3
-rw-r--r--test/functional/autocmd/cmdline_spec.lua117
-rw-r--r--test/functional/autocmd/termclose_spec.lua55
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua30
5 files changed, 202 insertions, 29 deletions
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua
index c38bd75c69..8ee9462a8d 100644
--- a/test/functional/autocmd/autocmd_spec.lua
+++ b/test/functional/autocmd/autocmd_spec.lua
@@ -1,9 +1,13 @@
local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
-local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
+local clear = helpers.clear
+local meths = helpers.meths
+local expect = helpers.expect
+local command = helpers.command
+local exc_exec = helpers.exc_exec
+local curbufmeths = helpers.curbufmeths
describe('autocmds:', function()
before_each(clear)
@@ -33,4 +37,22 @@ describe('autocmds:', function()
it('v:vim_did_enter is 1 after VimEnter', function()
eq(1, eval('v:vim_did_enter'))
end)
+
+ describe('BufLeave autocommand', function()
+ it('can wipe out the buffer created by :edit which triggered autocmd',
+ function()
+ meths.set_option('hidden', true)
+ curbufmeths.set_lines(0, 1, false, {
+ 'start of test file xx',
+ 'end of test file xx'})
+
+ command('autocmd BufLeave * bwipeout yy')
+ eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy',
+ exc_exec('edit yy'))
+
+ expect([[
+ start of test file xx
+ end of test file xx]])
+ end)
+ end)
end)
diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua
index ccbcdf5c5e..fef9838050 100644
--- a/test/functional/autocmd/bufenter_spec.lua
+++ b/test/functional/autocmd/bufenter_spec.lua
@@ -4,7 +4,6 @@ local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
-local execute = helpers.execute
local request = helpers.request
local source = helpers.source
@@ -28,7 +27,7 @@ describe('autocmd BufEnter', function()
endtry
endfunction
]])
- execute("call Test()")
+ command("call Test()")
eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
end)
diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua
new file mode 100644
index 0000000000..8d56687f7d
--- /dev/null
+++ b/test/functional/autocmd/cmdline_spec.lua
@@ -0,0 +1,117 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local expect = helpers.expect
+local next_msg = helpers.next_message
+local feed = helpers.feed
+local meths = helpers.meths
+
+describe('cmdline autocommands', function()
+ local channel
+ before_each(function()
+ clear()
+ channel = meths.get_api_info()[1]
+ meths.set_var("channel",channel)
+ command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)")
+ command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)")
+ command("autocmd CmdWinEnter * call rpcnotify(g:channel, 'CmdWinEnter', v:event)")
+ command("autocmd CmdWinLeave * call rpcnotify(g:channel, 'CmdWinLeave', v:event)")
+ end)
+
+ it('works', function()
+ feed(':')
+ eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg())
+ feed('redraw<cr>')
+ eq({'notification', 'CmdlineLeave',
+ {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg())
+
+ feed(':')
+ eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg())
+
+ -- note: feed('bork<c-c>') might not consume 'bork'
+ -- due to out-of-band interupt handling
+ feed('bork<esc>')
+ eq({'notification', 'CmdlineLeave',
+ {{cmdtype=':', cmdlevel=1, abort=true}}}, next_msg())
+ end)
+
+ it('can abort cmdline', function()
+ command("autocmd CmdlineLeave * let v:event.abort= len(getcmdline())>15")
+ feed(":put! ='ok'<cr>")
+ expect([[
+ ok
+ ]])
+
+ feed(":put! ='blah blah'<cr>")
+ expect([[
+ ok
+ ]])
+ end)
+
+ it('handles errors correctly', function()
+ clear()
+ local screen = Screen.new(72, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1},
+ [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
+ [3] = {bold = true, foreground = Screen.colors.SeaGreen4},
+ })
+ command("autocmd CmdlineEnter * echoerr 'FAIL'")
+ command("autocmd CmdlineLeave * echoerr 'very error'")
+ feed(':')
+ screen:expect([[
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} |
+ :^ |
+ ]])
+ feed("put ='lorem ipsum'<cr>")
+ screen:expect([[
+ {1:~ }|
+ {1:~ }|
+ : |
+ {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} |
+ :put ='lorem ipsum' |
+ {2:E5500: autocmd has thrown an exception: Vim(echoerr):very error} |
+ |
+ {3:Press ENTER or type command to continue}^ |
+ ]])
+
+ feed('<cr>')
+ screen:expect([[
+ |
+ ^lorem ipsum |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end)
+
+ it('works with nested cmdline', function()
+ feed(':')
+ eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg())
+ feed('<c-r>=')
+ eq({'notification', 'CmdlineEnter', {{cmdtype='=', cmdlevel=2}}}, next_msg())
+ feed('<c-f>')
+ eq({'notification', 'CmdWinEnter', {{}}}, next_msg())
+ feed(':')
+ eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=3}}}, next_msg())
+ feed('<c-c>')
+ eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=3, abort=true}}}, next_msg())
+ feed('<c-c>')
+ eq({'notification', 'CmdWinLeave', {{}}}, next_msg())
+ feed('1+2<cr>')
+ eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg())
+ end)
+end)
diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua
index ecda1bffb7..c6c30494dd 100644
--- a/test/functional/autocmd/termclose_spec.lua
+++ b/test/functional/autocmd/termclose_spec.lua
@@ -14,17 +14,52 @@ describe('TermClose event', function()
nvim('set_option', 'shellcmdflag', 'EXE')
end)
- local function eq_err(expected, actual)
- if expected ~= actual then
- error('expected: '..tostring(expected)..', actual: '..tostring(actual))
- end
- end
+ 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 terminal job ends', function()
+ it('triggers when long-running terminal job gets stopped', function()
+ nvim('set_option', 'shell', 'sh')
command('autocmd TermClose * let g:test_termclose = 23')
command('terminal')
command('call jobstop(b:terminal_job_id)')
- retry(nil, nil, function() eq_err(23, eval('g:test_termclose')) end)
+ retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
+ end)
+
+ it('kills job trapping SIGTERM', function()
+ 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)
+
+ local start = os.time()
+ command('call jobstop(g:test_job)')
+ retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
+ local duration = os.time() - start
+ eq(2, duration)
+ end)
+
+ it('kills pty job trapping SIGHUP and SIGTERM', function()
+ 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)
+
+ local start = os.time()
+ command('call jobstop(g:test_job)')
+ retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
+ local duration = os.time() - start
+ -- nvim starts sending kill after 2*KILL_TIMEOUT_MS
+ helpers.ok(4 <= duration)
+ helpers.ok(duration <= 7) -- <= 4 + delta because of slow CI
end)
it('reports the correct <abuf>', function()
@@ -35,12 +70,12 @@ describe('TermClose event', function()
eq(2, eval('bufnr("%")'))
command('terminal')
- retry(nil, nil, function() eq_err(3, eval('bufnr("%")')) end)
+ retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
command('buffer 1')
- retry(nil, nil, function() eq_err(1, eval('bufnr("%")')) end)
+ retry(nil, nil, function() eq(1, eval('bufnr("%")')) end)
command('3bdelete!')
- retry(nil, nil, function() eq_err('3', eval('g:abuf')) end)
+ retry(nil, nil, function() eq('3', eval('g:abuf')) end)
end)
end)
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
index bd5f1912c5..486a3346b1 100644
--- a/test/functional/autocmd/textyankpost_spec.lua
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
-local feed, execute, expect, command = helpers.feed, helpers.execute, helpers.expect, helpers.command
+local feed, command, expect = helpers.feed, helpers.command, helpers.expect
local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq
describe('TextYankPost', function()
@@ -8,11 +8,11 @@ describe('TextYankPost', function()
clear()
-- emulate the clipboard so system clipboard isn't affected
- execute('let &rtp = "test/functional/fixtures,".&rtp')
+ command('let &rtp = "test/functional/fixtures,".&rtp')
- execute('let g:count = 0')
- execute('autocmd TextYankPost * let g:event = copy(v:event)')
- execute('autocmd TextYankPost * let g:count += 1')
+ command('let g:count = 0')
+ command('autocmd TextYankPost * let g:event = copy(v:event)')
+ command('autocmd TextYankPost * let g:count += 1')
curbufmeths.set_lines(0, -1, true, {
'foo\0bar',
@@ -61,27 +61,27 @@ describe('TextYankPost', function()
regtype = 'V'
}, eval('g:event'))
- execute('set debug=msg')
+ command('set debug=msg')
-- the regcontents should not be changed without copy.
local status, err = pcall(command,'call extend(g:event.regcontents, ["more text"])')
eq(status,false)
neq(nil, string.find(err, ':E742:'))
-- can't mutate keys inside the autocommand
- execute('autocmd! TextYankPost * let v:event.regcontents = 0')
+ command('autocmd! TextYankPost * let v:event.regcontents = 0')
status, err = pcall(command,'normal yy')
eq(status,false)
neq(nil, string.find(err, ':E46:'))
-- can't add keys inside the autocommand
- execute('autocmd! TextYankPost * let v:event.mykey = 0')
+ command('autocmd! TextYankPost * let v:event.mykey = 0')
status, err = pcall(command,'normal yy')
eq(status,false)
neq(nil, string.find(err, ':E742:'))
end)
it('is not invoked recursively', function()
- execute('autocmd TextYankPost * normal "+yy')
+ command('autocmd TextYankPost * normal "+yy')
feed('yy')
eq({
operator = 'y',
@@ -134,7 +134,7 @@ describe('TextYankPost', function()
feed('"_yy')
eq(0, eval('g:count'))
- execute('delete _')
+ command('delete _')
eq(0, eval('g:count'))
end)
@@ -155,7 +155,7 @@ describe('TextYankPost', function()
regtype = 'V'
}, eval('g:event'))
- execute("set clipboard=unnamed")
+ command("set clipboard=unnamed")
-- regname still shows the name the user requested
feed('yy')
@@ -176,7 +176,7 @@ describe('TextYankPost', function()
end)
it('works with Ex commands', function()
- execute('1delete +')
+ command('1delete +')
eq({
operator = 'd',
regcontents = { 'foo\nbar' },
@@ -185,7 +185,7 @@ describe('TextYankPost', function()
}, eval('g:event'))
eq(1, eval('g:count'))
- execute('yank')
+ command('yank')
eq({
operator = 'y',
regcontents = { 'baz text' },
@@ -194,7 +194,7 @@ describe('TextYankPost', function()
}, eval('g:event'))
eq(2, eval('g:count'))
- execute('normal yw')
+ command('normal yw')
eq({
operator = 'y',
regcontents = { 'baz ' },
@@ -203,7 +203,7 @@ describe('TextYankPost', function()
}, eval('g:event'))
eq(3, eval('g:count'))
- execute('normal! dd')
+ command('normal! dd')
eq({
operator = 'd',
regcontents = { 'baz text' },