diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /test/helpers.lua | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 88 |
1 files changed, 71 insertions, 17 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index 82ff23bef8..f9405c011d 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -1,10 +1,7 @@ -require('test.compat') -local shared = require('vim.shared') +local shared = vim local assert = require('luassert') local busted = require('busted') local luv = require('luv') -local lfs = require('lfs') -local relpath = require('pl.path').relpath local Paths = require('test.cmakeconfig.paths') assert:set_parameter('TableFormatLevel', 100) @@ -18,10 +15,46 @@ local function shell_quote(str) end end +--- @class test.helpers local module = { REMOVE_THIS = {}, } +--- @param p string +--- @return string +local function relpath(p) + p = vim.fs.normalize(p) + local cwd = luv.cwd() + return p:gsub("^" .. cwd) +end + +--- @param path string +--- @return boolean +function module.isdir(path) + if not path then + return false + end + local stat = luv.fs_stat(path) + if not stat then + return false + end + return stat.type == 'directory' +end + +--- @param path string +--- @return boolean +function module.isfile(path) + if not path then + return false + end + local stat = luv.fs_stat(path) + if not stat then + return false + end + return stat.type == 'file' +end + +--- @return string function module.argss_to_cmd(...) local cmd = '' for i = 1, select('#', ...) do @@ -156,10 +189,16 @@ function module.pcall(fn, ...) local errmsg = tostring(rv):gsub('([%s<])vim[/\\]([^%s:/\\]+):%d+', '%1\xffvim\xff%2:0') :gsub('[^%s<]-[/\\]([^%s:/\\]+):%d+', '.../%1:0') :gsub('\xffvim\xff', 'vim/') + -- Scrub numbers in paths/stacktraces: -- shared.lua:0: in function 'gsplit' -- shared.lua:0: in function <shared.lua:0>' - errmsg = errmsg:gsub('([^%s]):%d+', '%1:0') + errmsg = errmsg:gsub('([^%s].lua):%d+', '%1:0') + -- [string "<nvim>"]:0: + -- [string ":lua"]:0: + -- [string ":luado"]:0: + errmsg = errmsg:gsub('(%[string "[^"]+"%]):%d+', '%1:0') + -- Scrub tab chars: errmsg = errmsg:gsub('\t', ' ') -- In Lua 5.1, we sometimes get a "(tail call): ?" on the last line. @@ -228,16 +267,16 @@ function module.glob(initial_path, re, exc_re) while #paths_to_check > 0 do local cur_path = paths_to_check[#paths_to_check] paths_to_check[#paths_to_check] = nil - for e in lfs.dir(cur_path) do + for e in vim.fs.dir(cur_path) do local full_path = cur_path .. '/' .. e local checked_path = full_path:sub(#initial_path + 1) if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then - local attrs = lfs.attributes(full_path) - if attrs then - local check_key = attrs.dev .. ':' .. tostring(attrs.ino) + local stat = luv.fs_stat(full_path) + if stat then + local check_key = stat.dev .. ':' .. tostring(stat.ino) if not checked_files[check_key] then checked_files[check_key] = true - if attrs.mode == 'directory' then + if stat.type == 'directory' then paths_to_check[#paths_to_check + 1] = full_path elseif not re or checked_path:match(re) then ret[#ret + 1] = full_path @@ -253,8 +292,8 @@ end function module.check_logs() local log_dir = os.getenv('LOG_DIR') local runtime_errors = {} - if log_dir and lfs.attributes(log_dir, 'mode') == 'directory' then - for tail in lfs.dir(log_dir) do + if log_dir and module.isdir(log_dir) then + for tail in vim.fs.dir(log_dir) do if tail:sub(1, 30) == 'valgrind-' or tail:find('san%.') then local file = log_dir .. '/' .. tail local fd = io.open(file) @@ -312,7 +351,7 @@ function module.is_os(s) or s == 'bsd') then error('unknown platform: '..tostring(s)) end - return ((s == 'win' and module.sysname():find('windows')) + return not not ((s == 'win' and (module.sysname():find('windows') or module.sysname():find('mingw'))) or (s == 'mac' and module.sysname() == 'darwin') or (s == 'freebsd' and module.sysname() == 'freebsd') or (s == 'openbsd' and module.sysname() == 'openbsd') @@ -371,8 +410,12 @@ end local tests_skipped = 0 -function module.check_cores(app, force) - app = app or 'build/bin/nvim' +function module.check_cores(app, force) -- luacheck: ignore + -- Temporary workaround: skip core check as it interferes with CI. + if true then + return + end + app = app or 'build/bin/nvim' -- luacheck: ignore local initial_path, re, exc_re local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' @@ -432,6 +475,7 @@ function module.check_cores(app, force) end end +--- @return string? function module.repeated_read_cmd(...) for _ = 1, 10 do local stream = module.popen_r(...) @@ -531,19 +575,24 @@ function module.concat_tables(...) return ret end +--- @param str string +--- @param leave_indent? integer +--- @return string function module.dedent(str, leave_indent) -- find minimum common indent across lines - local indent = nil + local indent --- @type string? for line in str:gmatch('[^\n]+') do local line_indent = line:match('^%s+') or '' if indent == nil or #line_indent < #indent then indent = line_indent end end - if indent == nil or #indent == 0 then + + if not indent or #indent == 0 then -- no minimum common indent return str end + local left_indent = (' '):rep(leave_indent or 0) -- create a pattern for the indent indent = indent:gsub('%s', '[ \t]') @@ -839,6 +888,11 @@ function module.read_nvim_log(logfile, ci_rename) return log end +function module.mkdir(path) + -- 493 is 0755 in decimal + return luv.fs_mkdir(path, 493) +end + module = shared.tbl_extend('error', module, Paths, shared, require('test.deprecated')) return module |