diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
commit | d5f194ce780c95821a855aca3c19426576d28ae0 (patch) | |
tree | d45f461b19f9118ad2bb1f440a7a08973ad18832 /test/testutil.lua | |
parent | c5d770d311841ea5230426cc4c868e8db27300a8 (diff) | |
parent | 44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff) | |
download | rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.tar.gz rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.tar.bz2 rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.zip |
Diffstat (limited to 'test/testutil.lua')
-rw-r--r-- | test/testutil.lua | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/test/testutil.lua b/test/testutil.lua index 00b30d74d5..e69dcae120 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -22,13 +22,6 @@ local M = { paths = Paths, } ---- @param p string ---- @return string -local function relpath(p) - p = vim.fs.normalize(p) - return (p:gsub('^' .. uv.cwd, '')) -end - --- @param path string --- @return boolean function M.isdir(path) @@ -45,14 +38,15 @@ end --- (Only on Windows) Replaces yucky "\\" slashes with delicious "/" slashes in a string, or all --- string values in a table (recursively). --- ---- @param obj string|table ---- @return any +--- @generic T: string|table +--- @param obj T +--- @return T|nil function M.fix_slashes(obj) if not M.is_os('win') then return obj end if type(obj) == 'string' then - local ret = obj:gsub('\\', '/') + local ret = string.gsub(obj, '\\', '/') return ret elseif type(obj) == 'table' then --- @cast obj table<any,any> @@ -394,21 +388,35 @@ end local sysname = uv.os_uname().sysname:lower() ---- @param s 'win'|'mac'|'freebsd'|'openbsd'|'bsd' +--- @param s 'win'|'mac'|'linux'|'freebsd'|'openbsd'|'bsd' --- @return boolean function M.is_os(s) - if not (s == 'win' or s == 'mac' or s == 'freebsd' or s == 'openbsd' or s == 'bsd') then + if + not (s == 'win' or s == 'mac' or s == 'linux' or s == 'freebsd' or s == 'openbsd' or s == 'bsd') + then error('unknown platform: ' .. tostring(s)) end return not not ( (s == 'win' and (sysname:find('windows') or sysname:find('mingw'))) or (s == 'mac' and sysname == 'darwin') + or (s == 'linux' and sysname == 'linux') or (s == 'freebsd' and sysname == 'freebsd') or (s == 'openbsd' and sysname == 'openbsd') or (s == 'bsd' and sysname:find('bsd')) ) end +local architecture = uv.os_uname().machine + +--- @param s 'x86_64'|'arm64' +--- @return boolean +function M.is_arch(s) + if not (s == 'x86_64' or s == 'arm64') then + error('unknown architecture: ' .. tostring(s)) + end + return s == architecture +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')) @@ -471,7 +479,8 @@ function M.check_cores(app, force) -- luacheck: ignore -- "./Xtest-tmpdir/" => "Xtest%-tmpdir" local local_tmpdir = nil if tmpdir_is_local and tmpdir then - local_tmpdir = vim.pesc(relpath(tmpdir):gsub('^[ ./]+', ''):gsub('%/+$', '')) + local_tmpdir = + vim.pesc(vim.fs.relpath(assert(vim.uv.cwd()), tmpdir):gsub('^[ ./]+', ''):gsub('%/+$', '')) end local db_cmd --- @type string |