aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2020-09-12 19:04:22 -0700
committerTJ DeVries <devries.timothyj@gmail.com>2020-10-05 09:47:59 -0400
commit8e77d70e29f936f4e708ee3244046188b8ad0383 (patch)
treede9bfa3d5704cf9cfb92fc9a50157718d940b518 /test/helpers.lua
parentaad7a74053e16611de04da4151e3e3be50746e3d (diff)
downloadrneovim-8e77d70e29f936f4e708ee3244046188b8ad0383.tar.gz
rneovim-8e77d70e29f936f4e708ee3244046188b8ad0383.tar.bz2
rneovim-8e77d70e29f936f4e708ee3244046188b8ad0383.zip
test/vim.validate(): assert normalized stacktrace
- The previous commit lost information in the tests. Instead, add some more "normalization" substitutions in pcall_err(), so that the general shape of the stacktrace is included in the asserted text. - Eliminate contains(), it is redundant with matches()
Diffstat (limited to 'test/helpers.lua')
-rw-r--r--test/helpers.lua48
1 files changed, 28 insertions, 20 deletions
diff --git a/test/helpers.lua b/test/helpers.lua
index d59ce2a7c7..68f0c92244 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -99,9 +99,6 @@ function module.matches(pat, actual)
end
error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual))
end
-function module.contains(pat, actual)
- return module.matches(".*" .. pat .. ".*", actual)
-end
--- Asserts that `pat` matches one or more lines in the tail of $NVIM_LOG_FILE.
---
@@ -119,8 +116,12 @@ function module.assert_log(pat, logfile)
pat, nrlines, logfile, logtail))
end
--- Invokes `fn` and returns the error string (may truncate full paths), or
--- raises an error if `fn` succeeds.
+-- Invokes `fn` and returns the error string (with truncated paths), or raises
+-- an error if `fn` succeeds.
+--
+-- Replaces line/column numbers with zero:
+-- shared.lua:0: in function 'gsplit'
+-- shared.lua:0: in function <shared.lua:0>'
--
-- Usage:
-- -- Match exact string.
@@ -128,29 +129,36 @@ end
-- -- Match Lua pattern.
-- matches('e[or]+$', pcall_err(function(a, b) error('some error') end, 'arg1', 'arg2'))
--
-function module.pcall_err(fn, ...)
+function module.pcall_err_withfile(fn, ...)
assert(type(fn) == 'function')
local status, rv = pcall(fn, ...)
if status == true then
error('expected failure, but got success')
end
- -- From this:
- -- /home/foo/neovim/runtime/lua/vim/shared.lua:186: Expected string, got number
- -- to this:
- -- Expected string, got number
- local errmsg = tostring(rv):gsub('^[^:]+:%d+: ', '')
- -- From this:
- -- Error executing lua: /very/long/foo.lua:186: Expected string, got number
- -- to this:
- -- Error executing lua: .../foo.lua:186: Expected string, got number
- errmsg = errmsg:gsub([[lua: [a-zA-Z]?:?[^:]-[/\]([^:/\]+):%d+: ]], 'lua: .../%1: ')
- -- Compiled modules will not have a path and will just be a name like
- -- shared.lua:186, so strip the number.
- errmsg = errmsg:gsub([[lua: ([^:/\ ]+):%d+: ]], 'lua: .../%1: ')
- -- ^ Windows drive-letter (C:)
+ -- From:
+ -- C:/long/path/foo.lua:186: Expected string, got number
+ -- to:
+ -- .../foo.lua:0: Expected string, got number
+ local errmsg = tostring(rv):gsub('[^%s]-[/\\]([^%s:/\\]+):%d+', '.../%1:0')
+ -- 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')
+ -- Scrub tab chars:
+ errmsg = errmsg:gsub('\t', ' ')
+ -- In Lua 5.1, we sometimes get a "(tail call): ?" on the last line.
+ -- We remove this so that the tests are not lua dependent.
+ errmsg = errmsg:gsub('%s*%(tail call%): %?', '')
+
return errmsg
end
+function module.pcall_err(fn, ...)
+ local errmsg = module.pcall_err_withfile(fn, ...)
+
+ return errmsg:gsub('.../helpers.lua:0: ', '')
+end
+
-- initial_path: directory to recurse into
-- re: include pattern (string)
-- exc_re: exclude pattern(s) (string or table)