From 349f810eed3382610924f88945b4402cbb95613d Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 1 Jul 2026 10:40:18 +0200 Subject: [PATCH] refactor(test): unify XDG path handling (cmake vs zig) fixes #40381 --- cmake/RunTests.cmake | 10 +--------- test/functional/lua/fs_spec.lua | 13 +++++++----- test/functional/plugin/dir_spec.lua | 8 +------- test/functional/plugin/lsp_spec.lua | 3 --- .../treesitter/inspect_tree_spec.lua | 2 -- test/run_tests.zig | 10 ++-------- test/runner.lua | 20 ++++++++++++++++--- 7 files changed, 29 insertions(+), 37 deletions(-) diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index 20063116dd..5dd5e394b7 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -11,12 +11,7 @@ endif() set(ENV{NVIM_TEST} "1") # Set LC_ALL to meet expectations of some locale-sensitive tests. set(ENV{LC_ALL} "en_US.UTF-8") -set(ENV{VIMRUNTIME} ${ROOT_DIR}/runtime) set(TEST_XDG_PREFIX ${BUILD_DIR}/Xtest_xdg${TEST_SUFFIX}) -set(ENV{XDG_CONFIG_HOME} ${TEST_XDG_PREFIX}/config) -set(ENV{XDG_DATA_HOME} ${TEST_XDG_PREFIX}/share) -set(ENV{XDG_STATE_HOME} ${TEST_XDG_PREFIX}/state) -set(ENV{NVIM_RPLUGIN_MANIFEST} ${BUILD_DIR}/Xtest_rplugin_manifest${TEST_SUFFIX}) unset(ENV{XDG_DATA_DIRS}) unset(ENV{NVIM}) # Clear $NVIM in case tests are running from Nvim. #11009 unset(ENV{TMUX}) # Nvim TUI shouldn't think it's running in tmux. #34173 @@ -87,13 +82,10 @@ if(NOT WIN32) endif() execute_process( - COMMAND ${NVIM_PRG} -l ${ROOT_DIR}/test/runner.lua -v + COMMAND ${NVIM_PRG} -l ${ROOT_DIR}/test/runner.lua -X${TEST_XDG_PREFIX} -v --summary-file=${TEST_SUMMARY_FILE} --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua --lpath=${BUILD_DIR}/?.lua - --lpath=${ROOT_DIR}/src/?.lua - --lpath=${ROOT_DIR}/runtime/lua/?.lua - --lpath=?.lua ${TEST_ARGS} ${TEST_PATH} TIMEOUT $ENV{TEST_TIMEOUT} diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 4a88e4b6d1..2c9b0043e1 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -356,6 +356,12 @@ describe('vim.fs', function() eq({ nvim_dir }, vim.fs.find(name, { path = parent, upward = true, type = 'directory' })) end) + local function filter_zig_cache(list) + return vim.tbl_filter(function(val) + return not vim.startswith(val, test_source_path .. '/.zig-cache/') + end, list) + end + it('follows symlinks', function() local build_dir = test_build_dir ---@type string local symlink = test_source_path .. '/build_link' ---@type string @@ -378,17 +384,14 @@ describe('vim.fs', function() }) ) - if t.is_zig_build() then - return pending('broken with build.zig') - end eq( { nvim_prog }, - vim.fs.find(nvim_prog_basename, { + filter_zig_cache(vim.fs.find(nvim_prog_basename, { path = test_source_path, type = 'file', limit = 2, follow = false, - }) + })) ) end) diff --git a/test/functional/plugin/dir_spec.lua b/test/functional/plugin/dir_spec.lua index b3c31108fa..04dcd7616f 100644 --- a/test/functional/plugin/dir_spec.lua +++ b/test/functional/plugin/dir_spec.lua @@ -165,9 +165,6 @@ describe('nvim.dir', function() end) it('uses an absolute buffer name for a relative startup directory argument', function() - if t.is_zig_build() then - return pending('broken with build.zig relative runtime paths after chdir') - end make_fixture() local cwd = assert(vim.uv.cwd()) assert(vim.uv.chdir(root)) @@ -373,9 +370,6 @@ describe('nvim.dir', function() end) it('coexists with netrw and can be disabled', function() - if t.is_zig_build() then - return pending('broken with build.zig relative runtime paths after chdir') - end make_fixture() n.clear({ args_rm = { '-u' } }) local cwd = fn.getcwd() @@ -399,7 +393,7 @@ describe('nvim.dir', function() it('supports the FileExplorer browse contract', function() if t.is_zig_build() then - return pending('broken with build.zig relative runtime paths after chdir') + return pending('broken with build.zig: TMPDIR relative cwd') end make_fixture() n.clear({ args_rm = { '-u' } }) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 237dab5fce..1f6d299d4c 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -500,9 +500,6 @@ describe('LSP', function() end) it('should overwrite options set by ftplugins', function() - if t.is_zig_build() then - return pending('TODO: broken with zig build') - end local client --- @type vim.lsp.Client local BUFFER_1 --- @type integer local BUFFER_2 --- @type integer diff --git a/test/functional/treesitter/inspect_tree_spec.lua b/test/functional/treesitter/inspect_tree_spec.lua index 88c855df28..b44cf7fce6 100644 --- a/test/functional/treesitter/inspect_tree_spec.lua +++ b/test/functional/treesitter/inspect_tree_spec.lua @@ -36,8 +36,6 @@ describe('vim.treesitter.inspect_tree', function() end) it('sets correct buffer name', function() - t.skip(t.is_zig_build(), 'vim.treesitter not found after chdir with build.zig') - n.api.nvim_set_current_dir(t.paths.test_source_path .. '/test/functional/fixtures') n.command('edit lua/syntax_error.lua') eq('lua/syntax_error.lua', n.fn.bufname('%')) diff --git a/test/run_tests.zig b/test/run_tests.zig index 8806b2e538..8dffb277c0 100644 --- a/test/run_tests.zig +++ b/test/run_tests.zig @@ -11,22 +11,16 @@ pub fn testStep(b: *std.Build, kind: []const u8, nvim_bin: *std.Build.Step.Compi } } test_step.addArg(b.fmt("-P{s}", .{b.install_path})); + // TODO(bfredl): investigate parallell test groups like in cmake + test_step.addArg(b.fmt("-X{s}/Xdg_dir", .{b.install_path})); test_step.addArg("-v"); test_step.addArg(b.fmt("--helper=./test/{s}/preload.lua", .{kind})); - test_step.addArg("--lpath=./src/?.lua"); - test_step.addArg("--lpath=./runtime/lua/?.lua"); - test_step.addArg("--lpath=./?.lua"); test_step.addPrefixedFileArg("--lpath=", config_dir.path(b, "?.lua")); // FULING: not a real file but works anyway? test_step.addArg(b.fmt("--default-path=./test/{s}", .{kind})); if (b.args) |args| test_step.addArgs(args); const env = test_step.getEnvMap(); try env.put("NVIM_TEST", "1"); - try env.put("VIMRUNTIME", "runtime"); - try env.put("NVIM_RPLUGIN_MANIFEST", "Xtest_xdg/Xtest_rplugin_manifest"); - try env.put("XDG_CONFIG_HOME", "Xtest_xdg/config"); - try env.put("XDG_DATA_HOME", "Xtest_xdg/share"); - try env.put("XDG_STATE_HOME", "Xtest_xdg/state"); _ = env.swapRemove("NVIM"); _ = env.swapRemove("XDG_DATA_DIRS"); diff --git a/test/runner.lua b/test/runner.lua index 5e97630564..51f5e91570 100644 --- a/test/runner.lua +++ b/test/runner.lua @@ -23,15 +23,29 @@ _G.c_include_path = {} while _G.arg[1] and vim.startswith(_G.arg[1], '-I') do table.insert(_G.c_include_path, string.sub(table.remove(_G.arg, 1), 3)) end +-- TODO(bfredl): use also for cmake? if _G.arg[1] and vim.startswith(_G.arg[1], '-P') then - _G.nvim_build_dir = string.sub(table.remove(_G.arg, 1), 3) + local build_dir = string.sub(table.remove(_G.arg, 1), 3) + _G.nvim_build_dir = build_dir - vim.env.TMPDIR = _G.nvim_build_dir .. '/Xtest_tmpdir' - vim.env.NVIM_LOG_FILE = _G.nvim_build_dir .. '/Xtest_nvimlog' + -- TMPDIR: for testutil.tmpname() and Nvim tempname(). + vim.env.TMPDIR = build_dir .. '/Xtest_tmpdir' + vim.fn.mkdir(vim.env.TMPDIR, 'p') +end +if _G.arg[1] and vim.startswith(_G.arg[1], '-X') then + local xdg_dir = string.sub(table.remove(_G.arg, 1), 3) + vim.env.NVIM_LOG_FILE = xdg_dir .. '/Xtest_nvimlog' + vim.env.NVIM_RPLUGIN_MANIFEST = xdg_dir .. '/Xtest_rplugin_manifest' + vim.env.XDG_CONFIG_HOME = xdg_dir .. '/config' + vim.env.XDG_DATA_HOME = xdg_dir .. '/share' + vim.env.XDG_STATE_HOME = xdg_dir .. '/state' end local root = repo_root() prepend_package_roots({ root, root .. '/test', '.', './test' }) +local entries = { root .. '/src/?.lua', root .. '/runtime/lua/?.lua' } +package.path = table.concat(entries, ';') .. ';' .. package.path +vim.env.VIMRUNTIME = root .. '/runtime' -- The harness is not an Nvim instance under test. If its startup server stays -- visible, serverlist({ peer = true }) can connect back to the runner and wait