aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/buffer_spec.lua32
-rw-r--r--test/functional/api/buffer_updates_spec.lua4
-rw-r--r--test/functional/api/command_spec.lua10
-rw-r--r--test/functional/api/keymap_spec.lua95
-rw-r--r--test/functional/api/server_requests_spec.lua6
-rw-r--r--test/functional/api/tabpage_spec.lua8
-rw-r--r--test/functional/api/ui_spec.lua22
-rw-r--r--test/functional/api/vim_spec.lua170
-rw-r--r--test/functional/api/window_spec.lua26
9 files changed, 180 insertions, 193 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 849fbedd01..da7515f012 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -10,11 +10,10 @@ local exc_exec = helpers.exc_exec
local feed_command = helpers.feed_command
local insert = helpers.insert
local NIL = helpers.NIL
-local meth_pcall = helpers.meth_pcall
local command = helpers.command
local bufmeths = helpers.bufmeths
local feed = helpers.feed
-local expect_err = helpers.expect_err
+local pcall_err = helpers.pcall_err
describe('api/buf', function()
before_each(clear)
@@ -191,17 +190,14 @@ describe('api/buf', function()
it('fails correctly when input is not valid', function()
eq(1, curbufmeths.get_number())
- local err, emsg = pcall(bufmeths.set_lines, 1, 1, 2, false, {'b\na'})
- eq(false, err)
- local exp_emsg = 'String cannot contain newlines'
- -- Expected {filename}:{lnum}: {exp_emsg}
- eq(': ' .. exp_emsg, emsg:sub(-#exp_emsg - 2))
+ eq([[String cannot contain newlines]],
+ pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'}))
end)
it("fails if 'nomodifiable'", function()
command('set nomodifiable')
- expect_err([[Buffer is not 'modifiable']],
- bufmeths.set_lines, 1, 1, 2, false, {'a','b'})
+ eq([[Buffer is not 'modifiable']],
+ pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'a','b'}))
end)
it('has correct line_count when inserting and deleting', function()
@@ -407,8 +403,8 @@ describe('api/buf', function()
eq(16, get_offset(3))
eq(24, get_offset(4))
eq(29, get_offset(5))
- eq({false,'Index out of bounds'}, meth_pcall(get_offset, 6))
- eq({false,'Index out of bounds'}, meth_pcall(get_offset, -1))
+ eq('Index out of bounds', pcall_err(get_offset, 6))
+ eq('Index out of bounds', pcall_err(get_offset, -1))
curbufmeths.set_option('eol', false)
curbufmeths.set_option('fixeol', false)
@@ -441,15 +437,15 @@ describe('api/buf', function()
eq(1, funcs.exists('b:lua'))
curbufmeths.del_var('lua')
eq(0, funcs.exists('b:lua'))
- eq({false, 'Key not found: lua'}, meth_pcall(curbufmeths.del_var, 'lua'))
+ eq( 'Key not found: lua', pcall_err(curbufmeths.del_var, 'lua'))
curbufmeths.set_var('lua', 1)
command('lockvar b:lua')
- eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.del_var, 'lua'))
- eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.set_var, 'lua', 1))
- eq({false, 'Key is read-only: changedtick'},
- meth_pcall(curbufmeths.del_var, 'changedtick'))
- eq({false, 'Key is read-only: changedtick'},
- meth_pcall(curbufmeths.set_var, 'changedtick', 1))
+ eq('Key is locked: lua', pcall_err(curbufmeths.del_var, 'lua'))
+ eq('Key is locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1))
+ eq('Key is read-only: changedtick',
+ pcall_err(curbufmeths.del_var, 'changedtick'))
+ eq('Key is read-only: changedtick',
+ pcall_err(curbufmeths.set_var, 'changedtick', 1))
end)
end)
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index 89d0c6f000..05ca0d5f4d 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -3,8 +3,8 @@ local clear = helpers.clear
local eq, ok = helpers.eq, helpers.ok
local buffer, command, eval, nvim, next_msg = helpers.buffer,
helpers.command, helpers.eval, helpers.nvim, helpers.next_msg
-local expect_err = helpers.expect_err
local nvim_prog = helpers.nvim_prog
+local pcall_err = helpers.pcall_err
local sleep = helpers.sleep
local write_file = helpers.write_file
@@ -760,7 +760,7 @@ describe('API: buffer events:', function()
it('returns a proper error on nonempty options dict', function()
clear()
local b = editoriginal(false)
- expect_err("unexpected key: builtin", buffer, 'attach', b, false, {builtin="asfd"})
+ eq("unexpected key: builtin", pcall_err(buffer, 'attach', b, false, {builtin="asfd"}))
end)
it('nvim_buf_attach returns response after delay #8634', function()
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index b7520235b7..e6a9e11fd9 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -5,9 +5,9 @@ local clear = helpers.clear
local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
-local expect_err = helpers.expect_err
local meths = helpers.meths
local source = helpers.source
+local pcall_err = helpers.pcall_err
describe('nvim_get_commands', function()
local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', range=NIL, register=false, script_id=0, }
@@ -19,10 +19,10 @@ describe('nvim_get_commands', function()
end)
it('validates input', function()
- expect_err('builtin=true not implemented', meths.get_commands,
- {builtin=true})
- expect_err('unexpected key: foo', meths.get_commands,
- {foo='blah'})
+ eq('builtin=true not implemented', pcall_err(meths.get_commands,
+ {builtin=true}))
+ eq('unexpected key: foo', pcall_err(meths.get_commands,
+ {foo='blah'}))
end)
it('gets global user-defined commands', function()
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index fee787162e..773207d360 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -5,11 +5,11 @@ local clear = helpers.clear
local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq, neq = helpers.eq, helpers.neq
-local expect_err = helpers.expect_err
local feed = helpers.feed
local funcs = helpers.funcs
local meths = helpers.meths
local source = helpers.source
+local pcall_err = helpers.pcall_err
local shallowcopy = helpers.shallowcopy
local sleep = helpers.sleep
@@ -360,12 +360,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('error on empty LHS', function()
-- escape parentheses in lua string, else comparison fails erroneously
- expect_err('Invalid %(empty%) LHS',
- meths.set_keymap, '', '', 'rhs', {})
- expect_err('Invalid %(empty%) LHS',
- meths.set_keymap, '', '', '', {})
-
- expect_err('Invalid %(empty%) LHS', meths.del_keymap, '', '')
+ eq('Invalid (empty) LHS', pcall_err(meths.set_keymap, '', '', 'rhs', {}))
+ eq('Invalid (empty) LHS', pcall_err(meths.set_keymap, '', '', '', {}))
+ eq('Invalid (empty) LHS', pcall_err(meths.del_keymap, '', ''))
end)
it('error if LHS longer than MAXMAPLEN', function()
@@ -385,10 +382,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- 51 chars should produce an error
lhs = lhs..'1'
- expect_err('LHS exceeds maximum map length: '..lhs,
- meths.set_keymap, '', lhs, 'rhs', {})
- expect_err('LHS exceeds maximum map length: '..lhs,
- meths.del_keymap, '', lhs)
+ eq('LHS exceeds maximum map length: '..lhs,
+ pcall_err(meths.set_keymap, '', lhs, 'rhs', {}))
+ eq('LHS exceeds maximum map length: '..lhs,
+ pcall_err(meths.del_keymap, '', lhs))
end)
it('does not throw errors when rhs is longer than MAXMAPLEN', function()
@@ -404,48 +401,48 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
it('throws errors when given too-long mode shortnames', function()
- expect_err('Shortname is too long: map',
- meths.set_keymap, 'map', 'lhs', 'rhs', {})
+ eq('Shortname is too long: map',
+ pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {}))
- expect_err('Shortname is too long: vmap',
- meths.set_keymap, 'vmap', 'lhs', 'rhs', {})
+ eq('Shortname is too long: vmap',
+ pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {}))
- expect_err('Shortname is too long: xnoremap',
- meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {})
+ eq('Shortname is too long: xnoremap',
+ pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {}))
- expect_err('Shortname is too long: map', meths.del_keymap, 'map', 'lhs')
- expect_err('Shortname is too long: vmap', meths.del_keymap, 'vmap', 'lhs')
- expect_err('Shortname is too long: xnoremap', meths.del_keymap, 'xnoremap', 'lhs')
+ eq('Shortname is too long: map', pcall_err(meths.del_keymap, 'map', 'lhs'))
+ eq('Shortname is too long: vmap', pcall_err(meths.del_keymap, 'vmap', 'lhs'))
+ eq('Shortname is too long: xnoremap', pcall_err(meths.del_keymap, 'xnoremap', 'lhs'))
end)
it('error on invalid mode shortname', function()
- expect_err('Invalid mode shortname: " "',
- meths.set_keymap, ' ', 'lhs', 'rhs', {})
- expect_err('Invalid mode shortname: "m"',
- meths.set_keymap, 'm', 'lhs', 'rhs', {})
- expect_err('Invalid mode shortname: "?"',
- meths.set_keymap, '?', 'lhs', 'rhs', {})
- expect_err('Invalid mode shortname: "y"',
- meths.set_keymap, 'y', 'lhs', 'rhs', {})
- expect_err('Invalid mode shortname: "p"',
- meths.set_keymap, 'p', 'lhs', 'rhs', {})
- expect_err('Invalid mode shortname: "?"', meths.del_keymap, '?', 'lhs')
- expect_err('Invalid mode shortname: "y"', meths.del_keymap, 'y', 'lhs')
- expect_err('Invalid mode shortname: "p"', meths.del_keymap, 'p', 'lhs')
+ eq('Invalid mode shortname: " "',
+ pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "m"',
+ pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "?"',
+ pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "y"',
+ pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "p"',
+ pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs'))
+ eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs'))
+ eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs'))
end)
it('error on invalid optnames', function()
- expect_err('Invalid key: silentt',
- meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true})
- expect_err('Invalid key: sidd',
- meths.set_keymap, 'n', 'lhs', 'rhs', {sidd = false})
- expect_err('Invalid key: nowaiT',
- meths.set_keymap, 'n', 'lhs', 'rhs', {nowaiT = false})
+ eq('Invalid key: silentt',
+ pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true}))
+ eq('Invalid key: sidd',
+ pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {sidd = false}))
+ eq('Invalid key: nowaiT',
+ pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {nowaiT = false}))
end)
it('error on <buffer> option key', function()
- expect_err('Invalid key: buffer',
- meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true})
+ eq('Invalid key: buffer',
+ pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true}))
end)
local optnames = {'nowait', 'silent', 'script', 'expr', 'unique'}
@@ -454,8 +451,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('throws an error when given non-boolean value for '..opt, function()
local opts = {}
opts[opt] = 2
- expect_err('Gave non%-boolean value for an opt: '..opt,
- meths.set_keymap, 'n', 'lhs', 'rhs', opts)
+ eq('Gave non-boolean value for an opt: '..opt,
+ pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', opts))
end)
end
@@ -581,8 +578,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('throws appropriate error messages when setting <unique> maps', function()
meths.set_keymap('l', 'lhs', 'rhs', {})
- expect_err('E227: mapping already exists for lhs',
- meths.set_keymap, 'l', 'lhs', 'rhs', {unique = true})
+ eq('E227: mapping already exists for lhs',
+ pcall_err(meths.set_keymap, 'l', 'lhs', 'rhs', {unique = true}))
-- different mapmode, no error should be thrown
meths.set_keymap('t', 'lhs', 'rhs', {unique = true})
end)
@@ -750,8 +747,8 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
end
it('rejects negative bufnr values', function()
- expect_err('Wrong type for argument 1, expecting Buffer',
- bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {})
+ eq('Wrong type for argument 1, expecting Buffer',
+ pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}))
end)
it('can set mappings active in the current buffer but not others', function()
@@ -800,8 +797,8 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it("can't disable mappings given wrong buffer handle", function()
local first, second = make_two_buffers(false)
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
- expect_err('E31: No such mapping',
- bufmeths.del_keymap, second, '', 'lhs')
+ eq('E31: No such mapping',
+ pcall_err(bufmeths.del_keymap, second, '', 'lhs'))
-- should still work
switch_to_buf(first)
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index a20667de40..e275d8cd35 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -10,7 +10,7 @@ local ok = helpers.ok
local meths = helpers.meths
local spawn, merge_args = helpers.spawn, helpers.merge_args
local set_session = helpers.set_session
-local meth_pcall = helpers.meth_pcall
+local pcall_err = helpers.pcall_err
describe('server -> client', function()
local cid
@@ -220,8 +220,8 @@ describe('server -> client', function()
end)
it('returns an error if the request failed', function()
- eq({false, "Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist" },
- meth_pcall(eval, "rpcrequest(vim, 'does-not-exist')"))
+ eq("Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist",
+ pcall_err(eval, "rpcrequest(vim, 'does-not-exist')"))
end)
end)
diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua
index c49091db02..ed7ce72597 100644
--- a/test/functional/api/tabpage_spec.lua
+++ b/test/functional/api/tabpage_spec.lua
@@ -6,7 +6,7 @@ local curtabmeths = helpers.curtabmeths
local funcs = helpers.funcs
local request = helpers.request
local NIL = helpers.NIL
-local meth_pcall = helpers.meth_pcall
+local pcall_err = helpers.pcall_err
local command = helpers.command
describe('api/tabpage', function()
@@ -34,11 +34,11 @@ describe('api/tabpage', function()
eq(1, funcs.exists('t:lua'))
curtabmeths.del_var('lua')
eq(0, funcs.exists('t:lua'))
- eq({false, 'Key not found: lua'}, meth_pcall(curtabmeths.del_var, 'lua'))
+ eq('Key not found: lua', pcall_err(curtabmeths.del_var, 'lua'))
curtabmeths.set_var('lua', 1)
command('lockvar t:lua')
- eq({false, 'Key is locked: lua'}, meth_pcall(curtabmeths.del_var, 'lua'))
- eq({false, 'Key is locked: lua'}, meth_pcall(curtabmeths.set_var, 'lua', 1))
+ eq('Key is locked: lua', pcall_err(curtabmeths.del_var, 'lua'))
+ eq('Key is locked: lua', pcall_err(curtabmeths.set_var, 'lua', 1))
end)
it('tabpage_set_var returns the old value', function()
diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua
index b028a50b02..2758da6a1f 100644
--- a/test/functional/api/ui_spec.lua
+++ b/test/functional/api/ui_spec.lua
@@ -3,9 +3,9 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
-local expect_err = helpers.expect_err
local meths = helpers.meths
local request = helpers.request
+local pcall_err = helpers.pcall_err
describe('nvim_ui_attach()', function()
before_each(function()
@@ -18,20 +18,20 @@ describe('nvim_ui_attach()', function()
eq(999, eval('&columns'))
end)
it('invalid option returns error', function()
- expect_err('No such UI option: foo',
- meths.ui_attach, 80, 24, { foo={'foo'} })
+ eq('No such UI option: foo',
+ pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} }))
end)
it('validates channel arg', function()
- expect_err('UI not attached to channel: 1',
- request, 'nvim_ui_try_resize', 40, 10)
- expect_err('UI not attached to channel: 1',
- request, 'nvim_ui_set_option', 'rgb', true)
- expect_err('UI not attached to channel: 1',
- request, 'nvim_ui_detach')
+ eq('UI not attached to channel: 1',
+ pcall_err(request, 'nvim_ui_try_resize', 40, 10))
+ eq('UI not attached to channel: 1',
+ pcall_err(request, 'nvim_ui_set_option', 'rgb', true))
+ eq('UI not attached to channel: 1',
+ pcall_err(request, 'nvim_ui_detach'))
local screen = Screen.new()
screen:attach({rgb=false})
- expect_err('UI already attached to channel: 1',
- request, 'nvim_ui_attach', 40, 10, { rgb=false })
+ eq('UI already attached to channel: 1',
+ pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb=false }))
end)
end)
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index b80b1c87af..c34e7a0945 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -8,8 +8,8 @@ local eval = helpers.eval
local expect = helpers.expect
local funcs = helpers.funcs
local iswin = helpers.iswin
-local meth_pcall = helpers.meth_pcall
local meths = helpers.meths
+local matches = helpers.matches
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
local is_os = helpers.is_os
local parse_context = helpers.parse_context
@@ -17,7 +17,7 @@ local request = helpers.request
local source = helpers.source
local next_msg = helpers.next_msg
-local expect_err = helpers.expect_err
+local pcall_err = helpers.pcall_err
local format_string = helpers.format_string
local intchar2lua = helpers.intchar2lua
local mergedicts_copy = helpers.mergedicts_copy
@@ -27,25 +27,25 @@ describe('API', function()
it('validates requests', function()
-- RPC
- expect_err('Invalid method: bogus$',
- request, 'bogus')
- expect_err('Invalid method: … の り 。…$',
- request, '… の り 。…')
- expect_err('Invalid method: <empty>$',
- request, '')
+ matches('Invalid method: bogus$',
+ pcall_err(request, 'bogus'))
+ matches('Invalid method: … の り 。…$',
+ pcall_err(request, '… の り 。…'))
+ matches('Invalid method: <empty>$',
+ pcall_err(request, ''))
-- Non-RPC: rpcrequest(v:servername) uses internal channel.
- expect_err('Invalid method: … の り 。…$',
- request, 'nvim_eval',
- [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), '… の り 。…')]=])
- expect_err('Invalid method: bogus$',
- request, 'nvim_eval',
- [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), 'bogus')]=])
+ matches('Invalid method: … の り 。…$',
+ pcall_err(request, 'nvim_eval',
+ [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), '… の り 。…')]=]))
+ matches('Invalid method: bogus$',
+ pcall_err(request, 'nvim_eval',
+ [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), 'bogus')]=]))
-- XXX: This must be the last one, else next one will fail:
-- "Packer instance already working. Use another Packer ..."
- expect_err("can't serialize object$",
- request, nil)
+ matches("can't serialize object$",
+ pcall_err(request, nil))
end)
it('handles errors in async requests', function()
@@ -203,8 +203,8 @@ describe('API', function()
end)
it("VimL error: returns error details, does NOT update v:errmsg", function()
- expect_err('E121: Undefined variable: bogus$', request,
- 'nvim_eval', 'bogus expression')
+ eq('Vim:E121: Undefined variable: bogus',
+ pcall_err(request, 'nvim_eval', 'bogus expression'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
end)
@@ -218,21 +218,21 @@ describe('API', function()
end)
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('Vim:E117: Unknown function: bogus function',
+ pcall_err(request, 'nvim_call_function', 'bogus function', {'arg1'}))
+ eq('Vim:E119: Not enough arguments for function: atan',
+ pcall_err(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('Vim:E808: Number or Float required',
+ pcall_err(request, 'nvim_call_function', 'atan', {'foo'}))
+ eq('Vim:Invalid channel stream "xxx"',
+ pcall_err(request, 'nvim_call_function', 'chanclose', {999, 'xxx'}))
+ eq('Vim:E900: Invalid channel id',
+ pcall_err(request, 'nvim_call_function', 'chansend', {999, 'foo'}))
eq('', eval('v:exception'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
@@ -243,8 +243,7 @@ describe('API', function()
throw 'wtf'
endfunction
]])
- expect_err('wtf$', request,
- 'nvim_call_function', 'Foo', {})
+ eq('wtf', pcall_err(request, 'nvim_call_function', 'Foo', {}))
eq('', eval('v:exception'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
@@ -257,8 +256,8 @@ describe('API', function()
endfunction
]])
-- E740
- expect_err('Function called with too many arguments$', request,
- 'nvim_call_function', 'Foo', too_many_args)
+ eq('Function called with too many arguments',
+ pcall_err(request, 'nvim_call_function', 'Foo', too_many_args))
end)
end)
@@ -293,24 +292,24 @@ describe('API', function()
it('validates args', function()
command('let g:d={"baz":"zub","meep":[]}')
- expect_err('Not found: bogus$', request,
- 'nvim_call_dict_function', 'g:d', 'bogus', {1,2})
- expect_err('Not a function: baz$', request,
- '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('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})
- expect_err('dict argument type must be String or Dictionary$', request,
- 'nvim_call_dict_function', 42, 'f', {1,2})
- expect_err('Failed to evaluate dict expression$', request,
- 'nvim_call_dict_function', 'foo', 'f', {1,2})
- expect_err('dict not found$', request,
- 'nvim_call_dict_function', '42', 'f', {1,2})
- expect_err('Invalid %(empty%) function name$', request,
- 'nvim_call_dict_function', "{ 'f': '' }", '', {1,2})
+ eq('Not found: bogus',
+ pcall_err(request, 'nvim_call_dict_function', 'g:d', 'bogus', {1,2}))
+ eq('Not a function: baz',
+ pcall_err(request, 'nvim_call_dict_function', 'g:d', 'baz', {1,2}))
+ eq('Not a function: meep',
+ pcall_err(request, 'nvim_call_dict_function', 'g:d', 'meep', {1,2}))
+ eq('Vim:E117: Unknown function: f',
+ pcall_err(request, 'nvim_call_dict_function', { f = '' }, 'f', {1,2}))
+ eq('Not a function: f',
+ pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", 'f', {1,2}))
+ eq('dict argument type must be String or Dictionary',
+ pcall_err(request, 'nvim_call_dict_function', 42, 'f', {1,2}))
+ eq('Failed to evaluate dict expression',
+ pcall_err(request, 'nvim_call_dict_function', 'foo', 'f', {1,2}))
+ eq('dict not found',
+ pcall_err(request, 'nvim_call_dict_function', '42', 'f', {1,2}))
+ eq('Invalid (empty) function name',
+ pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", '', {1,2}))
end)
end)
@@ -326,25 +325,20 @@ describe('API', function()
end)
it('reports errors', function()
- eq({false, 'Error loading lua: [string "<nvim>"]:1: '..
- "'=' expected near '+'"},
- meth_pcall(meths.execute_lua, 'a+*b', {}))
+ eq([[Error loading lua: [string "<nvim>"]:1: '=' expected near '+']],
+ pcall_err(meths.execute_lua, 'a+*b', {}))
- eq({false, 'Error loading lua: [string "<nvim>"]:1: '..
- "unexpected symbol near '1'"},
- meth_pcall(meths.execute_lua, '1+2', {}))
+ eq([[Error loading lua: [string "<nvim>"]:1: unexpected symbol near '1']],
+ pcall_err(meths.execute_lua, '1+2', {}))
- eq({false, 'Error loading lua: [string "<nvim>"]:1: '..
- "unexpected symbol"},
- meth_pcall(meths.execute_lua, 'aa=bb\0', {}))
+ eq([[Error loading lua: [string "<nvim>"]:1: unexpected symbol]],
+ pcall_err(meths.execute_lua, 'aa=bb\0', {}))
- eq({false, 'Error executing lua: [string "<nvim>"]:1: '..
- "attempt to call global 'bork' (a nil value)"},
- meth_pcall(meths.execute_lua, 'bork()', {}))
+ eq([[Error executing lua: [string "<nvim>"]:1: attempt to call global 'bork' (a nil value)]],
+ pcall_err(meths.execute_lua, 'bork()', {}))
- eq({false, 'Error executing lua: [string "<nvim>"]:1: '..
- "did\nthe\nfail"},
- meth_pcall(meths.execute_lua, 'error("did\\nthe\\nfail")', {}))
+ eq('Error executing lua: [string "<nvim>"]:1: did\nthe\nfail',
+ pcall_err(meths.execute_lua, 'error("did\\nthe\\nfail")', {}))
end)
it('uses native float values', function()
@@ -368,10 +362,10 @@ describe('API', function()
describe('nvim_paste', function()
it('validates args', function()
- expect_err('Invalid phase: %-2', request,
- 'nvim_paste', 'foo', true, -2)
- expect_err('Invalid phase: 4', request,
- 'nvim_paste', 'foo', true, 4)
+ eq('Invalid phase: -2',
+ pcall_err(request, 'nvim_paste', 'foo', true, -2))
+ eq('Invalid phase: 4',
+ pcall_err(request, 'nvim_paste', 'foo', true, 4))
end)
it('stream: multiple chunks form one undo-block', function()
nvim('paste', '1/chunk 1 (start)\n', true, 1)
@@ -460,22 +454,22 @@ describe('API', function()
end)
it('vim.paste() failure', function()
nvim('execute_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {})
- expect_err([[Error executing lua: %[string "%<nvim>"]:1: fake fail]],
- request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1)
+ eq([[Error executing lua: [string "<nvim>"]:1: fake fail]],
+ pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1))
end)
end)
describe('nvim_put', function()
it('validates args', function()
- expect_err('Invalid lines %(expected array of strings%)', request,
- 'nvim_put', {42}, 'l', false, false)
- expect_err("Invalid type: 'x'", request,
- 'nvim_put', {'foo'}, 'x', false, false)
+ eq('Invalid lines (expected array of strings)',
+ pcall_err(request, 'nvim_put', {42}, 'l', false, false))
+ eq("Invalid type: 'x'",
+ pcall_err(request, 'nvim_put', {'foo'}, 'x', false, false))
end)
it("fails if 'nomodifiable'", function()
command('set nomodifiable')
- expect_err([[Vim:E21: Cannot make changes, 'modifiable' is off]], request,
- 'nvim_put', {'a','b'}, 'l', true, true)
+ eq([[Vim:E21: Cannot make changes, 'modifiable' is off]],
+ pcall_err(request, 'nvim_put', {'a','b'}, 'l', true, true))
end)
it('inserts text', function()
-- linewise
@@ -571,10 +565,10 @@ describe('API', function()
yyybc line 2
line 3
]])
- eq({false, "Invalid type: 'bx'"},
- meth_pcall(meths.put, {'xxx', 'yyy'}, 'bx', false, true))
- eq({false, "Invalid type: 'b3x'"},
- meth_pcall(meths.put, {'xxx', 'yyy'}, 'b3x', false, true))
+ eq("Invalid type: 'bx'",
+ pcall_err(meths.put, {'xxx', 'yyy'}, 'bx', false, true))
+ eq("Invalid type: 'b3x'",
+ pcall_err(meths.put, {'xxx', 'yyy'}, 'b3x', false, true))
end)
end)
@@ -607,19 +601,19 @@ describe('API', function()
eq(1, funcs.exists('g:lua'))
meths.del_var('lua')
eq(0, funcs.exists('g:lua'))
- eq({false, "Key not found: lua"}, meth_pcall(meths.del_var, 'lua'))
+ eq("Key not found: lua", pcall_err(meths.del_var, 'lua'))
meths.set_var('lua', 1)
-- Set locked g: var.
command('lockvar lua')
- eq({false, 'Key is locked: lua'}, meth_pcall(meths.del_var, 'lua'))
- eq({false, 'Key is locked: lua'}, meth_pcall(meths.set_var, 'lua', 1))
+ eq('Key is locked: lua', pcall_err(meths.del_var, 'lua'))
+ eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1))
end)
it('nvim_get_vvar, nvim_set_vvar', function()
-- Set readonly v: var.
- expect_err('Key is read%-only: count$', request,
- 'nvim_set_vvar', 'count', 42)
+ eq('Key is read-only: count',
+ pcall_err(request, 'nvim_set_vvar', 'count', 42))
-- Set writable v: var.
meths.set_vvar('errmsg', 'set by API')
eq('set by API', meths.get_vvar('errmsg'))
@@ -1195,8 +1189,8 @@ describe('API', function()
eq({info=info}, meths.get_var("info_event"))
eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans())
- eq({false, "Vim:Error invoking 'nvim_set_current_buf' on channel 3 (amazing-cat):\nWrong type for argument 1, expecting Buffer"},
- meth_pcall(eval, 'rpcrequest(3, "nvim_set_current_buf", -1)'))
+ eq("Vim:Error invoking 'nvim_set_current_buf' on channel 3 (amazing-cat):\nWrong type for argument 1, expecting Buffer",
+ pcall_err(eval, 'rpcrequest(3, "nvim_set_current_buf", -1)'))
end)
it('works for :terminal channel', function()
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 3bc53cfc83..17e0d3235c 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -8,10 +8,9 @@ local curwinmeths = helpers.curwinmeths
local funcs = helpers.funcs
local request = helpers.request
local NIL = helpers.NIL
-local meth_pcall = helpers.meth_pcall
local meths = helpers.meths
local command = helpers.command
-local expect_err = helpers.expect_err
+local pcall_err = helpers.pcall_err
-- check if str is visible at the beginning of some line
local function is_visible(str)
@@ -56,8 +55,8 @@ describe('API/win', function()
end)
it('validates args', function()
- expect_err('Invalid buffer id$', window, 'set_buf', nvim('get_current_win'), 23)
- expect_err('Invalid window id$', window, 'set_buf', 23, nvim('get_current_buf'))
+ eq('Invalid buffer id', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
+ eq('Invalid window id', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
end)
end)
@@ -74,8 +73,7 @@ describe('API/win', function()
it('does not leak memory when using invalid window ID with invalid pos',
function()
- eq({false, 'Invalid window id'},
- meth_pcall(meths.win_set_cursor, 1, {"b\na"}))
+ eq('Invalid window id', pcall_err(meths.win_set_cursor, 1, {"b\na"}))
end)
it('updates the screen, and also when the window is unfocused', function()
@@ -185,11 +183,11 @@ describe('API/win', function()
eq(1, funcs.exists('w:lua'))
curwinmeths.del_var('lua')
eq(0, funcs.exists('w:lua'))
- eq({false, 'Key not found: lua'}, meth_pcall(curwinmeths.del_var, 'lua'))
+ eq('Key not found: lua', pcall_err(curwinmeths.del_var, 'lua'))
curwinmeths.set_var('lua', 1)
command('lockvar w:lua')
- eq({false, 'Key is locked: lua'}, meth_pcall(curwinmeths.del_var, 'lua'))
- eq({false, 'Key is locked: lua'}, meth_pcall(curwinmeths.set_var, 'lua', 1))
+ eq('Key is locked: lua', pcall_err(curwinmeths.del_var, 'lua'))
+ eq('Key is locked: lua', pcall_err(curwinmeths.set_var, 'lua', 1))
end)
it('window_set_var returns the old value', function()
@@ -222,7 +220,8 @@ describe('API/win', function()
eq('', nvim('get_option', 'statusline'))
command("set modified")
command("enew") -- global-local: not preserved in new buffer
- eq({false, "Failed to get value for option 'statusline'"}, meth_pcall(curwin, 'get_option', 'statusline'))
+ eq("Failed to get value for option 'statusline'",
+ pcall_err(curwin, 'get_option', 'statusline'))
eq('', eval('&l:statusline')) -- confirm local value was not copied
end)
end)
@@ -317,8 +316,8 @@ describe('API/win', function()
insert('text')
command('new')
local newwin = meths.get_current_win()
- eq({false,"Vim:E37: No write since last change (add ! to override)"},
- meth_pcall(meths.win_close, oldwin,false))
+ eq("Vim:E37: No write since last change (add ! to override)",
+ pcall_err(meths.win_close, oldwin,false))
eq({newwin,oldwin}, meths.list_wins())
end)
@@ -340,7 +339,8 @@ describe('API/win', function()
eq(3, #meths.list_wins())
eq(':', funcs.getcmdwintype())
-- Vim: not allowed to close other windows from cmdline-window.
- expect_err('E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$', meths.win_close, oldwin, true)
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.win_close, oldwin, true))
-- Close cmdline-window.
meths.win_close(0,true)
eq(2, #meths.list_wins())