From 8262de0b489d5b9b5f6c99c1016b62d4e72a899b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 07:57:31 +0800 Subject: vim-patch:8.2.3739: in wrong directory when using win_execute() with 'acd' set Problem: In wrong directory when using win_execute() with 'acd' set. Solution: Restore the directory when returning to the window. (closes vim/vim#9276) https://github.com/vim/vim/commit/dea4a616376c6500894c16e26057ce16d7ef9f0e --- test/functional/legacy/autochdir_spec.lua | 42 +++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'test/functional/legacy/autochdir_spec.lua') diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua index 37a94476a0..75df1f8c55 100644 --- a/test/functional/legacy/autochdir_spec.lua +++ b/test/functional/legacy/autochdir_spec.lua @@ -1,8 +1,12 @@ local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches -local eval, command, call = helpers.eval, helpers.command, helpers.call -local exec_capture = helpers.exec_capture +local eval, command, call, meths = helpers.eval, helpers.command, helpers.call, helpers.meths +local source, exec_capture = helpers.source, helpers.exec_capture + +local function expected_empty() + eq({}, meths.get_vvar('errors')) +end describe('autochdir behavior', function() local dir = 'Xtest_functional_legacy_autochdir' @@ -25,6 +29,38 @@ describe('autochdir behavior', function() eq(dir, eval([[substitute(getcwd(), '.*[/\\]\(\k*\)', '\1', '')]])) end) + it(':file in win_execute() does not cause wrong directory', function() + command('cd '..dir) + source([[ + func Test_set_filename_other_window() + let cwd = getcwd() + call mkdir('Xa') + call mkdir('Xb') + call mkdir('Xc') + try + args Xa/aaa.txt Xb/bbb.txt + set acd + let winid = win_getid() + snext + call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', '')) + call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt') + call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', '')) + finally + set noacd + call chdir(cwd) + call delete('Xa', 'rf') + call delete('Xb', 'rf') + call delete('Xc', 'rf') + bwipe! aaa.txt + bwipe! bbb.txt + bwipe! ccc.txt + endtry + endfunc + ]]) + call('Test_set_filename_other_window') + expected_empty() + end) + it(':verbose pwd shows whether autochdir is used', function() local subdir = 'Xautodir' command('cd '..dir) @@ -51,6 +87,8 @@ describe('autochdir behavior', function() command('set noautochdir') matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) command('wincmd w') + matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + command('cd '..cwd) matches('%[global%].*'..dir, exec_capture('verbose pwd')) command('wincmd w') matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) -- cgit From da9bc96152efedfa80fabf0d1aabe52b7269181e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 08:11:52 +0800 Subject: vim-patch:8.2.3920: restoring directory after using another window is inefficient Problem: Restoring directory after using another window is inefficient. Solution: Only restore the directory for win_execute(). Apply 'autochdir' only when needed. https://github.com/vim/vim/commit/90c317f2246a7fb4bd4e3feb0778b53627bc9fad --- test/functional/legacy/autochdir_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/legacy/autochdir_spec.lua') diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua index 75df1f8c55..89651284b5 100644 --- a/test/functional/legacy/autochdir_spec.lua +++ b/test/functional/legacy/autochdir_spec.lua @@ -61,6 +61,20 @@ describe('autochdir behavior', function() expected_empty() end) + it('win_execute() does not change directory', function() + local subdir = 'Xfile' + command('cd '..dir) + command('set autochdir') + call('mkdir', subdir) + local winid = eval('win_getid()') + command('new '..subdir..'/file') + matches('.*'..dir..'[/\\]'..subdir, eval('getcwd()')) + command('cd ..') + matches('.*'..dir, eval('getcwd()')) + call('win_execute', winid, 'echo') + matches('.*'..dir, eval('getcwd()')) + end) + it(':verbose pwd shows whether autochdir is used', function() local subdir = 'Xautodir' command('cd '..dir) -- cgit From eb70540ff0385f3929b39f26faceaa2765f6949a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 09:11:23 +0800 Subject: vim-patch:8.2.4513: window-local directory is not applied if 'acd' fails Problem: Window-local directory is not applied if 'acd' fails. Solution: Don't call do_autochdir(). (closes vim/vim#9891) https://github.com/vim/vim/commit/b29ae159777028bb3266835b55716749ab0515be --- test/functional/legacy/autochdir_spec.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'test/functional/legacy/autochdir_spec.lua') diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua index 89651284b5..7d2fdfc26e 100644 --- a/test/functional/legacy/autochdir_spec.lua +++ b/test/functional/legacy/autochdir_spec.lua @@ -64,7 +64,7 @@ describe('autochdir behavior', function() it('win_execute() does not change directory', function() local subdir = 'Xfile' command('cd '..dir) - command('set autochdir') + command('set acd') call('mkdir', subdir) local winid = eval('win_getid()') command('new '..subdir..'/file') @@ -85,23 +85,28 @@ describe('autochdir behavior', function() command('split '..subdir..'/local.txt') command('lcd '..subdir) matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) - command('set autochdir') + command('set acd') command('wincmd w') matches('%[autochdir%].*'..dir, exec_capture('verbose pwd')) - command('lcd '..cwd) - matches('%[window%].*'..dir, exec_capture('verbose pwd')) command('tcd '..cwd) matches('%[tabpage%].*'..dir, exec_capture('verbose pwd')) command('cd '..cwd) matches('%[global%].*'..dir, exec_capture('verbose pwd')) + command('lcd '..cwd) + matches('%[window%].*'..dir, exec_capture('verbose pwd')) command('edit') matches('%[autochdir%].*'..dir, exec_capture('verbose pwd')) + command('enew') command('wincmd w') matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) - command('set noautochdir') - matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + command('wincmd w') + matches('%[window%].*'..dir, exec_capture('verbose pwd')) command('wincmd w') matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + command('set noacd') + matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + command('wincmd w') + matches('%[window%].*'..dir, exec_capture('verbose pwd')) command('cd '..cwd) matches('%[global%].*'..dir, exec_capture('verbose pwd')) command('wincmd w') -- cgit From 0442635a509b242794d43605b74090242e645096 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 09:25:58 +0800 Subject: test(autochdir_spec): use better patterns --- test/functional/legacy/autochdir_spec.lua | 39 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'test/functional/legacy/autochdir_spec.lua') diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua index 7d2fdfc26e..13cb6cd287 100644 --- a/test/functional/legacy/autochdir_spec.lua +++ b/test/functional/legacy/autochdir_spec.lua @@ -14,19 +14,20 @@ describe('autochdir behavior', function() before_each(function() lfs.mkdir(dir) clear() + command('set shellslash') end) after_each(function() helpers.rmdir(dir) end) - -- Tests vim/vim/777 without test_autochdir(). + -- Tests vim/vim#777 without test_autochdir(). it('sets filename', function() command('set acd') command('new') command('w '..dir..'/Xtest') eq('Xtest', eval("expand('%')")) - eq(dir, eval([[substitute(getcwd(), '.*[/\\]\(\k*\)', '\1', '')]])) + eq(dir, eval([[substitute(getcwd(), '.*/\(\k*\)', '\1', '')]])) end) it(':file in win_execute() does not cause wrong directory', function() @@ -68,11 +69,11 @@ describe('autochdir behavior', function() call('mkdir', subdir) local winid = eval('win_getid()') command('new '..subdir..'/file') - matches('.*'..dir..'[/\\]'..subdir, eval('getcwd()')) + matches(dir..'/'..subdir..'$', eval('getcwd()')) command('cd ..') - matches('.*'..dir, eval('getcwd()')) + matches(dir..'$', eval('getcwd()')) call('win_execute', winid, 'echo') - matches('.*'..dir, eval('getcwd()')) + matches(dir..'$', eval('getcwd()')) end) it(':verbose pwd shows whether autochdir is used', function() @@ -80,36 +81,36 @@ describe('autochdir behavior', function() command('cd '..dir) local cwd = eval('getcwd()') command('edit global.txt') - matches('%[global%].*'..dir, exec_capture('verbose pwd')) + matches('%[global%].*'..dir..'$', exec_capture('verbose pwd')) call('mkdir', subdir) command('split '..subdir..'/local.txt') command('lcd '..subdir) - matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + matches('%[window%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd')) command('set acd') command('wincmd w') - matches('%[autochdir%].*'..dir, exec_capture('verbose pwd')) + matches('%[autochdir%].*'..dir..'$', exec_capture('verbose pwd')) command('tcd '..cwd) - matches('%[tabpage%].*'..dir, exec_capture('verbose pwd')) + matches('%[tabpage%].*'..dir..'$', exec_capture('verbose pwd')) command('cd '..cwd) - matches('%[global%].*'..dir, exec_capture('verbose pwd')) + matches('%[global%].*'..dir..'$', exec_capture('verbose pwd')) command('lcd '..cwd) - matches('%[window%].*'..dir, exec_capture('verbose pwd')) + matches('%[window%].*'..dir..'$', exec_capture('verbose pwd')) command('edit') - matches('%[autochdir%].*'..dir, exec_capture('verbose pwd')) + matches('%[autochdir%].*'..dir..'$', exec_capture('verbose pwd')) command('enew') command('wincmd w') - matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + matches('%[autochdir%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd')) command('wincmd w') - matches('%[window%].*'..dir, exec_capture('verbose pwd')) + matches('%[window%].*'..dir..'$', exec_capture('verbose pwd')) command('wincmd w') - matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + matches('%[autochdir%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd')) command('set noacd') - matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + matches('%[autochdir%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd')) command('wincmd w') - matches('%[window%].*'..dir, exec_capture('verbose pwd')) + matches('%[window%].*'..dir..'$', exec_capture('verbose pwd')) command('cd '..cwd) - matches('%[global%].*'..dir, exec_capture('verbose pwd')) + matches('%[global%].*'..dir..'$', exec_capture('verbose pwd')) command('wincmd w') - matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd')) + matches('%[window%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd')) end) end) -- cgit