mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
unittests: Add trace description right to the error message
This commit is contained in:
parent
046d6a8dfe
commit
9dd0d4f8b9
@ -16,6 +16,7 @@ local eq = global_helpers.eq
|
||||
local ok = global_helpers.ok
|
||||
local map = global_helpers.map
|
||||
local filter = global_helpers.filter
|
||||
local dedent = global_helpers.dedent
|
||||
|
||||
local start_dir = lfs.currentdir()
|
||||
-- XXX: NVIM_PROG takes precedence, QuickBuild sets it.
|
||||
@ -191,28 +192,6 @@ local function nvim_feed(input)
|
||||
end
|
||||
end
|
||||
|
||||
local function dedent(str)
|
||||
-- find minimum common indent across lines
|
||||
local indent = nil
|
||||
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
|
||||
-- no minimum common indent
|
||||
return str
|
||||
end
|
||||
-- create a pattern for the indent
|
||||
indent = indent:gsub('%s', '[ \t]')
|
||||
-- strip it from the first line
|
||||
str = str:gsub('^'..indent, '')
|
||||
-- strip it from the remaining lines
|
||||
str = str:gsub('[\n]'..indent, '\n')
|
||||
return str
|
||||
end
|
||||
|
||||
local function feed(...)
|
||||
for _, v in ipairs({...}) do
|
||||
nvim_feed(dedent(v))
|
||||
|
@ -251,6 +251,28 @@ local function concat_tables(...)
|
||||
return ret
|
||||
end
|
||||
|
||||
local function dedent(str)
|
||||
-- find minimum common indent across lines
|
||||
local indent = nil
|
||||
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
|
||||
-- no minimum common indent
|
||||
return str
|
||||
end
|
||||
-- create a pattern for the indent
|
||||
indent = indent:gsub('%s', '[ \t]')
|
||||
-- strip it from the first line
|
||||
str = str:gsub('^'..indent, '')
|
||||
-- strip it from the remaining lines
|
||||
str = str:gsub('[\n]'..indent, '\n')
|
||||
return str
|
||||
end
|
||||
|
||||
return {
|
||||
eq = eq,
|
||||
neq = neq,
|
||||
@ -265,4 +287,5 @@ return {
|
||||
hasenv = hasenv,
|
||||
which = which,
|
||||
concat_tables = concat_tables,
|
||||
dedent = dedent,
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ local posix = nil
|
||||
local syscall = nil
|
||||
|
||||
local check_cores = global_helpers.check_cores
|
||||
local dedent = global_helpers.dedent
|
||||
local neq = global_helpers.neq
|
||||
local map = global_helpers.map
|
||||
local eq = global_helpers.eq
|
||||
@ -525,18 +526,22 @@ local hook_sfnamelen = 30
|
||||
local hook_numlen = 5
|
||||
local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 + hook_numlen) + 1
|
||||
|
||||
local tracehelp = dedent([[
|
||||
┌ Trace type: _r_eturn from function , function _c_all, _l_ine executed,
|
||||
│ _t_ail return, _C_ount (should not actually appear).
|
||||
│┏ Function type: _L_ua function, _C_ function, _m_ain part of chunk,
|
||||
│┃ function that did _t_ail call.
|
||||
│┃┌ Function name type: _g_lobal, _l_ocal, _m_ethod, _f_ield, _u_pvalue,
|
||||
│┃│ space for unknown.
|
||||
│┃│ ┏ Source file name ┌ Function name ┏ Line
|
||||
│┃│ ┃ (trunc to 30 bytes, no .lua) │ (truncated to last 30 bytes) ┃ number
|
||||
CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n
|
||||
]])
|
||||
|
||||
local function child_sethook(wr)
|
||||
if os.getenv('NVIM_TEST_NO_TRACE') == '1' then
|
||||
return
|
||||
end
|
||||
-- Message:
|
||||
-- |> msg char (1)
|
||||
-- ||> what char (1)
|
||||
-- |||> namewhat char (1)
|
||||
-- ||| |> source file name (30)
|
||||
-- ||| | |> function name (30)
|
||||
-- ||| | | |> line number (5)
|
||||
-- CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n
|
||||
local function hook(reason, lnum)
|
||||
local msgchar = reason:sub(1, 1)
|
||||
if reason == 'count' then
|
||||
@ -636,7 +641,7 @@ local function check_child_err(rd)
|
||||
end
|
||||
local res = sc.read(rd, 2)
|
||||
if #res ~= 2 then
|
||||
local error = 'Test crashed, trace:\n'
|
||||
local error = '\nTest crashed, trace:\n' .. tracehelp
|
||||
for i = 1, #trace do
|
||||
error = error .. trace[i]
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user