aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/helpers.lua')
-rw-r--r--test/helpers.lua228
1 files changed, 138 insertions, 90 deletions
diff --git a/test/helpers.lua b/test/helpers.lua
index f9405c011d..d4ea8b27a3 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -25,7 +25,7 @@ local module = {
local function relpath(p)
p = vim.fs.normalize(p)
local cwd = luv.cwd()
- return p:gsub("^" .. cwd)
+ return p:gsub('^' .. cwd)
end
--- @param path string
@@ -60,7 +60,7 @@ function module.argss_to_cmd(...)
for i = 1, select('#', ...) do
local arg = select(i, ...)
if type(arg) == 'string' then
- cmd = cmd .. ' ' ..shell_quote(arg)
+ cmd = cmd .. ' ' .. shell_quote(arg)
else
for _, subarg in ipairs(arg) do
cmd = cmd .. ' ' .. shell_quote(subarg)
@@ -92,19 +92,19 @@ function module.retry(max, max_ms, fn)
if status then
return result
end
- luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()).
+ luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()).
if (max and tries >= max) or (luv.now() - start_time > timeout) then
- busted.fail(string.format("retry() attempts: %d\n%s", tries, tostring(result)), 2)
+ busted.fail(string.format('retry() attempts: %d\n%s', tries, tostring(result)), 2)
end
tries = tries + 1
- luv.sleep(20) -- Avoid hot loop...
+ luv.sleep(20) -- Avoid hot loop...
end
end
local check_logs_useless_lines = {
- ['Warning: noted but unhandled ioctl']=1,
- ['could cause spurious value errors to appear']=2,
- ['See README_MISSING_SYSCALL_OR_IOCTL for guidance']=3,
+ ['Warning: noted but unhandled ioctl'] = 1,
+ ['could cause spurious value errors to appear'] = 2,
+ ['See README_MISSING_SYSCALL_OR_IOCTL for guidance'] = 3,
}
function module.eq(expected, actual, context)
@@ -120,7 +120,10 @@ end
--- @param expected (any) description of expected result
--- @param actual (any) description of actual result
function module.ok(cond, expected, actual)
- assert((not expected and not actual) or (expected and actual), 'if "expected" is given, "actual" is also required')
+ assert(
+ (not expected and not actual) or (expected and actual),
+ 'if "expected" is given, "actual" is also required'
+ )
local msg = expected and ('expected %s, got: %s'):format(expected, tostring(actual)) or nil
return assert(cond, msg)
end
@@ -129,7 +132,7 @@ local function epicfail(state, arguments, _)
state.failure_message = arguments[1]
return false
end
-assert:register("assertion", "epicfail", epicfail)
+assert:register('assertion', 'epicfail', epicfail)
function module.fail(msg)
return assert.epicfail(msg)
end
@@ -157,14 +160,26 @@ function module.assert_log(pat, logfile, nrlines, inverse)
module.retry(nil, 1000, function()
local lines = module.read_file_list(logfile, -nrlines) or {}
- local msg = string.format('Pattern %q %sfound in log (last %d lines): %s:\n%s',
- pat, (inverse and '' or 'not '), nrlines, logfile, ' '..table.concat(lines, '\n '))
- for _,line in ipairs(lines) do
+ local msg = string.format(
+ 'Pattern %q %sfound in log (last %d lines): %s:\n%s',
+ pat,
+ (inverse and '' or 'not '),
+ nrlines,
+ logfile,
+ ' ' .. table.concat(lines, '\n ')
+ )
+ for _, line in ipairs(lines) do
if line:match(pat) then
- if inverse then error(msg) else return end
+ if inverse then
+ error(msg)
+ else
+ return
+ end
end
end
- if not inverse then error(msg) end
+ if not inverse then
+ error(msg)
+ end
end)
end
@@ -186,9 +201,10 @@ function module.pcall(fn, ...)
-- C:/long/path/foo.lua:186: Expected string, got number
-- to:
-- .../foo.lua:0: Expected string, got number
- local errmsg = tostring(rv):gsub('([%s<])vim[/\\]([^%s:/\\]+):%d+', '%1\xffvim\xff%2:0')
- :gsub('[^%s<]-[/\\]([^%s:/\\]+):%d+', '.../%1:0')
- :gsub('\xffvim\xff', 'vim/')
+ 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'
@@ -233,9 +249,10 @@ end
function module.pcall_err_withtrace(fn, ...)
local errmsg = module.pcall_err_withfile(fn, ...)
- return errmsg:gsub('^%.%.%./helpers%.lua:0: ', '')
- :gsub('^Error executing lua:- ' ,'')
- :gsub('^%[string "<nvim>"%]:0: ' ,'')
+ return errmsg
+ :gsub('^%.%.%./helpers%.lua:0: ', '')
+ :gsub('^Error executing lua:- ', '')
+ :gsub('^%[string "<nvim>"%]:0: ', '')
end
function module.pcall_err(...)
@@ -243,7 +260,7 @@ function module.pcall_err(...)
end
function module.remove_trace(s)
- return (s:gsub("\n%s*stack traceback:.*", ""))
+ return (s:gsub('\n%s*stack traceback:.*', ''))
end
-- initial_path: directory to recurse into
@@ -251,12 +268,14 @@ end
-- exc_re: exclude pattern(s) (string or table)
function module.glob(initial_path, re, exc_re)
exc_re = type(exc_re) == 'table' and exc_re or { exc_re }
- local paths_to_check = {initial_path}
+ local paths_to_check = { initial_path }
local ret = {}
local checked_files = {}
local function is_excluded(path)
for _, pat in pairs(exc_re) do
- if path:match(pat) then return true end
+ if path:match(pat) then
+ return true
+ end
end
return false
end
@@ -318,7 +337,7 @@ function module.check_logs()
out:write(start_msg .. '\n')
if status then
for line in f:lines() do
- out:write('= '..line..'\n')
+ out:write('= ' .. line .. '\n')
end
f:close()
else
@@ -331,9 +350,10 @@ function module.check_logs()
end
end
end
- assert(0 == #runtime_errors, string.format(
- 'Found runtime errors in logfile(s): %s',
- table.concat(runtime_errors, ', ')))
+ assert(
+ 0 == #runtime_errors,
+ string.format('Found runtime errors in logfile(s): %s', table.concat(runtime_errors, ', '))
+ )
end
function module.sysname()
@@ -344,18 +364,16 @@ function module.sysname()
end
function module.is_os(s)
- if not (s == 'win'
- or s == 'mac'
- or s == 'freebsd'
- or s == 'openbsd'
- or s == 'bsd') then
- error('unknown platform: '..tostring(s))
- end
- return not not ((s == 'win' and (module.sysname():find('windows') or module.sysname():find('mingw')))
+ if not (s == 'win' or s == 'mac' or s == 'freebsd' or s == 'openbsd' or s == 'bsd') then
+ error('unknown platform: ' .. tostring(s))
+ end
+ 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')
- or (s == 'bsd' and module.sysname():find('bsd')))
+ or (s == 'bsd' and module.sysname():find('bsd'))
+ )
end
local function tmpdir_get()
@@ -371,7 +389,7 @@ end
module.tmpname = (function()
local seq = 0
local tmpdir = tmpdir_get()
- return (function()
+ return function()
if tmpdir_is_local(tmpdir) then
-- Cannot control os.tmpname() dir, so hack our own tmpname() impl.
seq = seq + 1
@@ -384,15 +402,15 @@ module.tmpname = (function()
if module.is_os('win') and fname:sub(1, 2) == '\\s' then
-- In Windows tmpname() returns a filename starting with
-- special sequence \s, prepend $TEMP path
- return tmpdir..fname
+ return tmpdir .. fname
elseif fname:match('^/tmp') and module.is_os('mac') then
-- In OS X /tmp links to /private/tmp
- return '/private'..fname
+ return '/private' .. fname
else
return fname
end
end
- end)
+ end
end)()
function module.hasenv(name)
@@ -417,14 +435,17 @@ function module.check_cores(app, force) -- luacheck: ignore
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 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"'
local random_skip = false
-- Workspace-local $TMPDIR, scrubbed and pattern-escaped.
-- "./Xtest-tmpdir/" => "Xtest%-tmpdir"
- local local_tmpdir = (tmpdir_is_local(tmpdir_get())
- and relpath(tmpdir_get()):gsub('^[ ./]+',''):gsub('%/+$',''):gsub('([^%w])', '%%%1')
- or nil)
+ local local_tmpdir = (
+ tmpdir_is_local(tmpdir_get())
+ and relpath(tmpdir_get()):gsub('^[ ./]+', ''):gsub('%/+$', ''):gsub('([^%w])', '%%%1')
+ or nil
+ )
local db_cmd
if module.hasenv('NVIM_TEST_CORE_GLOB_DIRECTORY') then
initial_path = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY')
@@ -444,7 +465,7 @@ function module.check_cores(app, force) -- luacheck: ignore
else
re = '/core[^/]*$'
end
- exc_re = { '^/%.deps$', '^/%'..deps_prefix()..'$', local_tmpdir, '^/%node_modules$' }
+ exc_re = { '^/%.deps$', '^/%' .. deps_prefix() .. '$', local_tmpdir, '^/%node_modules$' }
db_cmd = gdb_db_cmd
random_skip = true
end
@@ -457,7 +478,7 @@ function module.check_cores(app, force) -- luacheck: ignore
local found_cores = 0
local out = io.stdout
for _, core in ipairs(cores) do
- local len = 80 - #core - #('Core file ') - 2
+ local len = 80 - #core - #'Core file ' - 2
local esigns = ('='):rep(len / 2)
out:write(('\n%s Core file %s %s\n'):format(esigns, core, esigns))
out:flush()
@@ -471,7 +492,7 @@ function module.check_cores(app, force) -- luacheck: ignore
end
tests_skipped = 0
if found_cores > 0 then
- error("crash detected (see above)")
+ error('crash detected (see above)')
end
end
@@ -597,9 +618,9 @@ function module.dedent(str, leave_indent)
-- create a pattern for the indent
indent = indent:gsub('%s', '[ \t]')
-- strip it from the first line
- str = str:gsub('^'..indent, left_indent)
+ str = str:gsub('^' .. indent, left_indent)
-- strip it from the remaining lines
- str = str:gsub('[\n]'..indent, '\n' .. left_indent)
+ str = str:gsub('[\n]' .. indent, '\n' .. left_indent)
return str
end
@@ -611,13 +632,38 @@ local function format_float(v)
end
local SUBTBL = {
- '\\000', '\\001', '\\002', '\\003', '\\004',
- '\\005', '\\006', '\\007', '\\008', '\\t',
- '\\n', '\\011', '\\012', '\\r', '\\014',
- '\\015', '\\016', '\\017', '\\018', '\\019',
- '\\020', '\\021', '\\022', '\\023', '\\024',
- '\\025', '\\026', '\\027', '\\028', '\\029',
- '\\030', '\\031',
+ '\\000',
+ '\\001',
+ '\\002',
+ '\\003',
+ '\\004',
+ '\\005',
+ '\\006',
+ '\\007',
+ '\\008',
+ '\\t',
+ '\\n',
+ '\\011',
+ '\\012',
+ '\\r',
+ '\\014',
+ '\\015',
+ '\\016',
+ '\\017',
+ '\\018',
+ '\\019',
+ '\\020',
+ '\\021',
+ '\\022',
+ '\\023',
+ '\\024',
+ '\\025',
+ '\\026',
+ '\\027',
+ '\\028',
+ '\\029',
+ '\\030',
+ '\\031',
}
-- Formats Lua value `v`.
@@ -647,13 +693,14 @@ function module.format_luav(v, indent, opts)
if opts.literal_strings then
ret = v
else
- local quote = opts.dquote_strings and '"' or '\''
- ret = quote .. tostring(v):gsub(
- opts.dquote_strings and '["\\]' or '[\'\\]',
- '\\%0'):gsub(
- '[%z\1-\31]', function(match)
+ local quote = opts.dquote_strings and '"' or "'"
+ ret = quote
+ .. tostring(v)
+ :gsub(opts.dquote_strings and '["\\]' or "['\\]", '\\%0')
+ :gsub('[%z\1-\31]', function(match)
return SUBTBL[match:byte() + 1]
- end) .. quote
+ end)
+ .. quote
end
elseif type(v) == 'table' then
if v == module.REMOVE_THIS then
@@ -664,8 +711,7 @@ function module.format_luav(v, indent, opts)
local non_empty = false
local format_luav = module.format_luav
for i, subv in ipairs(v) do
- ret = ('%s%s%s,%s'):format(ret, next_indent,
- format_luav(subv, next_indent_arg, opts), nl)
+ ret = ('%s%s%s,%s'):format(ret, next_indent, format_luav(subv, next_indent_arg, opts), nl)
processed_keys[i] = true
non_empty = true
end
@@ -674,8 +720,7 @@ function module.format_luav(v, indent, opts)
if type(k) == 'string' and k:match('^[a-zA-Z_][a-zA-Z0-9_]*$') then
ret = ret .. next_indent .. k .. ' = '
else
- ret = ('%s%s[%s] = '):format(ret, next_indent,
- format_luav(k, nil, opts))
+ ret = ('%s%s[%s] = '):format(ret, next_indent, format_luav(k, nil, opts))
end
ret = ret .. format_luav(subv, next_indent_arg, opts) .. ',' .. nl
non_empty = true
@@ -684,7 +729,7 @@ function module.format_luav(v, indent, opts)
if nl == ' ' and non_empty then
ret = ret:sub(1, -3)
end
- ret = ret .. indent .. '}'
+ ret = ret .. indent .. '}'
end
elseif type(v) == 'number' then
if v % 1 == 0 then
@@ -709,7 +754,7 @@ end
-- Commit: 520c0b91a528
function module.format_string(fmt, ...)
local i = 0
- local args = {...}
+ local args = { ... }
local function getarg()
i = i + 1
return args[i]
@@ -728,7 +773,7 @@ function module.format_string(fmt, ...)
-- Builtin %q is replaced here as it gives invalid and inconsistent with
-- luajit results for e.g. "\e" on lua: luajit transforms that into `\27`,
-- lua leaves as-is.
- arg = module.format_luav(arg, nil, {dquote_strings = (subfmt:sub(-1) == 'q')})
+ arg = module.format_luav(arg, nil, { dquote_strings = (subfmt:sub(-1) == 'q') })
subfmt = subfmt:sub(1, -2) .. 's'
end
if subfmt == '%e' then
@@ -767,27 +812,27 @@ end
function module.hexdump(str)
local len = string.len(str)
- local dump = ""
- local hex = ""
- local asc = ""
+ local dump = ''
+ local hex = ''
+ local asc = ''
for i = 1, len do
if 1 == i % 8 then
- dump = dump .. hex .. asc .. "\n"
- hex = string.format("%04x: ", i - 1)
- asc = ""
+ dump = dump .. hex .. asc .. '\n'
+ hex = string.format('%04x: ', i - 1)
+ asc = ''
end
local ord = string.byte(str, i)
- hex = hex .. string.format("%02x ", ord)
+ hex = hex .. string.format('%02x ', ord)
if ord >= 32 and ord <= 126 then
asc = asc .. string.char(ord)
else
- asc = asc .. "."
+ asc = asc .. '.'
end
end
- return dump .. hex .. string.rep(" ", 8 - len % 8) .. asc
+ return dump .. hex .. string.rep(' ', 8 - len % 8) .. asc
end
-- Reads text lines from `filename` into a table.
@@ -805,16 +850,16 @@ function module.read_file_list(filename, start)
-- There is no need to read more than the last 2MB of the log file, so seek
-- to that.
- local file_size = file:seek("end")
+ local file_size = file:seek('end')
local offset = file_size - 2000000
if offset < 0 then
offset = 0
end
- file:seek("set", offset)
+ file:seek('set', offset)
local lines = {}
local i = 1
- local line = file:read("*l")
+ local line = file:read('*l')
while line ~= nil do
if i >= start then
table.insert(lines, line)
@@ -823,7 +868,7 @@ function module.read_file_list(filename, start)
end
end
i = i + 1
- line = file:read("*l")
+ line = file:read('*l')
end
file:close()
return lines
@@ -875,13 +920,16 @@ function module.read_nvim_log(logfile, ci_rename)
local is_ci = module.is_ci()
local keep = is_ci and 100 or 10
local lines = module.read_file_list(logfile, -keep) or {}
- local log = (('-'):rep(78)..'\n'
- ..string.format('$NVIM_LOG_FILE: %s\n', logfile)
- ..(#lines > 0 and '(last '..tostring(keep)..' lines)\n' or '(empty)\n'))
- for _,line in ipairs(lines) do
- log = log..line..'\n'
- end
- log = log..('-'):rep(78)..'\n'
+ local log = (
+ ('-'):rep(78)
+ .. '\n'
+ .. string.format('$NVIM_LOG_FILE: %s\n', logfile)
+ .. (#lines > 0 and '(last ' .. tostring(keep) .. ' lines)\n' or '(empty)\n')
+ )
+ for _, line in ipairs(lines) do
+ log = log .. line .. '\n'
+ end
+ log = log .. ('-'):rep(78) .. '\n'
if is_ci and ci_rename then
os.rename(logfile, logfile .. '.displayed')
end