robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 9a29622b3b00ddb601

master
2.4 KiB66 linesraw
1local uv = vim.uv
2
3---@return string
4local function repo_root()
5  local source = debug.getinfo(1, 'S').source
6  assert(type(source) == 'string' and vim.startswith(source, '@'), 'failed to resolve runner path')
7  local script_path = assert(uv.fs_realpath(source:sub(2)), 'failed to resolve runner path')
8  return vim.fs.dirname(vim.fs.dirname(script_path))
9end
10
11---@param roots string[]
12local function prepend_package_roots(roots)
13  local entries = {}
14  for _, root in ipairs(roots) do
15    entries[#entries + 1] = root .. '/?.lua'
16    entries[#entries + 1] = root .. '/?/init.lua'
17  end
18
19  package.path = table.concat(entries, ';') .. ';' .. package.path
20end
21
22_G.c_include_path = {}
23while _G.arg[1] and vim.startswith(_G.arg[1], '-I') do
24  table.insert(_G.c_include_path, string.sub(table.remove(_G.arg, 1), 3))
25end
26-- TODO(bfredl): use also for cmake?
27if _G.arg[1] and vim.startswith(_G.arg[1], '-P') then
28  local build_dir = string.sub(table.remove(_G.arg, 1), 3)
29  _G.nvim_build_dir = build_dir
30
31  -- TMPDIR: for testutil.tmpname() and Nvim tempname().
32  vim.env.TMPDIR = build_dir .. '/Xtest_tmpdir'
33  vim.fn.mkdir(vim.env.TMPDIR, 'p')
34end
35if _G.arg[1] and vim.startswith(_G.arg[1], '-X') then
36  local xdg_dir = string.sub(table.remove(_G.arg, 1), 3)
37  vim.env.NVIM_RPLUGIN_MANIFEST = xdg_dir .. '/Xtest_rplugin_manifest'
38  vim.env.XDG_CONFIG_HOME = xdg_dir .. '/config'
39  vim.env.XDG_DATA_HOME = xdg_dir .. '/share'
40  vim.env.XDG_STATE_HOME = xdg_dir .. '/state'
41  if vim.fn.has('win32') == 0 then
42    -- Socket dir (stdpath("run")), deliberately NOT in the build dir. sockaddr_un.sun_path is 104
43    -- bytes on macOS/BSD, "/…/build/tmp/nvim.<pid>.<n>" can exceed it. #38623
44    vim.env.XDG_RUNTIME_DIR = ('/tmp/nvim_%d'):format(vim.uv.os_getpid())
45    vim.fn.mkdir(vim.env.XDG_RUNTIME_DIR, 'p')
46  end
47end
48
49local root = repo_root()
50prepend_package_roots({ root, root .. '/test', '.', './test' })
51local entries = { root .. '/src/?.lua', root .. '/runtime/lua/?.lua' }
52package.path = table.concat(entries, ';') .. ';' .. package.path
53vim.env.VIMRUNTIME = root .. '/runtime'
54
55-- The harness is not an Nvim instance under test. If its startup server stays
56-- visible, serverlist({ peer = true }) can connect back to the runner and wait
57-- forever for an RPC response.
58if vim.v.servername ~= '' then
59  assert(vim.fn.serverstop(vim.v.servername) == 1)
60end
61
62local exit_code = require('test.harness').main(_G.arg)
63io.stdout:flush()
64io.stderr:flush()
65
66os.exit(exit_code)