aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/autocmd')
-rw-r--r--test/functional/autocmd/bufenter_spec.lua13
-rw-r--r--test/functional/autocmd/cmdline_spec.lua11
-rw-r--r--test/functional/autocmd/dirchanged_spec.lua7
-rw-r--r--test/functional/autocmd/filetype_spec.lua16
-rw-r--r--test/functional/autocmd/tabclose_spec.lua87
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua8
-rw-r--r--test/functional/autocmd/termclose_spec.lua30
7 files changed, 127 insertions, 45 deletions
diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua
index fef9838050..e14ddb3316 100644
--- a/test/functional/autocmd/bufenter_spec.lua
+++ b/test/functional/autocmd/bufenter_spec.lua
@@ -31,4 +31,17 @@ describe('autocmd BufEnter', function()
eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
end)
+
+ it('triggered by ":split normal|:help|:bw"', function()
+ command("split normal")
+ command("wincmd j")
+ command("helptags runtime/doc")
+ command("help")
+ command("wincmd L")
+ command("autocmd BufEnter normal let g:bufentered = 1")
+ command("bw")
+ eq(1, eval('bufnr("%")')) -- The cursor is back to the bottom window
+ eq(0, eval("exists('g:bufentered')")) -- The autocmd hasn't been triggered
+ end)
+
end)
diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua
index 8d56687f7d..3f0504d02f 100644
--- a/test/functional/autocmd/cmdline_spec.lua
+++ b/test/functional/autocmd/cmdline_spec.lua
@@ -5,7 +5,7 @@ local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local expect = helpers.expect
-local next_msg = helpers.next_message
+local next_msg = helpers.next_msg
local feed = helpers.feed
local meths = helpers.meths
@@ -59,24 +59,25 @@ describe('cmdline autocommands', function()
[1] = {bold = true, foreground = Screen.colors.Blue1},
[2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[3] = {bold = true, foreground = Screen.colors.SeaGreen4},
+ [4] = {bold = true, reverse = true},
})
command("autocmd CmdlineEnter * echoerr 'FAIL'")
command("autocmd CmdlineLeave * echoerr 'very error'")
feed(':')
screen:expect([[
+ |
{1:~ }|
{1:~ }|
{1:~ }|
- {1:~ }|
- {1:~ }|
+ {4: }|
: |
{2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} |
:^ |
]])
feed("put ='lorem ipsum'<cr>")
screen:expect([[
- {1:~ }|
- {1:~ }|
+ |
+ {4: }|
: |
{2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} |
:put ='lorem ipsum' |
diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua
index 63cf0bc410..7979e91a4c 100644
--- a/test/functional/autocmd/dirchanged_spec.lua
+++ b/test/functional/autocmd/dirchanged_spec.lua
@@ -154,4 +154,11 @@ describe('autocmd DirChanged', function()
eq('Failed to change directory', string.match(err, ': (.*)'))
eq({cwd=dirs[2], scope='global'}, eval('g:ev'))
end)
+
+ it('works when local to buffer', function()
+ command('let g:triggered = 0')
+ command('autocmd DirChanged <buffer> let g:triggered = 1')
+ command('cd '..dirs[1])
+ eq(1, eval('g:triggered'))
+ end)
end)
diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua
new file mode 100644
index 0000000000..e6fa7ab6bb
--- /dev/null
+++ b/test/functional/autocmd/filetype_spec.lua
@@ -0,0 +1,16 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local eval = helpers.eval
+local clear = helpers.clear
+local command = helpers.command
+
+describe('autocmd FileType', function()
+ before_each(clear)
+
+ it("is triggered by :help only once", function()
+ command("let g:foo = 0")
+ command("autocmd FileType help let g:foo = g:foo + 1")
+ command("help help")
+ assert.same(1, eval('g:foo'))
+ end)
+end)
diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua
index 1431c69589..b7c33dc3d8 100644
--- a/test/functional/autocmd/tabclose_spec.lua
+++ b/test/functional/autocmd/tabclose_spec.lua
@@ -2,32 +2,67 @@ local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
describe('TabClosed', function()
- describe('au TabClosed', function()
- describe('with * as <afile>', function()
- it('matches when closing any tab', function()
- clear()
- nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
- repeat
- nvim('command', 'tabnew')
- until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
- eq("\ntabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
- eq("\ntabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
- eq("\ntabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
- eq("\ntabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
- end)
- end)
- describe('with NR as <afile>', function()
- it('matches when closing a tab whose index is NR', function()
- nvim('command', 'au! TabClosed 2 echom "tabclosed:match"')
- repeat
- nvim('command', 'tabnew')
- until nvim('eval', 'tabpagenr()') == 5 -- current tab is now 5
- -- sanity check, we shouldn't match on tabs with numbers other than 2
- eq("\ntabclosed:5:5:4", nvim('command_output', 'tabclose'))
- -- close tab page 2, current tab is now 3
- eq("\ntabclosed:2:2:3\ntabclosed:match", nvim('command_output', '2tabclose'))
- end)
- end)
+ before_each(clear)
+
+ describe('au TabClosed', function()
+ describe('with * as <afile>', function()
+ it('matches when closing any tab', function()
+ nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
+ repeat
+ nvim('command', 'tabnew')
+ until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
+ eq("tabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
+ eq("tabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
+ eq("tabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
+ eq("tabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
+ end)
+
+ it('is triggered when closing a window via bdelete from another tab', function()
+ nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
+ nvim('command', '1tabedit Xtestfile')
+ nvim('command', '1tabedit Xtestfile')
+ nvim('command', 'normal! 1gt')
+ eq({1, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
+ eq("tabclosed:2:2:1\ntabclosed:2:2:1", nvim('command_output', 'bdelete Xtestfile'))
+ eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
+ end)
+
+ it('is triggered when closing a window via bdelete from current tab', function()
+ nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
+ nvim('command', 'file Xtestfile1')
+ nvim('command', '1tabedit Xtestfile2')
+ nvim('command', '1tabedit Xtestfile2')
+
+ -- Only one tab is closed, and the alternate file is used for the other.
+ eq({2, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
+ eq("tabclosed:2:2:2", nvim('command_output', 'bdelete Xtestfile2'))
+ eq('Xtestfile1', nvim('eval', 'bufname("")'))
+ end)
+ end)
+
+ describe('with NR as <afile>', function()
+ it('matches when closing a tab whose index is NR', function()
+ nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
+ nvim('command', 'au! TabClosed 2 echom "tabclosed:match"')
+ repeat
+ nvim('command', 'tabnew')
+ until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7
+ -- sanity check, we shouldn't match on tabs with numbers other than 2
+ eq("tabclosed:7:7:6", nvim('command_output', 'tabclose'))
+ -- close tab page 2, current tab is now 5
+ eq("tabclosed:2:2:5\ntabclosed:match", nvim('command_output', '2tabclose'))
+ end)
+ end)
+
+ describe('with close', function()
+ it('is triggered', function()
+ nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
+ nvim('command', 'tabedit Xtestfile')
+ eq({2, 2}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
+ eq("tabclosed:2:2:1", nvim('command_output', 'close'))
+ eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
+ end)
end)
+ end)
end)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
index bdbe677132..59cac07b34 100644
--- a/test/functional/autocmd/tabnewentered_spec.lua
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -7,14 +7,14 @@ describe('TabNewEntered', function()
it('matches when entering any new tab', function()
clear()
nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")')
- eq("\ntabnewentered:2:2", nvim('command_output', 'tabnew'))
- eq("\n\"test.x2\" [New File]\ntabnewentered:3:3", nvim('command_output', 'tabnew test.x2'))
+ eq("tabnewentered:2:2", nvim('command_output', 'tabnew'))
+ eq("tabnewentered:3:3", nvim('command_output', 'tabnew test.x2'))
end)
end)
describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function()
nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"')
- eq('\n"Xtest-tabnewentered" [New File]\ntabnewentered:4:4\ntabnewentered:match',
+ eq('tabnewentered:4:4\ntabnewentered:match',
nvim('command_output', 'tabnew Xtest-tabnewentered'))
end)
end)
@@ -24,7 +24,7 @@ describe('TabNewEntered', function()
nvim('command', 'au! TabNewEntered * echom "entered"')
nvim('command', 'tabnew test.x2')
nvim('command', 'split')
- eq('\nentered', nvim('command_output', 'execute "normal \\<C-W>T"'))
+ eq('entered', nvim('command_output', 'execute "normal \\<C-W>T"'))
end)
end)
end)
diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua
index c6c30494dd..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()
@@ -22,7 +24,7 @@ describe('TermClose event', function()
end)
it('triggers when long-running terminal job gets stopped', function()
- nvim('set_option', 'shell', 'sh')
+ 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)')
@@ -30,6 +32,7 @@ describe('TermClose event', function()
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', { ]]
@@ -37,14 +40,19 @@ describe('TermClose event', function()
.. [[ '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()
+ 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)
- local duration = os.time() - start
- eq(2, duration)
+ 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', { ]]
@@ -53,13 +61,15 @@ describe('TermClose event', function()
.. [[ '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()
+ 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)
- 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
+ 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()