aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-09-06 17:17:37 -0700
committerJustin M. Keyes <justinkz@gmail.com>2019-09-06 17:19:07 -0700
commit7e1c9598617a140e40a0a22676c0631294617246 (patch)
treee6988da22f16062b57d50daeda084bcc489a6a1d /test/helpers.lua
parentaf946046b922dc5d5285a70a23d11916d8389a5d (diff)
downloadrneovim-7e1c9598617a140e40a0a22676c0631294617246.tar.gz
rneovim-7e1c9598617a140e40a0a22676c0631294617246.tar.bz2
rneovim-7e1c9598617a140e40a0a22676c0631294617246.zip
test: Eliminate expect_err
Eliminate `expect_err` in favor of `pcall_err` + `eq` or `matches`.
Diffstat (limited to 'test/helpers.lua')
-rw-r--r--test/helpers.lua15
1 files changed, 7 insertions, 8 deletions
diff --git a/test/helpers.lua b/test/helpers.lua
index b6fd6d7e3f..ebc0a7d811 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -74,15 +74,14 @@ function module.matches(pat, actual)
error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual))
end
--- Expects an error matching Lua pattern `pat`.
---
-function module.expect_err(pat, fn, ...)
- assert(type(fn) == 'function')
- local fn_args = {...}
- assert.error_matches(function() return fn(unpack(fn_args)) end, pat)
-end
-
-- Invokes `fn` and returns the error string, or raises an error if `fn` succeeds.
+--
+-- Usage:
+-- -- Match exact string.
+-- eq('e', pcall_err(function(a, b) error('e') end, 'arg1', 'arg2'))
+-- -- Match Lua pattern.
+-- matches('e[or]+$', pcall_err(function(a, b) error('some error') end, 'arg1', 'arg2'))
+--
function module.pcall_err(fn, ...)
assert(type(fn) == 'function')
local status, rv = pcall(fn, ...)