aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/vim_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-05-10 19:18:58 +0200
committerGitHub <noreply@github.com>2018-05-10 19:18:58 +0200
commit8d40b3617c8bb10af5d4d4abcab0dfe77a4e807d (patch)
treecded38835bde85bc8a1682303617f84bf2549f7e /test/functional/api/vim_spec.lua
parent1cd8517344c0d99ca6fb3246c70f78d271993cf6 (diff)
parent966e7abc4960746b4dde618807fb5516d162ae2d (diff)
downloadrneovim-8d40b3617c8bb10af5d4d4abcab0dfe77a4e807d.tar.gz
rneovim-8d40b3617c8bb10af5d4d4abcab0dfe77a4e807d.tar.bz2
rneovim-8d40b3617c8bb10af5d4d4abcab0dfe77a4e807d.zip
Merge #8371 'API: more reliable/descriptive VimL errors'
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r--test/functional/api/vim_spec.lua69
1 files changed, 48 insertions, 21 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 0ff755b320..2d13506d6d 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -5,6 +5,7 @@ local global_helpers = require('test.helpers')
local NIL = helpers.NIL
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
local command = helpers.command
+local eval = helpers.eval
local funcs = helpers.funcs
local iswin = helpers.iswin
local meth_pcall = helpers.meth_pcall
@@ -40,20 +41,20 @@ describe('api', function()
os.remove(fname)
end)
- it("parse error: fails (specific error), does NOT update v:errmsg", function()
- -- Most API methods return generic errors (or no error) if a VimL
- -- expression fails; nvim_command returns the VimL error details.
+ it('VimL validation error: fails with specific error', function()
local status, rv = pcall(nvim, "command", "bogus_command")
eq(false, status) -- nvim_command() failed.
eq("E492:", string.match(rv, "E%d*:")) -- VimL error was returned.
- eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
+ eq('', eval('v:exception'))
end)
- it("runtime error: fails (specific error)", function()
+ it('VimL execution error: fails with specific error', function()
local status, rv = pcall(nvim, "command_output", "buffer 23487")
eq(false, status) -- nvim_command() failed.
eq("E86: Buffer 23487 does not exist", string.match(rv, "E%d*:.*"))
- eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ eq('', eval('v:exception'))
end)
end)
@@ -109,21 +110,21 @@ describe('api', function()
eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]]))
end)
- it("parse error: fails (specific error), does NOT update v:errmsg", function()
+ it('VimL validation error: fails with specific error', function()
local status, rv = pcall(nvim, "command_output", "bogus commannnd")
eq(false, status) -- nvim_command_output() failed.
eq("E492: Not an editor command: bogus commannnd",
string.match(rv, "E%d*:.*"))
- eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
-- Verify NO hit-enter prompt.
eq({mode='n', blocking=false}, nvim("get_mode"))
end)
- it("runtime error: fails (specific error)", function()
+ it('VimL execution error: fails with specific error', function()
local status, rv = pcall(nvim, "command_output", "buffer 42")
eq(false, status) -- nvim_command_output() failed.
eq("E86: Buffer 42 does not exist", string.match(rv, "E%d*:.*"))
- eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
-- Verify NO hit-enter prompt.
eq({mode='n', blocking=false}, nvim("get_mode"))
end)
@@ -145,11 +146,10 @@ describe('api', function()
eq(2, request("vim_eval", "1+1"))
end)
- it("VimL error: fails (generic error), does NOT update v:errmsg", function()
- local status, rv = pcall(nvim, "eval", "bogus expression")
- eq(false, status) -- nvim_eval() failed.
- ok(nil ~= string.find(rv, "Failed to evaluate expression"))
- eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ it("VimL error: returns error details, does NOT update v:errmsg", function()
+ expect_err('E121: Undefined variable: bogus', request,
+ 'nvim_eval', 'bogus expression')
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
end)
@@ -160,12 +160,39 @@ describe('api', function()
eq(17, nvim('call_function', 'eval', {17}))
eq('foo', nvim('call_function', 'simplify', {'this/./is//redundant/../../../foo'}))
end)
- it("VimL error: fails (generic error), does NOT update v:errmsg", function()
- local status, rv = pcall(nvim, "call_function", "bogus function", {"arg1"})
- eq(false, status) -- nvim_call_function() failed.
- ok(nil ~= string.find(rv, "Error calling function"))
- eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+
+ it("VimL validation error: returns specific error, does NOT update v:errmsg", function()
+ expect_err('E117: Unknown function: bogus function', request,
+ 'nvim_call_function', 'bogus function', {'arg1'})
+ expect_err('E119: Not enough arguments for function: atan', request,
+ 'nvim_call_function', 'atan', {})
+ eq('', eval('v:exception'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ end)
+
+ it("VimL error: returns error details, does NOT update v:errmsg", function()
+ expect_err('E808: Number or Float required', request,
+ 'nvim_call_function', 'atan', {'foo'})
+ expect_err('Invalid channel stream "xxx"', request,
+ 'nvim_call_function', 'chanclose', {999, 'xxx'})
+ expect_err('E900: Invalid channel id', request,
+ 'nvim_call_function', 'chansend', {999, 'foo'})
+ eq('', eval('v:exception'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
+
+ it("VimL exception: returns exception details, does NOT update v:errmsg", function()
+ source([[
+ function! Foo() abort
+ throw 'wtf'
+ endfunction
+ ]])
+ expect_err('wtf', request,
+ 'nvim_call_function', 'Foo', {})
+ eq('', eval('v:exception'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ end)
+
it('validates args', function()
local too_many_args = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }
source([[
@@ -216,7 +243,7 @@ describe('api', function()
'nvim_call_dict_function', 'g:d', 'baz', {1,2})
expect_err('Not a function: meep', request,
'nvim_call_dict_function', 'g:d', 'meep', {1,2})
- expect_err('Error calling function', request,
+ expect_err('E117: Unknown function: f', request,
'nvim_call_dict_function', { f = '' }, 'f', {1,2})
expect_err('Not a function: f', request,
'nvim_call_dict_function', "{ 'f': '' }", 'f', {1,2})