vim-patch:8.1.0604: autocommand test fails on MS-Windows

Problem:    Autocommand test fails on MS-Windows.
Solution:   Use pathcmp() instead of strcmp() to check if a directory differs.
9eb76af451
This commit is contained in:
zeertzjq 2021-10-17 22:04:53 +08:00
parent e91dee5c21
commit 57651df9c1
4 changed files with 70 additions and 11 deletions

View File

@ -7811,7 +7811,7 @@ void ex_cd(exarg_T *eap)
break;
}
bool dir_differs = prev_dir == NULL || STRCMP(prev_dir, new_dir) != 0;
bool dir_differs = prev_dir == NULL || pathcmp((char *)prev_dir, (char *)new_dir, -1) != 0;
if (dir_differs && vim_chdir(new_dir)) {
EMSG(_(e_failed));
} else {

View File

@ -1620,6 +1620,13 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
abort();
}
#ifdef BACKSLASH_IN_FILENAME
char new_dir_buf[MAXPATHL];
STRCPY(new_dir_buf, new_dir);
slash_adjust(new_dir_buf);
new_dir = new_dir_buf;
#endif
tv_dict_add_str(dict, S_LEN("scope"), buf); // -V614
tv_dict_add_str(dict, S_LEN("cwd"), new_dir);
tv_dict_add_bool(dict, S_LEN("changed_window"), cause == kCdCauseWindow);
@ -1659,14 +1666,10 @@ int vim_chdirfile(char_u *fname, CdCause cause)
NameBuff[0] = NUL;
}
if (os_chdir(dir) != 0) {
return FAIL;
}
#ifdef BACKSLASH_IN_FILENAME
slash_adjust((char_u *)dir);
#endif
if (cause != kCdCauseOther && !strequal(dir, (char *)NameBuff)) {
if (cause != kCdCauseOther && pathcmp(dir, (char *)NameBuff, -1) != 0) {
if (os_chdir(dir) != 0) {
return FAIL;
}
do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
}

View File

@ -23,6 +23,7 @@
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/hashtab.h"
#include "nvim/main.h"
#include "nvim/mark.h"
@ -4540,7 +4541,7 @@ static void win_enter_ext(win_T *const wp, const int flags)
}
}
if (os_chdir(new_dir) == 0) {
if (!p_acd && !strequal(new_dir, cwd)) {
if (!p_acd && pathcmp(new_dir, cwd, -1) != 0) {
do_autocmd_dirchanged(new_dir, curwin->w_localdir
? kCdScopeWindow : kCdScopeTab, kCdCauseWindow);
}
@ -4550,7 +4551,7 @@ static void win_enter_ext(win_T *const wp, const int flags)
// Window doesn't have a local directory and we are not in the global
// directory: Change to the global directory.
if (os_chdir((char *)globaldir) == 0) {
if (!p_acd && !strequal((char *)globaldir, cwd)) {
if (!p_acd && pathcmp((char *)globaldir, cwd, -1) != 0) {
do_autocmd_dirchanged((char *)globaldir, kCdScopeGlobal, kCdCauseWindow);
}
}

View File

@ -6,6 +6,7 @@ local command = h.command
local eq = h.eq
local eval = h.eval
local request = h.request
local iswin = h.iswin
describe('autocmd DirChanged', function()
local curdir = string.gsub(lfs.currentdir(), '\\', '/')
@ -14,6 +15,11 @@ describe('autocmd DirChanged', function()
curdir .. '/Xtest-functional-autocmd-dirchanged.dir2',
curdir .. '/Xtest-functional-autocmd-dirchanged.dir3',
}
local win_dirs = {
curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR1',
curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR2',
curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3',
}
setup(function() for _, dir in pairs(dirs) do h.mkdir(dir) end end)
teardown(function() for _, dir in pairs(dirs) do h.rmdir(dir) end end)
@ -122,6 +128,12 @@ describe('autocmd DirChanged', function()
eq({}, eval('g:ev'))
eq(1, eval('g:cdcount'))
if iswin() then
command('lcd '..win_dirs[1])
eq({}, eval('g:ev'))
eq(1, eval('g:cdcount'))
end
command('tcd '..dirs[2])
eq({cwd=dirs[2], scope='tab', changed_window=false}, eval('g:ev'))
eq(2, eval('g:cdcount'))
@ -130,6 +142,12 @@ describe('autocmd DirChanged', function()
eq({}, eval('g:ev'))
eq(2, eval('g:cdcount'))
if iswin() then
command('tcd '..win_dirs[2])
eq({}, eval('g:ev'))
eq(2, eval('g:cdcount'))
end
command('cd '..dirs[3])
eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev'))
eq(3, eval('g:cdcount'))
@ -138,6 +156,12 @@ describe('autocmd DirChanged', function()
eq({}, eval('g:ev'))
eq(3, eval('g:cdcount'))
if iswin() then
command('cd '..win_dirs[3])
eq({}, eval('g:ev'))
eq(3, eval('g:cdcount'))
end
command('set autochdir')
command('split '..dirs[1]..'/foo')
@ -147,6 +171,12 @@ describe('autocmd DirChanged', function()
command('split '..dirs[1]..'/bar')
eq({}, eval('g:ev'))
eq(4, eval('g:cdcount'))
if iswin() then
command('split '..win_dirs[1]..'/baz')
eq({}, eval('g:ev'))
eq(4, eval('g:cdcount'))
end
end)
it("is triggered by switching to win/tab with different CWD #6054", function()
@ -174,6 +204,31 @@ describe('autocmd DirChanged', function()
eq(9, eval('g:cdcount'))
command('tabnext') -- tab 2 (has the *same* CWD)
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
if iswin() then
command('tabnew') -- tab 3
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tcd '..win_dirs[3])
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabnext') -- tab 1
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabprevious') -- tab 3
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabprevious') -- tab 2
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabprevious') -- tab 1
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('lcd '..win_dirs[3]) -- window 3
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabnext') -- tab 2
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabnext') -- tab 3
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabnext') -- tab 1
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
command('tabprevious') -- tab 3
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
end
end)
it('is triggered by nvim_set_current_dir()', function()