mirror of
https://github.com/neovim/neovim.git
synced 2026-03-27 02:42:00 +00:00
Merge pull request #28344 from bfredl/wonderland
feat(build): build.zig MVP: build and run functionaltests on linux
This commit is contained in:
@@ -7,6 +7,7 @@ end
|
||||
|
||||
M.translations_enabled = "${ENABLE_TRANSLATIONS}" == "ON"
|
||||
M.is_asan = "${ENABLE_ASAN_UBSAN}" == "ON"
|
||||
M.is_zig_build = false
|
||||
M.vterm_test_file = "${VTERM_TEST_FILE}"
|
||||
M.test_build_dir = "${CMAKE_BINARY_DIR}"
|
||||
M.test_source_path = "${CMAKE_SOURCE_DIR}"
|
||||
|
||||
@@ -4874,7 +4874,7 @@ describe('API', function()
|
||||
-- #20681
|
||||
eq('Invalid command: "win_getid"', pcall_err(api.nvim_cmd, { cmd = 'win_getid' }, {}))
|
||||
eq('Invalid command: "echo "hi""', pcall_err(api.nvim_cmd, { cmd = 'echo "hi"' }, {}))
|
||||
eq('Invalid command: "win_getid"', pcall_err(exec_lua, [[return vim.cmd.win_getid{}]]))
|
||||
matches('Invalid command: "win_getid"$', pcall_err(exec_lua, [[return vim.cmd.win_getid{}]]))
|
||||
|
||||
-- Lua call allows empty {} for dict item.
|
||||
eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]]))
|
||||
@@ -4882,16 +4882,16 @@ describe('API', function()
|
||||
eq('', api.nvim_cmd({ cmd = 'set', args = {}, magic = {} }, {}))
|
||||
|
||||
-- Lua call does not allow non-empty list-like {} for dict item.
|
||||
eq(
|
||||
"Invalid 'magic': Expected Dict-like Lua table",
|
||||
matches(
|
||||
"Invalid 'magic': Expected Dict%-like Lua table$",
|
||||
pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { 'a' } }]])
|
||||
)
|
||||
eq(
|
||||
"Invalid key: 'bogus'",
|
||||
matches(
|
||||
"Invalid key: 'bogus'$",
|
||||
pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { bogus = true } }]])
|
||||
)
|
||||
eq(
|
||||
"Invalid key: 'bogus'",
|
||||
matches(
|
||||
"Invalid key: 'bogus'$",
|
||||
pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, mods = { bogus = true } }]])
|
||||
)
|
||||
end)
|
||||
|
||||
@@ -169,7 +169,8 @@ pcall(vim.cmd.edit, 'Xtest_swapredraw.lua')
|
||||
exec(init)
|
||||
command('edit! ' .. testfile)
|
||||
command('preserve')
|
||||
local nvim2 = n.new_session(true, { args = { '--clean', '--embed' }, merge = false })
|
||||
local args2 = { '--clean', '--embed', '--cmd', n.runtime_set }
|
||||
local nvim2 = n.new_session(true, { args = args2, merge = false })
|
||||
set_session(nvim2)
|
||||
local screen2 = Screen.new(100, 40)
|
||||
screen2:add_extra_attr_ids({
|
||||
|
||||
@@ -47,7 +47,8 @@ local setup_treesitter = function()
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
clear({ args_rm = { '--cmd' }, args = { '--clean' } })
|
||||
-- avoid options, but we still need TS parsers
|
||||
clear({ args_rm = { '--cmd' }, args = { '--clean', '--cmd', n.runtime_set } })
|
||||
end)
|
||||
|
||||
describe('commenting', function()
|
||||
|
||||
@@ -245,8 +245,8 @@ describe('vim.fs', function()
|
||||
describe('find()', function()
|
||||
it('works', function()
|
||||
eq(
|
||||
{ test_build_dir .. '/build' },
|
||||
vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' })
|
||||
{ test_build_dir .. '/bin' },
|
||||
vim.fs.find('bin', { path = nvim_dir, upward = true, type = 'directory' })
|
||||
)
|
||||
eq({ nvim_prog }, vim.fs.find(nvim_prog_basename, { path = test_build_dir, type = 'file' }))
|
||||
|
||||
@@ -255,7 +255,7 @@ describe('vim.fs', function()
|
||||
end)
|
||||
|
||||
it('follows symlinks', function()
|
||||
local build_dir = test_source_path .. '/build' ---@type string
|
||||
local build_dir = test_build_dir ---@type string
|
||||
local symlink = test_source_path .. '/build_link' ---@type string
|
||||
vim.uv.fs_symlink(build_dir, symlink, { junction = true, dir = true })
|
||||
|
||||
@@ -263,8 +263,11 @@ describe('vim.fs', function()
|
||||
vim.uv.fs_unlink(symlink)
|
||||
end)
|
||||
|
||||
local cases = { nvim_prog, symlink .. '/bin/' .. nvim_prog_basename }
|
||||
table.sort(cases)
|
||||
|
||||
eq(
|
||||
{ nvim_prog, symlink .. '/bin/' .. nvim_prog_basename },
|
||||
cases,
|
||||
vim.fs.find(nvim_prog_basename, {
|
||||
path = test_source_path,
|
||||
type = 'file',
|
||||
@@ -273,6 +276,9 @@ 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, {
|
||||
@@ -285,6 +291,9 @@ describe('vim.fs', function()
|
||||
end)
|
||||
|
||||
it('follow=true handles symlink loop', function()
|
||||
if t.is_zig_build() then
|
||||
return pending('broken/slow with build.zig')
|
||||
end
|
||||
local cwd = test_source_path ---@type string
|
||||
local symlink = test_source_path .. '/loop_link' ---@type string
|
||||
vim.uv.fs_symlink(cwd, symlink, { junction = true, dir = true })
|
||||
@@ -304,9 +313,9 @@ describe('vim.fs', function()
|
||||
it('accepts predicate as names', function()
|
||||
local opts = { path = nvim_dir, upward = true, type = 'directory' }
|
||||
eq(
|
||||
{ test_build_dir .. '/build' },
|
||||
{ test_build_dir .. '/bin' },
|
||||
vim.fs.find(function(x)
|
||||
return x == 'build'
|
||||
return x == 'bin'
|
||||
end, opts)
|
||||
)
|
||||
eq(
|
||||
|
||||
@@ -2100,9 +2100,9 @@ describe('lua stdlib', function()
|
||||
eq(false, fn.luaeval "vim.v['false']")
|
||||
eq(NIL, fn.luaeval 'vim.v.null')
|
||||
matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath'))
|
||||
eq('Key is read-only: count', pcall_err(exec_lua, [[vim.v.count = 42]]))
|
||||
eq('Dict is locked', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]]))
|
||||
eq('Key is fixed: errmsg', pcall_err(exec_lua, [[vim.v.errmsg = nil]]))
|
||||
matches('Key is read%-only: count$', pcall_err(exec_lua, [[vim.v.count = 42]]))
|
||||
matches('Dict is locked$', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]]))
|
||||
matches('Key is fixed: errmsg$', pcall_err(exec_lua, [[vim.v.errmsg = nil]]))
|
||||
exec_lua([[vim.v.errmsg = 'set by Lua']])
|
||||
eq('set by Lua', eval('v:errmsg'))
|
||||
exec_lua([[vim.v.errmsg = 42]])
|
||||
@@ -2111,7 +2111,10 @@ describe('lua stdlib', function()
|
||||
eq({ 'one', 'two' }, eval('v:oldfiles'))
|
||||
exec_lua([[vim.v.oldfiles = {}]])
|
||||
eq({}, eval('v:oldfiles'))
|
||||
eq('Setting v:oldfiles to value with wrong type', pcall_err(exec_lua, [[vim.v.oldfiles = 'a']]))
|
||||
matches(
|
||||
'Setting v:oldfiles to value with wrong type$',
|
||||
pcall_err(exec_lua, [[vim.v.oldfiles = 'a']])
|
||||
)
|
||||
eq({}, eval('v:oldfiles'))
|
||||
|
||||
feed('i foo foo foo<Esc>0/foo<CR>')
|
||||
|
||||
@@ -491,7 +491,7 @@ describe('LSP', function()
|
||||
vim._with({ buf = _G.BUFFER }, function()
|
||||
keymap = vim.fn.maparg('K', 'n', false, false)
|
||||
end)
|
||||
return keymap:match('<Lua %d+: .+/runtime/lua/vim/lsp%.lua:%d+>') ~= nil
|
||||
return keymap:match('<Lua %d+: .*runtime/lua/vim/lsp%.lua:%d+>') ~= nil
|
||||
end)
|
||||
)
|
||||
end,
|
||||
@@ -499,6 +499,9 @@ 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
|
||||
|
||||
@@ -17,7 +17,9 @@ local sleep = uv.sleep
|
||||
--- Functions executing in the current nvim session/process being tested.
|
||||
local M = {}
|
||||
|
||||
local runtime_set = 'set runtimepath^=./build/lib/nvim/'
|
||||
local lib_path = t.is_zig_build() and './zig-out/lib' or './build/lib/nvim/'
|
||||
M.runtime_set = 'set runtimepath^=' .. lib_path
|
||||
|
||||
M.nvim_prog = (os.getenv('NVIM_PRG') or t.paths.test_build_dir .. '/bin/nvim')
|
||||
-- Default settings for the test session.
|
||||
M.nvim_set = (
|
||||
@@ -34,7 +36,7 @@ M.nvim_argv = {
|
||||
'NONE',
|
||||
-- XXX: find treesitter parsers.
|
||||
'--cmd',
|
||||
runtime_set,
|
||||
M.runtime_set,
|
||||
'--cmd',
|
||||
M.nvim_set,
|
||||
-- Remove default user commands and mappings.
|
||||
@@ -425,7 +427,7 @@ local function remove_args(args, args_rm)
|
||||
last = ''
|
||||
elseif vim.tbl_contains(args_rm, arg) then
|
||||
last = arg
|
||||
elseif arg == runtime_set and vim.tbl_contains(args_rm, 'runtimepath') then
|
||||
elseif arg == M.runtime_set and vim.tbl_contains(args_rm, 'runtimepath') then
|
||||
table.remove(new_args) -- Remove the preceding "--cmd".
|
||||
last = ''
|
||||
else
|
||||
|
||||
@@ -192,7 +192,7 @@ describe('eval-API', function()
|
||||
local screen = Screen.new(40, 8)
|
||||
|
||||
command('set ft=vim')
|
||||
command('set rtp^=build/runtime/')
|
||||
n.add_builddir_to_rtp()
|
||||
command('syntax on')
|
||||
insert([[
|
||||
call bufnr('%')
|
||||
|
||||
@@ -2,10 +2,10 @@ local platform = vim.uv.os_uname()
|
||||
local deps_install_dir = table.remove(_G.arg, 1)
|
||||
local subcommand = table.remove(_G.arg, 1)
|
||||
local suffix = (platform and platform.sysname:lower():find 'windows') and '.dll' or '.so'
|
||||
package.path = (deps_install_dir .. '/share/lua/5.1/?.lua;')
|
||||
.. (deps_install_dir .. '/share/lua/5.1/?/init.lua;')
|
||||
package.path = (deps_install_dir .. '/?.lua;')
|
||||
.. (deps_install_dir .. '/?/init.lua;')
|
||||
.. package.path
|
||||
package.cpath = deps_install_dir .. '/lib/lua/5.1/?' .. suffix .. ';' .. package.cpath
|
||||
package.cpath = deps_install_dir .. '/?' .. suffix .. ';' .. package.cpath
|
||||
|
||||
local uv = vim.uv
|
||||
|
||||
|
||||
44
test/run_tests.zig
Normal file
44
test/run_tests.zig
Normal file
@@ -0,0 +1,44 @@
|
||||
const std = @import("std");
|
||||
const LazyPath = std.Build.LazyPath;
|
||||
|
||||
pub fn test_steps(b: *std.Build, nvim_bin: *std.Build.Step.Compile, depend_on: *std.Build.Step, lua_deps: LazyPath, config_dir: LazyPath) !void {
|
||||
const test_step = b.addRunArtifact(nvim_bin);
|
||||
test_step.addArg("-ll");
|
||||
test_step.addFileArg(b.path("./test/lua_runner.lua"));
|
||||
test_step.addDirectoryArg(lua_deps);
|
||||
test_step.addArgs(&.{ "busted", "-v", "-o", "test.busted.outputHandlers.nvim", "--lazy" });
|
||||
// TODO(bfredl): a bit funky with paths, should work even if we run "zig build" in a nested dir
|
||||
test_step.addArg("./test/functional/preload.lua"); // TEST_TYPE!!
|
||||
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?
|
||||
// TODO(bfredl): look into $BUSTED_ARGS user hook, TEST_TAG, TEST_FILTER
|
||||
if (b.args) |args| {
|
||||
test_step.addArgs(args); // accept TEST_FILE as a positional argument
|
||||
} else {
|
||||
test_step.addArg("./test/functional/");
|
||||
}
|
||||
|
||||
test_step.step.dependOn(depend_on);
|
||||
|
||||
const env = test_step.getEnvMap();
|
||||
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");
|
||||
try env.put("TMPDIR", b.fmt("{s}/Xtest_tmpdir", .{b.install_path}));
|
||||
try env.put("NVIM_LOG_FILE", b.fmt("{s}/Xtest_nvimlog", .{b.install_path}));
|
||||
|
||||
env.remove("NVIM");
|
||||
env.remove("XDG_DATA_DIRS");
|
||||
|
||||
const empty_dir = b.addWriteFiles();
|
||||
_ = empty_dir.add(".touch", "");
|
||||
const tmpdir_create = b.addInstallDirectory(.{ .source_dir = empty_dir.getDirectory(), .install_dir = .prefix, .install_subdir = "Xtest_tmpdir/" });
|
||||
test_step.step.dependOn(&tmpdir_create.step);
|
||||
|
||||
const functionaltest_step = b.step("functionaltest", "run functionaltests");
|
||||
functionaltest_step.dependOn(&test_step.step);
|
||||
}
|
||||
@@ -422,6 +422,10 @@ function M.is_asan()
|
||||
return M.paths.is_asan
|
||||
end
|
||||
|
||||
function M.is_zig_build()
|
||||
return M.paths.is_zig_build
|
||||
end
|
||||
|
||||
local tmpname_id = 0
|
||||
local tmpdir = os.getenv('TMPDIR') or os.getenv('TEMP')
|
||||
local tmpdir_is_local = not not (tmpdir and tmpdir:find('Xtest'))
|
||||
|
||||
Reference in New Issue
Block a user