aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/autocmd/dirchanged_spec.lua78
-rw-r--r--test/functional/provider/define_spec.lua4
-rw-r--r--test/functional/terminal/scrollback_spec.lua11
3 files changed, 67 insertions, 26 deletions
diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua
index 15196dbd44..63cf0bc410 100644
--- a/test/functional/autocmd/dirchanged_spec.lua
+++ b/test/functional/autocmd/dirchanged_spec.lua
@@ -20,29 +20,44 @@ describe('autocmd DirChanged', function()
before_each(function()
clear()
- command('autocmd DirChanged * let [g:event, g:scope, g:cdcount] = [copy(v:event), expand("<amatch>"), 1 + get(g:, "cdcount", 0)]')
+ command('autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] '
+ ..' = [getcwd(), copy(v:event), expand("<amatch>"), 1 + get(g:, "cdcount", 0)]')
+ -- Normalize path separators.
+ command([[autocmd DirChanged * let g:ev['cwd'] = substitute(g:ev['cwd'], '\\', '/', 'g')]])
+ command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]])
end)
it('sets v:event', function()
command('lcd '..dirs[1])
- eq({cwd=dirs[1], scope='window'}, eval('g:event'))
+ eq({cwd=dirs[1], scope='window'}, eval('g:ev'))
eq(1, eval('g:cdcount'))
command('tcd '..dirs[2])
- eq({cwd=dirs[2], scope='tab'}, eval('g:event'))
+ eq({cwd=dirs[2], scope='tab'}, eval('g:ev'))
eq(2, eval('g:cdcount'))
command('cd '..dirs[3])
- eq({cwd=dirs[3], scope='global'}, eval('g:event'))
+ eq({cwd=dirs[3], scope='global'}, eval('g:ev'))
eq(3, eval('g:cdcount'))
end)
+ it('sets getcwd() during event #6260', function()
+ command('lcd '..dirs[1])
+ eq(dirs[1], eval('g:getcwd'))
+
+ command('tcd '..dirs[2])
+ eq(dirs[2], eval('g:getcwd'))
+
+ command('cd '..dirs[3])
+ eq(dirs[3], eval('g:getcwd'))
+ end)
+
it('disallows recursion', function()
command('set shellslash')
-- Set up a _nested_ handler.
command('autocmd DirChanged * nested lcd '..dirs[3])
command('lcd '..dirs[1])
- eq({cwd=dirs[1], scope='window'}, eval('g:event'))
+ eq({cwd=dirs[1], scope='window'}, eval('g:ev'))
eq(1, eval('g:cdcount'))
-- autocmd changed to dirs[3], but did NOT trigger another DirChanged.
eq(dirs[3], eval('getcwd()'))
@@ -50,32 +65,32 @@ describe('autocmd DirChanged', function()
it('sets <amatch> to CWD "scope"', function()
command('lcd '..dirs[1])
- eq('window', eval('g:scope'))
+ eq('window', eval('g:amatch'))
command('tcd '..dirs[2])
- eq('tab', eval('g:scope'))
+ eq('tab', eval('g:amatch'))
command('cd '..dirs[3])
- eq('global', eval('g:scope'))
+ eq('global', eval('g:amatch'))
end)
it('does not trigger if :cd fails', function()
- command('let g:event = {}')
+ command('let g:ev = {}')
local status1, err1 = pcall(function()
command('lcd '..dirs[1] .. '/doesnotexist')
end)
- eq({}, eval('g:event'))
+ eq({}, eval('g:ev'))
local status2, err2 = pcall(function()
command('lcd '..dirs[2] .. '/doesnotexist')
end)
- eq({}, eval('g:event'))
+ eq({}, eval('g:ev'))
local status3, err3 = pcall(function()
command('lcd '..dirs[3] .. '/doesnotexist')
end)
- eq({}, eval('g:event'))
+ eq({}, eval('g:ev'))
eq(false, status1)
eq(false, status2)
@@ -90,24 +105,53 @@ describe('autocmd DirChanged', function()
command('set autochdir')
command('split '..dirs[1]..'/foo')
- eq({cwd=dirs[1], scope='window'}, eval('g:event'))
+ eq({cwd=dirs[1], scope='window'}, eval('g:ev'))
command('split '..dirs[2]..'/bar')
- eq({cwd=dirs[2], scope='window'}, eval('g:event'))
+ eq({cwd=dirs[2], scope='window'}, eval('g:ev'))
+
+ eq(2, eval('g:cdcount'))
+ end)
+
+ it("is triggered by switching to win/tab with different CWD #6054", function()
+ command('lcd '..dirs[3]) -- window 3
+ command('split '..dirs[2]..'/foo') -- window 2
+ command('lcd '..dirs[2])
+ command('split '..dirs[1]..'/bar') -- window 1
+ command('lcd '..dirs[1])
+
+ command('2wincmd w') -- window 2
+ eq({cwd=dirs[2], scope='window'}, eval('g:ev'))
+
+ eq(4, eval('g:cdcount'))
+ command('tabnew') -- tab 2 (tab-local CWD)
+ eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tcd '..dirs[3])
+ command('tabnext') -- tab 1 (no tab-local CWD)
+ eq({cwd=dirs[2], scope='window'}, eval('g:ev'))
+ command('tabnext') -- tab 2
+ eq({cwd=dirs[3], scope='tab'}, eval('g:ev'))
+ eq(7, eval('g:cdcount'))
+
+ command('tabnext') -- tab 1
+ command('3wincmd w') -- window 3
+ eq(9, eval('g:cdcount'))
+ command('tabnext') -- tab 2 (has the *same* CWD)
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
end)
it('is triggered by nvim_set_current_dir()', function()
request('nvim_set_current_dir', dirs[1])
- eq({cwd=dirs[1], scope='global'}, eval('g:event'))
+ eq({cwd=dirs[1], scope='global'}, eval('g:ev'))
request('nvim_set_current_dir', dirs[2])
- eq({cwd=dirs[2], scope='global'}, eval('g:event'))
+ eq({cwd=dirs[2], scope='global'}, eval('g:ev'))
local status, err = pcall(function()
request('nvim_set_current_dir', '/doesnotexist')
end)
eq(false, status)
eq('Failed to change directory', string.match(err, ': (.*)'))
- eq({cwd=dirs[2], scope='global'}, eval('g:event'))
+ eq({cwd=dirs[2], scope='global'}, eval('g:ev'))
end)
end)
diff --git a/test/functional/provider/define_spec.lua b/test/functional/provider/define_spec.lua
index b0363eb435..51a8831274 100644
--- a/test/functional/provider/define_spec.lua
+++ b/test/functional/provider/define_spec.lua
@@ -3,7 +3,6 @@ local eval, command, nvim = helpers.eval, helpers.command, helpers.nvim
local eq, run, stop = helpers.eq, helpers.run, helpers.stop
local clear = helpers.clear
-
local function get_prefix(sync)
if sync then
return 'sync'
@@ -11,12 +10,10 @@ local function get_prefix(sync)
return 'async'
end
-
local function call(fn, arguments)
command('call '..fn..'('..arguments..')')
end
-
local function clear_and_init(init)
return function()
clear()
@@ -26,7 +23,6 @@ local function clear_and_init(init)
end
end
-
local function runx(sync, handler, on_setup)
local function setup_cb(...)
on_setup(...)
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index 930d0cf58b..81649f2bde 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -368,10 +368,11 @@ describe("'scrollback' option", function()
clear()
end)
- local function expect_lines(expected)
+ local function expect_lines(expected, epsilon)
+ local ep = epsilon and epsilon or 0
local actual = eval("line('$')")
- if expected ~= actual then
- error('expected: '..expected..', actual: '..tostring(actual))
+ if expected > actual + ep and expected < actual - ep then
+ error('expected (+/- '..ep..'): '..expected..', actual: '..tostring(actual))
end
end
@@ -399,12 +400,12 @@ describe("'scrollback' option", function()
screen:expect('line30 ', nil, nil, nil, true)
- retry(nil, nil, function() expect_lines(33) end)
+ retry(nil, nil, function() expect_lines(33, 2) end)
curbufmeths.set_option('scrollback', 10)
wait()
retry(nil, nil, function() expect_lines(16) end)
curbufmeths.set_option('scrollback', 10000)
- eq(16, eval("line('$')"))
+ retry(nil, nil, function() expect_lines(16) end)
-- Terminal job data is received asynchronously, may happen before the
-- 'scrollback' option is synchronized with the internal sb_buffer.
command('sleep 100m')