fix(tui): log chdir failure properly #37591

This commit is contained in:
zeertzjq
2026-01-28 18:44:17 +08:00
committed by GitHub
parent 027b7d6bbb
commit 1f0dbfea2f
10 changed files with 72 additions and 44 deletions

View File

@@ -1755,7 +1755,7 @@ void tui_chdir(TUIData *tui, String path)
{ {
int err = uv_chdir(path.data); int err = uv_chdir(path.data);
if (err != 0) { if (err != 0) {
ELOG("Failed to chdir to %s: %s", path.data, strerror(err)); ELOG("Failed to chdir to %s: %s", path.data, uv_strerror(err));
} }
} }

View File

@@ -106,6 +106,19 @@ return function(options)
local failureCount = 0 local failureCount = 0
local errorCount = 0 local errorCount = 0
local naCheck = function(pending)
if pending.name:find(' N/A[: ]') or pending.name:find(' N/A$') then
return true
end
if type(pending.message) ~= 'string' then
return false
end
if pending.message:find(' N/A[: ]') or pending.message:find(' N/A$') then
return true
end
return false
end
local pendingDescription = function(pending) local pendingDescription = function(pending)
local string = '' local string = ''
@@ -156,10 +169,21 @@ return function(options)
local testString = summaryStrings[status].test local testString = summaryStrings[status].test
if testString then if testString then
local naCount = 0
for _, t in ipairs(list) do for _, t in ipairs(list) do
local fullname = getFileLine(t.element) .. colors.bright(t.name) if status == 'skipped' and naCheck(t) then
string = string .. testString:format(fullname) naCount = naCount + 1
string = string .. getDescription(t) else
local fullname = getFileLine(t.element) .. colors.bright(t.name)
string = string .. testString:format(fullname)
string = string .. getDescription(t)
end
end
if naCount > 0 then
string = string
.. colors.bright(
('%d N/A %s not shown\n'):format(naCount, naCount == 1 and 'test' or 'tests')
)
end end
end end
end end

View File

@@ -12,7 +12,7 @@ local read_file = t.read_file
local feed = n.feed local feed = n.feed
local retry = t.retry local retry = t.retry
if skip(is_os('win'), 'Only applies to POSIX systems') then if skip(is_os('win'), 'N/A: Only applies to POSIX systems') then
return return
end end

View File

@@ -749,7 +749,7 @@ describe('jobs', function()
it('lists passed to callbacks are freed if not stored #25891', function() it('lists passed to callbacks are freed if not stored #25891', function()
if not exec_lua('return pcall(require, "ffi")') then if not exec_lua('return pcall(require, "ffi")') then
pending('missing LuaJIT FFI') pending('N/A: missing LuaJIT FFI')
end end
source([[ source([[

View File

@@ -220,12 +220,10 @@ describe('server', function()
end) end)
it('removes stale socket files automatically #26053', function() it('removes stale socket files automatically #26053', function()
if is_os('win') then -- Windows named pipes are ephemeral kernel objects that are automatically
-- Windows named pipes are ephemeral kernel objects that are automatically -- cleaned up when the process terminates. Unix domain sockets persist as
-- cleaned up when the process terminates. Unix domain sockets persist as -- files on the filesystem and can become stale after crashes.
-- files on the filesystem and can become stale after crashes. t.skip(is_os('win'), 'N/A on Windows')
return
end
clear() clear()
clear_serverlist() clear_serverlist()
@@ -246,9 +244,7 @@ describe('server', function()
end) end)
it('does not remove live sockets #26053', function() it('does not remove live sockets #26053', function()
if is_os('win') then t.skip(is_os('win'), 'N/A on Windows')
return
end
clear() clear()
local socket_path = './Xtest-live-socket' local socket_path = './Xtest-live-socket'

View File

@@ -31,9 +31,7 @@ describe('completion', function()
end) end)
it('ctrl-x_ctrl-f completes Windows drive letter', function() it('ctrl-x_ctrl-f completes Windows drive letter', function()
if not t.is_os('win') then t.skip(not t.is_os('win'), 'N/A for non-Windows')
return
end
feed('iblablaC:/W<C-x><C-f>') feed('iblablaC:/W<C-x><C-f>')
screen:expect { screen:expect {
any = [[C:\Windows\]], any = [[C:\Windows\]],

View File

@@ -48,10 +48,8 @@ describe(':source', function()
end) end)
it("changing 'shellslash' changes the result of expand()", function() it("changing 'shellslash' changes the result of expand()", function()
if not is_os('win') then t.skip(not is_os('win'), "N/A: 'shellslash' only works on Windows")
pending("'shellslash' only works on Windows")
return
end
api.nvim_set_option_value('shellslash', false, {}) api.nvim_set_option_value('shellslash', false, {})
mkdir('Xshellslash') mkdir('Xshellslash')

View File

@@ -10,7 +10,7 @@ before_each(clear)
describe('ffi.cdef', function() describe('ffi.cdef', function()
it('can use Neovim core functions', function() it('can use Neovim core functions', function()
if not exec_lua("return pcall(require, 'ffi')") then if not exec_lua("return pcall(require, 'ffi')") then
pending('missing LuaJIT FFI') pending('N/A: missing LuaJIT FFI')
end end
eq( eq(

View File

@@ -206,7 +206,7 @@ describe('URI methods', function()
describe('uri from bufnr', function() describe('uri from bufnr', function()
it('Windows paths should not be treated as uris', function() it('Windows paths should not be treated as uris', function()
skip(not is_os('win'), 'Not applicable on non-Windows') skip(not is_os('win'), 'N/A on non-Windows')
local file = t.tmpname() local file = t.tmpname()
write_file(file, 'Test content') write_file(file, 'Test content')

View File

@@ -2744,7 +2744,7 @@ describe('TUI', function()
it('argv[0] can be overridden #23953', function() it('argv[0] can be overridden #23953', function()
if not exec_lua('return pcall(require, "ffi")') then if not exec_lua('return pcall(require, "ffi")') then
pending('missing LuaJIT FFI') pending('N/A: missing LuaJIT FFI')
end end
local script_file = 'Xargv0.lua' local script_file = 'Xargv0.lua'
write_file( write_file(
@@ -3674,7 +3674,7 @@ describe('TUI', function()
it('queries the terminal for OSC 52 support with XTGETTCAP', function() it('queries the terminal for OSC 52 support with XTGETTCAP', function()
clear() clear()
if not exec_lua('return pcall(require, "ffi")') then if not exec_lua('return pcall(require, "ffi")') then
pending('missing LuaJIT FFI') pending('N/A: missing LuaJIT FFI')
end end
-- Change vterm's DA1 response so that it doesn't include 52 -- Change vterm's DA1 response so that it doesn't include 52
@@ -4122,33 +4122,29 @@ describe('TUI client', function()
screen_client:expect({ any = vim.pesc('[Process exited 0]') }) screen_client:expect({ any = vim.pesc('[Process exited 0]') })
end) end)
local ffi_str_defs = [[
local ffi = require('ffi')
local cstr = ffi.typeof('char[?]')
ffi.cdef('typedef struct { char *data; size_t size; } String;')
local function to_api_string(str)
return ffi.new('String', { data = cstr(#str + 1, str), size = #str })
end
]]
it('does not crash or hang with a very long title', function() it('does not crash or hang with a very long title', function()
local server, _, screen_client = start_headless_server_and_client(true) local server, _, screen_client = start_headless_server_and_client(true)
local server_exec_lua = tt.make_lua_executor(server) local server_exec_lua = tt.make_lua_executor(server)
if not server_exec_lua('return pcall(require, "ffi")') then if not server_exec_lua('return pcall(require, "ffi")') then
pending('missing LuaJIT FFI') pending('N/A: missing LuaJIT FFI')
end end
local bufname = api.nvim_buf_get_name(0) local bufname = api.nvim_buf_get_name(0)
-- Normally a title cannot be longer than the 65535-byte buffer as maketitle() -- Normally a title cannot be longer than the 65535-byte buffer as maketitle()
-- limits it length. Use FFI to send a very long title directly. -- limits it length. Use FFI to send a very long title directly.
server_exec_lua([=[ server_exec_lua(ffi_str_defs .. [[
local ffi = require('ffi') ffi.cdef('void ui_call_set_title(String title);')
local cstr = ffi.typeof('char[?]') ffi.C.ui_call_set_title(to_api_string(('a'):rep(65536)))
local function to_cstr(string) ]])
return cstr(#string + 1, string)
end
ffi.cdef([[
typedef struct { char *data; size_t size; } String;
void ui_call_set_title(String title);
]])
local len = 65536
local title = ffi.new('String', { data = to_cstr(('a'):rep(len)), size = len })
ffi.C.ui_call_set_title(title)
]=])
screen_client:expect_unchanged() screen_client:expect_unchanged()
assert_log('set_title: title string too long!', testlog) assert_log('set_title: title string too long!', testlog)
eq(bufname, api.nvim_buf_get_var(0, 'term_title')) eq(bufname, api.nvim_buf_get_var(0, 'term_title'))
@@ -4160,6 +4156,22 @@ describe('TUI client', function()
end) end)
end) end)
it('logs chdir failure properly', function()
local server, _, screen_client = start_headless_server_and_client(true)
local server_exec_lua = tt.make_lua_executor(server)
if not server_exec_lua('return pcall(require, "ffi")') then
pending('N/A: missing LuaJIT FFI')
end
-- Use FFI to send a chdir event to a non-directory path.
server_exec_lua(ffi_str_defs .. [[
ffi.cdef('void ui_call_chdir(String path);')
ffi.C.ui_call_chdir(to_api_string('README.md'))
]])
screen_client:expect_unchanged()
assert_log('Failed to chdir to README.md: not a directory', testlog)
end)
it('nvim_ui_send works with remote client #36317', function() it('nvim_ui_send works with remote client #36317', function()
local server, _, _ = start_headless_server_and_client(false) local server, _, _ = start_headless_server_and_client(false)
server:request('nvim_ui_send', '\027]2;TEST_TITLE\027\\') server:request('nvim_ui_send', '\027]2;TEST_TITLE\027\\')