aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-04-01 12:52:28 +0300
committerZyX <kp-pav@yandex.ru>2017-04-01 12:52:28 +0300
commit9dd0d4f8b9217f711fff32e9f47674e556a8fab0 (patch)
tree7a6fa451d674859d3c7aca308f443709446e56b3
parent046d6a8dfe8ef5b319fdd7139303d46b56b5daa6 (diff)
downloadrneovim-9dd0d4f8b9217f711fff32e9f47674e556a8fab0.tar.gz
rneovim-9dd0d4f8b9217f711fff32e9f47674e556a8fab0.tar.bz2
rneovim-9dd0d4f8b9217f711fff32e9f47674e556a8fab0.zip
unittests: Add trace description right to the error message
-rw-r--r--test/functional/helpers.lua23
-rw-r--r--test/helpers.lua23
-rw-r--r--test/unit/helpers.lua23
3 files changed, 38 insertions, 31 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index ab36508262..335cf3c3ff 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -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))
diff --git a/test/helpers.lua b/test/helpers.lua
index 82451bc61d..3fc10e9e30 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -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,
}
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index c8296abb2a..048027692a 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -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