Merge #10932 'test: Eliminate expect_err'

This commit is contained in:
Justin M. Keyes
2019-09-06 18:16:57 -07:00
committed by GitHub
30 changed files with 330 additions and 320 deletions

View File

@@ -178,9 +178,20 @@ local function trim(s)
return s:match('^%s*(.*%S)') or '' return s:match('^%s*(.*%S)') or ''
end end
--- Escapes magic chars in a Lua pattern string.
---
--@see https://github.com/rxi/lume
--@param s String to escape
--@returns %-escaped pattern string
local function pesc(s)
assert(type(s) == 'string')
return s:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', '%%%1')
end
local module = { local module = {
deepcopy = deepcopy, deepcopy = deepcopy,
gsplit = gsplit, gsplit = gsplit,
pesc = pesc,
split = split, split = split,
tbl_contains = tbl_contains, tbl_contains = tbl_contains,
tbl_extend = tbl_extend, tbl_extend = tbl_extend,

View File

@@ -10,11 +10,10 @@ local exc_exec = helpers.exc_exec
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local insert = helpers.insert local insert = helpers.insert
local NIL = helpers.NIL local NIL = helpers.NIL
local meth_pcall = helpers.meth_pcall
local command = helpers.command local command = helpers.command
local bufmeths = helpers.bufmeths local bufmeths = helpers.bufmeths
local feed = helpers.feed local feed = helpers.feed
local expect_err = helpers.expect_err local pcall_err = helpers.pcall_err
describe('api/buf', function() describe('api/buf', function()
before_each(clear) before_each(clear)
@@ -191,17 +190,14 @@ describe('api/buf', function()
it('fails correctly when input is not valid', function() it('fails correctly when input is not valid', function()
eq(1, curbufmeths.get_number()) eq(1, curbufmeths.get_number())
local err, emsg = pcall(bufmeths.set_lines, 1, 1, 2, false, {'b\na'}) eq([[String cannot contain newlines]],
eq(false, err) pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'}))
local exp_emsg = 'String cannot contain newlines'
-- Expected {filename}:{lnum}: {exp_emsg}
eq(': ' .. exp_emsg, emsg:sub(-#exp_emsg - 2))
end) end)
it("fails if 'nomodifiable'", function() it("fails if 'nomodifiable'", function()
command('set nomodifiable') command('set nomodifiable')
expect_err([[Buffer is not 'modifiable']], eq([[Buffer is not 'modifiable']],
bufmeths.set_lines, 1, 1, 2, false, {'a','b'}) pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'a','b'}))
end) end)
it('has correct line_count when inserting and deleting', function() it('has correct line_count when inserting and deleting', function()
@@ -407,8 +403,8 @@ describe('api/buf', function()
eq(16, get_offset(3)) eq(16, get_offset(3))
eq(24, get_offset(4)) eq(24, get_offset(4))
eq(29, get_offset(5)) eq(29, get_offset(5))
eq({false,'Index out of bounds'}, meth_pcall(get_offset, 6)) eq('Index out of bounds', pcall_err(get_offset, 6))
eq({false,'Index out of bounds'}, meth_pcall(get_offset, -1)) eq('Index out of bounds', pcall_err(get_offset, -1))
curbufmeths.set_option('eol', false) curbufmeths.set_option('eol', false)
curbufmeths.set_option('fixeol', false) curbufmeths.set_option('fixeol', false)
@@ -441,15 +437,15 @@ describe('api/buf', function()
eq(1, funcs.exists('b:lua')) eq(1, funcs.exists('b:lua'))
curbufmeths.del_var('lua') curbufmeths.del_var('lua')
eq(0, funcs.exists('b: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) curbufmeths.set_var('lua', 1)
command('lockvar b:lua') command('lockvar b:lua')
eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(curbufmeths.del_var, 'lua'))
eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.set_var, 'lua', 1)) eq('Key is locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1))
eq({false, 'Key is read-only: changedtick'}, eq('Key is read-only: changedtick',
meth_pcall(curbufmeths.del_var, 'changedtick')) pcall_err(curbufmeths.del_var, 'changedtick'))
eq({false, 'Key is read-only: changedtick'}, eq('Key is read-only: changedtick',
meth_pcall(curbufmeths.set_var, 'changedtick', 1)) pcall_err(curbufmeths.set_var, 'changedtick', 1))
end) end)
end) end)

View File

@@ -3,8 +3,8 @@ local clear = helpers.clear
local eq, ok = helpers.eq, helpers.ok local eq, ok = helpers.eq, helpers.ok
local buffer, command, eval, nvim, next_msg = helpers.buffer, local buffer, command, eval, nvim, next_msg = helpers.buffer,
helpers.command, helpers.eval, helpers.nvim, helpers.next_msg helpers.command, helpers.eval, helpers.nvim, helpers.next_msg
local expect_err = helpers.expect_err
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local pcall_err = helpers.pcall_err
local sleep = helpers.sleep local sleep = helpers.sleep
local write_file = helpers.write_file 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() it('returns a proper error on nonempty options dict', function()
clear() clear()
local b = editoriginal(false) 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) end)
it('nvim_buf_attach returns response after delay #8634', function() it('nvim_buf_attach returns response after delay #8634', function()

View File

@@ -5,9 +5,9 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local eq = helpers.eq local eq = helpers.eq
local expect_err = helpers.expect_err
local meths = helpers.meths local meths = helpers.meths
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err
describe('nvim_get_commands', function() 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, } 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) end)
it('validates input', function() it('validates input', function()
expect_err('builtin=true not implemented', meths.get_commands, eq('builtin=true not implemented', pcall_err(meths.get_commands,
{builtin=true}) {builtin=true}))
expect_err('unexpected key: foo', meths.get_commands, eq('unexpected key: foo', pcall_err(meths.get_commands,
{foo='blah'}) {foo='blah'}))
end) end)
it('gets global user-defined commands', function() it('gets global user-defined commands', function()

View File

@@ -5,11 +5,11 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local eq, neq = helpers.eq, helpers.neq local eq, neq = helpers.eq, helpers.neq
local expect_err = helpers.expect_err
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err
local shallowcopy = helpers.shallowcopy local shallowcopy = helpers.shallowcopy
local sleep = helpers.sleep local sleep = helpers.sleep
@@ -360,12 +360,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('error on empty LHS', function() it('error on empty LHS', function()
-- escape parentheses in lua string, else comparison fails erroneously -- escape parentheses in lua string, else comparison fails erroneously
expect_err('Invalid %(empty%) LHS', eq('Invalid (empty) LHS', pcall_err(meths.set_keymap, '', '', 'rhs', {}))
meths.set_keymap, '', '', 'rhs', {}) eq('Invalid (empty) LHS', pcall_err(meths.set_keymap, '', '', '', {}))
expect_err('Invalid %(empty%) LHS', eq('Invalid (empty) LHS', pcall_err(meths.del_keymap, '', ''))
meths.set_keymap, '', '', '', {})
expect_err('Invalid %(empty%) LHS', meths.del_keymap, '', '')
end) end)
it('error if LHS longer than MAXMAPLEN', function() 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 -- 51 chars should produce an error
lhs = lhs..'1' lhs = lhs..'1'
expect_err('LHS exceeds maximum map length: '..lhs, eq('LHS exceeds maximum map length: '..lhs,
meths.set_keymap, '', lhs, 'rhs', {}) pcall_err(meths.set_keymap, '', lhs, 'rhs', {}))
expect_err('LHS exceeds maximum map length: '..lhs, eq('LHS exceeds maximum map length: '..lhs,
meths.del_keymap, '', lhs) pcall_err(meths.del_keymap, '', lhs))
end) end)
it('does not throw errors when rhs is longer than MAXMAPLEN', function() 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) end)
it('throws errors when given too-long mode shortnames', function() it('throws errors when given too-long mode shortnames', function()
expect_err('Shortname is too long: map', eq('Shortname is too long: map',
meths.set_keymap, 'map', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {}))
expect_err('Shortname is too long: vmap', eq('Shortname is too long: vmap',
meths.set_keymap, 'vmap', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {}))
expect_err('Shortname is too long: xnoremap', eq('Shortname is too long: xnoremap',
meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {}))
expect_err('Shortname is too long: map', meths.del_keymap, 'map', 'lhs') eq('Shortname is too long: map', pcall_err(meths.del_keymap, 'map', 'lhs'))
expect_err('Shortname is too long: vmap', meths.del_keymap, 'vmap', 'lhs') eq('Shortname is too long: vmap', pcall_err(meths.del_keymap, 'vmap', 'lhs'))
expect_err('Shortname is too long: xnoremap', meths.del_keymap, 'xnoremap', 'lhs') eq('Shortname is too long: xnoremap', pcall_err(meths.del_keymap, 'xnoremap', 'lhs'))
end) end)
it('error on invalid mode shortname', function() it('error on invalid mode shortname', function()
expect_err('Invalid mode shortname: " "', eq('Invalid mode shortname: " "',
meths.set_keymap, ' ', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {}))
expect_err('Invalid mode shortname: "m"', eq('Invalid mode shortname: "m"',
meths.set_keymap, 'm', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {}))
expect_err('Invalid mode shortname: "?"', eq('Invalid mode shortname: "?"',
meths.set_keymap, '?', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {}))
expect_err('Invalid mode shortname: "y"', eq('Invalid mode shortname: "y"',
meths.set_keymap, 'y', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {}))
expect_err('Invalid mode shortname: "p"', eq('Invalid mode shortname: "p"',
meths.set_keymap, 'p', 'lhs', 'rhs', {}) pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {}))
expect_err('Invalid mode shortname: "?"', meths.del_keymap, '?', 'lhs') eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs'))
expect_err('Invalid mode shortname: "y"', meths.del_keymap, 'y', 'lhs') eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs'))
expect_err('Invalid mode shortname: "p"', meths.del_keymap, 'p', 'lhs') eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs'))
end) end)
it('error on invalid optnames', function() it('error on invalid optnames', function()
expect_err('Invalid key: silentt', eq('Invalid key: silentt',
meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true}) pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true}))
expect_err('Invalid key: sidd', eq('Invalid key: sidd',
meths.set_keymap, 'n', 'lhs', 'rhs', {sidd = false}) pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {sidd = false}))
expect_err('Invalid key: nowaiT', eq('Invalid key: nowaiT',
meths.set_keymap, 'n', 'lhs', 'rhs', {nowaiT = false}) pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {nowaiT = false}))
end) end)
it('error on <buffer> option key', function() it('error on <buffer> option key', function()
expect_err('Invalid key: buffer', eq('Invalid key: buffer',
meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true}) pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true}))
end) end)
local optnames = {'nowait', 'silent', 'script', 'expr', 'unique'} 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() it('throws an error when given non-boolean value for '..opt, function()
local opts = {} local opts = {}
opts[opt] = 2 opts[opt] = 2
expect_err('Gave non%-boolean value for an opt: '..opt, eq('Gave non-boolean value for an opt: '..opt,
meths.set_keymap, 'n', 'lhs', 'rhs', opts) pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', opts))
end) end)
end end
@@ -581,8 +578,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('throws appropriate error messages when setting <unique> maps', function() it('throws appropriate error messages when setting <unique> maps', function()
meths.set_keymap('l', 'lhs', 'rhs', {}) meths.set_keymap('l', 'lhs', 'rhs', {})
expect_err('E227: mapping already exists for lhs', eq('E227: mapping already exists for lhs',
meths.set_keymap, 'l', 'lhs', 'rhs', {unique = true}) pcall_err(meths.set_keymap, 'l', 'lhs', 'rhs', {unique = true}))
-- different mapmode, no error should be thrown -- different mapmode, no error should be thrown
meths.set_keymap('t', 'lhs', 'rhs', {unique = true}) meths.set_keymap('t', 'lhs', 'rhs', {unique = true})
end) end)
@@ -750,8 +747,8 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
end end
it('rejects negative bufnr values', function() it('rejects negative bufnr values', function()
expect_err('Wrong type for argument 1, expecting Buffer', eq('Wrong type for argument 1, expecting Buffer',
bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}) pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}))
end) end)
it('can set mappings active in the current buffer but not others', function() 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() it("can't disable mappings given wrong buffer handle", function()
local first, second = make_two_buffers(false) local first, second = make_two_buffers(false)
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
expect_err('E31: No such mapping', eq('E31: No such mapping',
bufmeths.del_keymap, second, '', 'lhs') pcall_err(bufmeths.del_keymap, second, '', 'lhs'))
-- should still work -- should still work
switch_to_buf(first) switch_to_buf(first)

View File

@@ -10,7 +10,7 @@ local ok = helpers.ok
local meths = helpers.meths local meths = helpers.meths
local spawn, merge_args = helpers.spawn, helpers.merge_args local spawn, merge_args = helpers.spawn, helpers.merge_args
local set_session = helpers.set_session local set_session = helpers.set_session
local meth_pcall = helpers.meth_pcall local pcall_err = helpers.pcall_err
describe('server -> client', function() describe('server -> client', function()
local cid local cid
@@ -220,8 +220,8 @@ describe('server -> client', function()
end) end)
it('returns an error if the request failed', function() 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" }, eq("Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist",
meth_pcall(eval, "rpcrequest(vim, 'does-not-exist')")) pcall_err(eval, "rpcrequest(vim, 'does-not-exist')"))
end) end)
end) end)

View File

@@ -6,7 +6,7 @@ local curtabmeths = helpers.curtabmeths
local funcs = helpers.funcs local funcs = helpers.funcs
local request = helpers.request local request = helpers.request
local NIL = helpers.NIL local NIL = helpers.NIL
local meth_pcall = helpers.meth_pcall local pcall_err = helpers.pcall_err
local command = helpers.command local command = helpers.command
describe('api/tabpage', function() describe('api/tabpage', function()
@@ -34,11 +34,11 @@ describe('api/tabpage', function()
eq(1, funcs.exists('t:lua')) eq(1, funcs.exists('t:lua'))
curtabmeths.del_var('lua') curtabmeths.del_var('lua')
eq(0, funcs.exists('t: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) curtabmeths.set_var('lua', 1)
command('lockvar t:lua') command('lockvar t:lua')
eq({false, 'Key is locked: lua'}, meth_pcall(curtabmeths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(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.set_var, 'lua', 1))
end) end)
it('tabpage_set_var returns the old value', function() it('tabpage_set_var returns the old value', function()

View File

@@ -3,9 +3,9 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local expect_err = helpers.expect_err
local meths = helpers.meths local meths = helpers.meths
local request = helpers.request local request = helpers.request
local pcall_err = helpers.pcall_err
describe('nvim_ui_attach()', function() describe('nvim_ui_attach()', function()
before_each(function() before_each(function()
@@ -18,20 +18,20 @@ describe('nvim_ui_attach()', function()
eq(999, eval('&columns')) eq(999, eval('&columns'))
end) end)
it('invalid option returns error', function() it('invalid option returns error', function()
expect_err('No such UI option: foo', eq('No such UI option: foo',
meths.ui_attach, 80, 24, { foo={'foo'} }) pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} }))
end) end)
it('validates channel arg', function() it('validates channel arg', function()
expect_err('UI not attached to channel: 1', eq('UI not attached to channel: 1',
request, 'nvim_ui_try_resize', 40, 10) pcall_err(request, 'nvim_ui_try_resize', 40, 10))
expect_err('UI not attached to channel: 1', eq('UI not attached to channel: 1',
request, 'nvim_ui_set_option', 'rgb', true) pcall_err(request, 'nvim_ui_set_option', 'rgb', true))
expect_err('UI not attached to channel: 1', eq('UI not attached to channel: 1',
request, 'nvim_ui_detach') pcall_err(request, 'nvim_ui_detach'))
local screen = Screen.new() local screen = Screen.new()
screen:attach({rgb=false}) screen:attach({rgb=false})
expect_err('UI already attached to channel: 1', eq('UI already attached to channel: 1',
request, 'nvim_ui_attach', 40, 10, { rgb=false }) pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb=false }))
end) end)
end) end)

View File

@@ -8,8 +8,8 @@ local eval = helpers.eval
local expect = helpers.expect local expect = helpers.expect
local funcs = helpers.funcs local funcs = helpers.funcs
local iswin = helpers.iswin local iswin = helpers.iswin
local meth_pcall = helpers.meth_pcall
local meths = helpers.meths local meths = helpers.meths
local matches = helpers.matches
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
local is_os = helpers.is_os local is_os = helpers.is_os
local parse_context = helpers.parse_context local parse_context = helpers.parse_context
@@ -17,7 +17,7 @@ local request = helpers.request
local source = helpers.source local source = helpers.source
local next_msg = helpers.next_msg 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 format_string = helpers.format_string
local intchar2lua = helpers.intchar2lua local intchar2lua = helpers.intchar2lua
local mergedicts_copy = helpers.mergedicts_copy local mergedicts_copy = helpers.mergedicts_copy
@@ -27,25 +27,25 @@ describe('API', function()
it('validates requests', function() it('validates requests', function()
-- RPC -- RPC
expect_err('Invalid method: bogus$', matches('Invalid method: bogus$',
request, 'bogus') pcall_err(request, 'bogus'))
expect_err('Invalid method: … の り 。…$', matches('Invalid method: … の り 。…$',
request, '… の り 。…') pcall_err(request, '… の り 。…'))
expect_err('Invalid method: <empty>$', matches('Invalid method: <empty>$',
request, '') pcall_err(request, ''))
-- Non-RPC: rpcrequest(v:servername) uses internal channel. -- Non-RPC: rpcrequest(v:servername) uses internal channel.
expect_err('Invalid method: … の り 。…$', matches('Invalid method: … の り 。…$',
request, 'nvim_eval', pcall_err(request, 'nvim_eval',
[=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), '… の り 。…')]=]) [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), '… の り 。…')]=]))
expect_err('Invalid method: bogus$', matches('Invalid method: bogus$',
request, 'nvim_eval', pcall_err(request, 'nvim_eval',
[=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), 'bogus')]=]) [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), 'bogus')]=]))
-- XXX: This must be the last one, else next one will fail: -- XXX: This must be the last one, else next one will fail:
-- "Packer instance already working. Use another Packer ..." -- "Packer instance already working. Use another Packer ..."
expect_err("can't serialize object$", matches("can't serialize object$",
request, nil) pcall_err(request, nil))
end) end)
it('handles errors in async requests', function() it('handles errors in async requests', function()
@@ -203,8 +203,8 @@ describe('API', function()
end) end)
it("VimL error: returns error details, does NOT update v:errmsg", function() it("VimL error: returns error details, does NOT update v:errmsg", function()
expect_err('E121: Undefined variable: bogus$', request, eq('Vim:E121: Undefined variable: bogus',
'nvim_eval', 'bogus expression') pcall_err(request, 'nvim_eval', 'bogus expression'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end) end)
end) end)
@@ -218,21 +218,21 @@ describe('API', function()
end) end)
it("VimL validation error: returns specific error, does NOT update v:errmsg", function() it("VimL validation error: returns specific error, does NOT update v:errmsg", function()
expect_err('E117: Unknown function: bogus function$', request, eq('Vim:E117: Unknown function: bogus function',
'nvim_call_function', 'bogus function', {'arg1'}) pcall_err(request, 'nvim_call_function', 'bogus function', {'arg1'}))
expect_err('E119: Not enough arguments for function: atan', request, eq('Vim:E119: Not enough arguments for function: atan',
'nvim_call_function', 'atan', {}) pcall_err(request, 'nvim_call_function', 'atan', {}))
eq('', eval('v:exception')) eq('', eval('v:exception'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end) end)
it("VimL error: returns error details, does NOT update v:errmsg", function() it("VimL error: returns error details, does NOT update v:errmsg", function()
expect_err('E808: Number or Float required$', request, eq('Vim:E808: Number or Float required',
'nvim_call_function', 'atan', {'foo'}) pcall_err(request, 'nvim_call_function', 'atan', {'foo'}))
expect_err('Invalid channel stream "xxx"$', request, eq('Vim:Invalid channel stream "xxx"',
'nvim_call_function', 'chanclose', {999, 'xxx'}) pcall_err(request, 'nvim_call_function', 'chanclose', {999, 'xxx'}))
expect_err('E900: Invalid channel id$', request, eq('Vim:E900: Invalid channel id',
'nvim_call_function', 'chansend', {999, 'foo'}) pcall_err(request, 'nvim_call_function', 'chansend', {999, 'foo'}))
eq('', eval('v:exception')) eq('', eval('v:exception'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end) end)
@@ -243,8 +243,7 @@ describe('API', function()
throw 'wtf' throw 'wtf'
endfunction endfunction
]]) ]])
expect_err('wtf$', request, eq('wtf', pcall_err(request, 'nvim_call_function', 'Foo', {}))
'nvim_call_function', 'Foo', {})
eq('', eval('v:exception')) eq('', eval('v:exception'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end) end)
@@ -257,8 +256,8 @@ describe('API', function()
endfunction endfunction
]]) ]])
-- E740 -- E740
expect_err('Function called with too many arguments$', request, eq('Function called with too many arguments',
'nvim_call_function', 'Foo', too_many_args) pcall_err(request, 'nvim_call_function', 'Foo', too_many_args))
end) end)
end) end)
@@ -293,24 +292,24 @@ describe('API', function()
it('validates args', function() it('validates args', function()
command('let g:d={"baz":"zub","meep":[]}') command('let g:d={"baz":"zub","meep":[]}')
expect_err('Not found: bogus$', request, eq('Not found: bogus',
'nvim_call_dict_function', 'g:d', 'bogus', {1,2}) pcall_err(request, 'nvim_call_dict_function', 'g:d', 'bogus', {1,2}))
expect_err('Not a function: baz$', request, eq('Not a function: baz',
'nvim_call_dict_function', 'g:d', 'baz', {1,2}) pcall_err(request, 'nvim_call_dict_function', 'g:d', 'baz', {1,2}))
expect_err('Not a function: meep$', request, eq('Not a function: meep',
'nvim_call_dict_function', 'g:d', 'meep', {1,2}) pcall_err(request, 'nvim_call_dict_function', 'g:d', 'meep', {1,2}))
expect_err('E117: Unknown function: f$', request, eq('Vim:E117: Unknown function: f',
'nvim_call_dict_function', { f = '' }, 'f', {1,2}) pcall_err(request, 'nvim_call_dict_function', { f = '' }, 'f', {1,2}))
expect_err('Not a function: f$', request, eq('Not a function: f',
'nvim_call_dict_function', "{ 'f': '' }", 'f', {1,2}) pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", 'f', {1,2}))
expect_err('dict argument type must be String or Dictionary$', request, eq('dict argument type must be String or Dictionary',
'nvim_call_dict_function', 42, 'f', {1,2}) pcall_err(request, 'nvim_call_dict_function', 42, 'f', {1,2}))
expect_err('Failed to evaluate dict expression$', request, eq('Failed to evaluate dict expression',
'nvim_call_dict_function', 'foo', 'f', {1,2}) pcall_err(request, 'nvim_call_dict_function', 'foo', 'f', {1,2}))
expect_err('dict not found$', request, eq('dict not found',
'nvim_call_dict_function', '42', 'f', {1,2}) pcall_err(request, 'nvim_call_dict_function', '42', 'f', {1,2}))
expect_err('Invalid %(empty%) function name$', request, eq('Invalid (empty) function name',
'nvim_call_dict_function', "{ 'f': '' }", '', {1,2}) pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", '', {1,2}))
end) end)
end) end)
@@ -326,25 +325,20 @@ describe('API', function()
end) end)
it('reports errors', function() it('reports errors', function()
eq({false, 'Error loading lua: [string "<nvim>"]:1: '.. eq([[Error loading lua: [string "<nvim>"]:1: '=' expected near '+']],
"'=' expected near '+'"}, pcall_err(meths.execute_lua, 'a+*b', {}))
meth_pcall(meths.execute_lua, 'a+*b', {}))
eq({false, 'Error loading lua: [string "<nvim>"]:1: '.. eq([[Error loading lua: [string "<nvim>"]:1: unexpected symbol near '1']],
"unexpected symbol near '1'"}, pcall_err(meths.execute_lua, '1+2', {}))
meth_pcall(meths.execute_lua, '1+2', {}))
eq({false, 'Error loading lua: [string "<nvim>"]:1: '.. eq([[Error loading lua: [string "<nvim>"]:1: unexpected symbol]],
"unexpected symbol"}, pcall_err(meths.execute_lua, 'aa=bb\0', {}))
meth_pcall(meths.execute_lua, 'aa=bb\0', {}))
eq({false, 'Error executing lua: [string "<nvim>"]:1: '.. eq([[Error executing lua: [string "<nvim>"]:1: attempt to call global 'bork' (a nil value)]],
"attempt to call global 'bork' (a nil value)"}, pcall_err(meths.execute_lua, 'bork()', {}))
meth_pcall(meths.execute_lua, 'bork()', {}))
eq({false, 'Error executing lua: [string "<nvim>"]:1: '.. eq('Error executing lua: [string "<nvim>"]:1: did\nthe\nfail',
"did\nthe\nfail"}, pcall_err(meths.execute_lua, 'error("did\\nthe\\nfail")', {}))
meth_pcall(meths.execute_lua, 'error("did\\nthe\\nfail")', {}))
end) end)
it('uses native float values', function() it('uses native float values', function()
@@ -368,10 +362,10 @@ describe('API', function()
describe('nvim_paste', function() describe('nvim_paste', function()
it('validates args', function() it('validates args', function()
expect_err('Invalid phase: %-2', request, eq('Invalid phase: -2',
'nvim_paste', 'foo', true, -2) pcall_err(request, 'nvim_paste', 'foo', true, -2))
expect_err('Invalid phase: 4', request, eq('Invalid phase: 4',
'nvim_paste', 'foo', true, 4) pcall_err(request, 'nvim_paste', 'foo', true, 4))
end) end)
it('stream: multiple chunks form one undo-block', function() it('stream: multiple chunks form one undo-block', function()
nvim('paste', '1/chunk 1 (start)\n', true, 1) nvim('paste', '1/chunk 1 (start)\n', true, 1)
@@ -460,22 +454,22 @@ describe('API', function()
end) end)
it('vim.paste() failure', function() it('vim.paste() failure', function()
nvim('execute_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {}) nvim('execute_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {})
expect_err([[Error executing lua: %[string "%<nvim>"]:1: fake fail]], eq([[Error executing lua: [string "<nvim>"]:1: fake fail]],
request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1) pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1))
end) end)
end) end)
describe('nvim_put', function() describe('nvim_put', function()
it('validates args', function() it('validates args', function()
expect_err('Invalid lines %(expected array of strings%)', request, eq('Invalid lines (expected array of strings)',
'nvim_put', {42}, 'l', false, false) pcall_err(request, 'nvim_put', {42}, 'l', false, false))
expect_err("Invalid type: 'x'", request, eq("Invalid type: 'x'",
'nvim_put', {'foo'}, 'x', false, false) pcall_err(request, 'nvim_put', {'foo'}, 'x', false, false))
end) end)
it("fails if 'nomodifiable'", function() it("fails if 'nomodifiable'", function()
command('set nomodifiable') command('set nomodifiable')
expect_err([[Vim:E21: Cannot make changes, 'modifiable' is off]], request, eq([[Vim:E21: Cannot make changes, 'modifiable' is off]],
'nvim_put', {'a','b'}, 'l', true, true) pcall_err(request, 'nvim_put', {'a','b'}, 'l', true, true))
end) end)
it('inserts text', function() it('inserts text', function()
-- linewise -- linewise
@@ -571,10 +565,10 @@ describe('API', function()
yyybc line 2 yyybc line 2
line 3 line 3
]]) ]])
eq({false, "Invalid type: 'bx'"}, eq("Invalid type: 'bx'",
meth_pcall(meths.put, {'xxx', 'yyy'}, 'bx', false, true)) pcall_err(meths.put, {'xxx', 'yyy'}, 'bx', false, true))
eq({false, "Invalid type: 'b3x'"}, eq("Invalid type: 'b3x'",
meth_pcall(meths.put, {'xxx', 'yyy'}, 'b3x', false, true)) pcall_err(meths.put, {'xxx', 'yyy'}, 'b3x', false, true))
end) end)
end) end)
@@ -607,19 +601,19 @@ describe('API', function()
eq(1, funcs.exists('g:lua')) eq(1, funcs.exists('g:lua'))
meths.del_var('lua') meths.del_var('lua')
eq(0, funcs.exists('g: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) meths.set_var('lua', 1)
-- Set locked g: var. -- Set locked g: var.
command('lockvar lua') command('lockvar lua')
eq({false, 'Key is locked: lua'}, meth_pcall(meths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(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.set_var, 'lua', 1))
end) end)
it('nvim_get_vvar, nvim_set_vvar', function() it('nvim_get_vvar, nvim_set_vvar', function()
-- Set readonly v: var. -- Set readonly v: var.
expect_err('Key is read%-only: count$', request, eq('Key is read-only: count',
'nvim_set_vvar', 'count', 42) pcall_err(request, 'nvim_set_vvar', 'count', 42))
-- Set writable v: var. -- Set writable v: var.
meths.set_vvar('errmsg', 'set by API') meths.set_vvar('errmsg', 'set by API')
eq('set by API', meths.get_vvar('errmsg')) eq('set by API', meths.get_vvar('errmsg'))
@@ -1195,8 +1189,8 @@ describe('API', function()
eq({info=info}, meths.get_var("info_event")) eq({info=info}, meths.get_var("info_event"))
eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans()) 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"}, eq("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)')) pcall_err(eval, 'rpcrequest(3, "nvim_set_current_buf", -1)'))
end) end)
it('works for :terminal channel', function() it('works for :terminal channel', function()

View File

@@ -8,10 +8,9 @@ local curwinmeths = helpers.curwinmeths
local funcs = helpers.funcs local funcs = helpers.funcs
local request = helpers.request local request = helpers.request
local NIL = helpers.NIL local NIL = helpers.NIL
local meth_pcall = helpers.meth_pcall
local meths = helpers.meths local meths = helpers.meths
local command = helpers.command 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 -- check if str is visible at the beginning of some line
local function is_visible(str) local function is_visible(str)
@@ -56,8 +55,8 @@ describe('API/win', function()
end) end)
it('validates args', function() it('validates args', function()
expect_err('Invalid buffer id$', window, 'set_buf', nvim('get_current_win'), 23) eq('Invalid buffer id', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
expect_err('Invalid window id$', window, 'set_buf', 23, nvim('get_current_buf')) eq('Invalid window id', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
end) end)
end) end)
@@ -74,8 +73,7 @@ describe('API/win', function()
it('does not leak memory when using invalid window ID with invalid pos', it('does not leak memory when using invalid window ID with invalid pos',
function() function()
eq({false, 'Invalid window id'}, eq('Invalid window id', pcall_err(meths.win_set_cursor, 1, {"b\na"}))
meth_pcall(meths.win_set_cursor, 1, {"b\na"}))
end) end)
it('updates the screen, and also when the window is unfocused', function() 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')) eq(1, funcs.exists('w:lua'))
curwinmeths.del_var('lua') curwinmeths.del_var('lua')
eq(0, funcs.exists('w: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) curwinmeths.set_var('lua', 1)
command('lockvar w:lua') command('lockvar w:lua')
eq({false, 'Key is locked: lua'}, meth_pcall(curwinmeths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(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.set_var, 'lua', 1))
end) end)
it('window_set_var returns the old value', function() it('window_set_var returns the old value', function()
@@ -222,7 +220,8 @@ describe('API/win', function()
eq('', nvim('get_option', 'statusline')) eq('', nvim('get_option', 'statusline'))
command("set modified") command("set modified")
command("enew") -- global-local: not preserved in new buffer 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 eq('', eval('&l:statusline')) -- confirm local value was not copied
end) end)
end) end)
@@ -317,8 +316,8 @@ describe('API/win', function()
insert('text') insert('text')
command('new') command('new')
local newwin = meths.get_current_win() local newwin = meths.get_current_win()
eq({false,"Vim:E37: No write since last change (add ! to override)"}, eq("Vim:E37: No write since last change (add ! to override)",
meth_pcall(meths.win_close, oldwin,false)) pcall_err(meths.win_close, oldwin,false))
eq({newwin,oldwin}, meths.list_wins()) eq({newwin,oldwin}, meths.list_wins())
end) end)
@@ -340,7 +339,8 @@ describe('API/win', function()
eq(3, #meths.list_wins()) eq(3, #meths.list_wins())
eq(':', funcs.getcmdwintype()) eq(':', funcs.getcmdwintype())
-- Vim: not allowed to close other windows from cmdline-window. -- 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. -- Close cmdline-window.
meths.win_close(0,true) meths.win_close(0,true)
eq(2, #meths.list_wins()) eq(2, #meths.list_wins())

View File

@@ -7,7 +7,7 @@ local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local meths = helpers.meths local meths = helpers.meths
local meth_pcall = helpers.meth_pcall local pcall_err = helpers.pcall_err
local funcs = helpers.funcs local funcs = helpers.funcs
local expect = helpers.expect local expect = helpers.expect
local command = helpers.command local command = helpers.command
@@ -219,8 +219,8 @@ describe('autocmd', function()
eq(7, eval('g:test')) eq(7, eval('g:test'))
-- API calls are blocked when aucmd_win is not in scope -- API calls are blocked when aucmd_win is not in scope
eq({false, 'Vim(call):E5555: API call: Invalid window id'}, eq('Vim(call):E5555: API call: Invalid window id',
meth_pcall(command, "call nvim_set_current_win(g:winid)")) pcall_err(command, "call nvim_set_current_win(g:winid)"))
-- second time aucmd_win is needed, a different code path is invoked -- second time aucmd_win is needed, a different code path is invoked
-- to reuse the same window, so check again -- to reuse the same window, so check again
@@ -257,8 +257,8 @@ describe('autocmd', function()
eq(0, eval('g:had_value')) eq(0, eval('g:had_value'))
eq(7, eval('g:test')) eq(7, eval('g:test'))
eq({false, 'Vim(call):E5555: API call: Invalid window id'}, eq('Vim(call):E5555: API call: Invalid window id',
meth_pcall(command, "call nvim_set_current_win(g:winid)")) pcall_err(command, "call nvim_set_current_win(g:winid)"))
end) end)
it(':doautocmd does not warn "No matching autocommands" #10689', function() it(':doautocmd does not warn "No matching autocommands" #10689', function()

View File

@@ -17,7 +17,7 @@ local pathroot = helpers.pathroot
local nvim_set = helpers.nvim_set local nvim_set = helpers.nvim_set
local expect_twostreams = helpers.expect_twostreams local expect_twostreams = helpers.expect_twostreams
local expect_msg_seq = helpers.expect_msg_seq local expect_msg_seq = helpers.expect_msg_seq
local expect_err = helpers.expect_err local pcall_err = helpers.pcall_err
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
-- Kill process with given pid -- Kill process with given pid
@@ -122,8 +122,8 @@ describe('jobs', function()
local dir = 'Xtest_not_executable_dir' local dir = 'Xtest_not_executable_dir'
mkdir(dir) mkdir(dir)
funcs.setfperm(dir, 'rw-------') funcs.setfperm(dir, 'rw-------')
expect_err('E475: Invalid argument: expected valid directory$', nvim, eq('Vim(call):E475: Invalid argument: expected valid directory',
'command', "call jobstart('pwd', {'cwd': '" .. dir .. "'})") pcall_err(nvim, 'command', "call jobstart('pwd', {'cwd': '"..dir.."'})"))
rmdir(dir) rmdir(dir)
end) end)

View File

@@ -4,7 +4,7 @@ local lfs = require('lfs')
local neq, eq, command = helpers.neq, helpers.eq, helpers.command local neq, eq, command = helpers.neq, helpers.eq, helpers.command
local clear, curbufmeths = helpers.clear, helpers.curbufmeths local clear, curbufmeths = helpers.clear, helpers.curbufmeths
local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval
local insert, meth_pcall = helpers.insert, helpers.meth_pcall local insert, pcall_err = helpers.insert, helpers.pcall_err
local meths = helpers.meths local meths = helpers.meths
describe('eval-API', function() describe('eval-API', function()
@@ -148,8 +148,8 @@ describe('eval-API', function()
end) end)
it('cannot be called from sandbox', function() it('cannot be called from sandbox', function()
eq({false, 'Vim(call):E48: Not allowed in sandbox'}, eq('Vim(call):E48: Not allowed in sandbox',
meth_pcall(command, "sandbox call nvim_input('ievil')")) pcall_err(command, "sandbox call nvim_input('ievil')"))
eq({''}, meths.buf_get_lines(0, 0, -1, true)) eq({''}, meths.buf_get_lines(0, 0, -1, true))
end) end)
end) end)

View File

@@ -15,7 +15,7 @@ local curwinmeths = helpers.curwinmeths
local curtabmeths = helpers.curtabmeths local curtabmeths = helpers.curtabmeths
local get_pathsep = helpers.get_pathsep local get_pathsep = helpers.get_pathsep
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local expect_err = helpers.expect_err local pcall_err = helpers.pcall_err
local fname = 'Xtest-functional-eval-buf_functions' local fname = 'Xtest-functional-eval-buf_functions'
local fname2 = fname .. '.2' local fname2 = fname .. '.2'
@@ -297,8 +297,8 @@ describe('setbufvar() function', function()
eq('Vim(call):E461: Illegal variable name: b:', eq('Vim(call):E461: Illegal variable name: b:',
exc_exec('call setbufvar(1, "", 0)')) exc_exec('call setbufvar(1, "", 0)'))
eq(true, bufmeths.get_var(buf1, 'number')) eq(true, bufmeths.get_var(buf1, 'number'))
expect_err('Vim:E46: Cannot change read%-only variable "b:changedtick"', eq('Vim:E46: Cannot change read-only variable "b:changedtick"',
funcs.setbufvar, 1, 'changedtick', true) pcall_err(funcs.setbufvar, 1, 'changedtick', true))
eq(2, funcs.getbufvar(1, 'changedtick')) eq(2, funcs.getbufvar(1, 'changedtick'))
end) end)
end) end)

View File

@@ -9,7 +9,7 @@ local meths = helpers.meths
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local redir_exec = helpers.redir_exec local redir_exec = helpers.redir_exec
local meth_pcall = helpers.meth_pcall local pcall_err = helpers.pcall_err
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
before_each(clear) before_each(clear)
@@ -64,8 +64,8 @@ describe('b:changedtick', function()
redir_exec('let b:.changedtick = ' .. ctn)) redir_exec('let b:.changedtick = ' .. ctn))
eq('\nE46: Cannot change read-only variable "d.changedtick"', eq('\nE46: Cannot change read-only variable "d.changedtick"',
redir_exec('let d.changedtick = ' .. ctn)) redir_exec('let d.changedtick = ' .. ctn))
eq({false, 'Key is read-only: changedtick'}, eq('Key is read-only: changedtick',
meth_pcall(curbufmeths.set_var, 'changedtick', ctn)) pcall_err(curbufmeths.set_var, 'changedtick', ctn))
eq('\nE795: Cannot delete variable b:changedtick', eq('\nE795: Cannot delete variable b:changedtick',
redir_exec('unlet b:changedtick')) redir_exec('unlet b:changedtick'))
@@ -75,8 +75,8 @@ describe('b:changedtick', function()
redir_exec('unlet b:["changedtick"]')) redir_exec('unlet b:["changedtick"]'))
eq('\nE46: Cannot change read-only variable "d.changedtick"', eq('\nE46: Cannot change read-only variable "d.changedtick"',
redir_exec('unlet d.changedtick')) redir_exec('unlet d.changedtick'))
eq({false, 'Key is read-only: changedtick'}, eq('Key is read-only: changedtick',
meth_pcall(curbufmeths.del_var, 'changedtick')) pcall_err(curbufmeths.del_var, 'changedtick'))
eq(ct, changedtick()) eq(ct, changedtick())
eq('\nE46: Cannot change read-only variable "b:["changedtick"]"', eq('\nE46: Cannot change read-only variable "b:["changedtick"]"',

View File

@@ -5,7 +5,6 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local expect_err = helpers.expect_err
local feed = helpers.feed local feed = helpers.feed
local map = helpers.map local map = helpers.map
local nvim = helpers.nvim local nvim = helpers.nvim
@@ -14,6 +13,7 @@ local redir_exec = helpers.redir_exec
local source = helpers.source local source = helpers.source
local trim = helpers.trim local trim = helpers.trim
local write_file = helpers.write_file local write_file = helpers.write_file
local pcall_err = helpers.pcall_err
describe('context functions', function() describe('context functions', function()
local fname1 = 'Xtest-functional-eval-ctx1' local fname1 = 'Xtest-functional-eval-ctx1'
@@ -110,9 +110,9 @@ describe('context functions', function()
nvim('del_var', 'one') nvim('del_var', 'one')
nvim('del_var', 'Two') nvim('del_var', 'Two')
nvim('del_var', 'THREE') nvim('del_var', 'THREE')
expect_err('E121: Undefined variable: g:one', eval, 'g:one') eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one'))
expect_err('E121: Undefined variable: g:Two', eval, 'g:Two') eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two'))
expect_err('E121: Undefined variable: g:THREE', eval, 'g:THREE') eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE'))
call('ctxpop') call('ctxpop')
eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]')) eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]'))
@@ -120,9 +120,9 @@ describe('context functions', function()
nvim('del_var', 'one') nvim('del_var', 'one')
nvim('del_var', 'Two') nvim('del_var', 'Two')
nvim('del_var', 'THREE') nvim('del_var', 'THREE')
expect_err('E121: Undefined variable: g:one', eval, 'g:one') eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one'))
expect_err('E121: Undefined variable: g:Two', eval, 'g:Two') eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two'))
expect_err('E121: Undefined variable: g:THREE', eval, 'g:THREE') eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE'))
call('ctxpop') call('ctxpop')
eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]')) eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]'))
@@ -217,9 +217,9 @@ describe('context functions', function()
command('delfunction Greet') command('delfunction Greet')
command('delfunction GreetAll') command('delfunction GreetAll')
expect_err('Vim:E117: Unknown function: Greet', call, 'Greet', 'World') eq('Vim:E117: Unknown function: Greet', pcall_err(call, 'Greet', 'World'))
expect_err('Vim:E117: Unknown function: Greet', call, 'GreetAll', eq('Vim:E117: Unknown function: GreetAll',
'World', 'One', 'Two', 'Three') pcall_err(call, 'GreetAll', 'World', 'One', 'Two', 'Three'))
call('ctxpop') call('ctxpop')
@@ -233,13 +233,13 @@ describe('context functions', function()
it('errors out when context stack is empty', function() it('errors out when context stack is empty', function()
local err = 'Vim:Context stack is empty' local err = 'Vim:Context stack is empty'
expect_err(err, call, 'ctxpop') eq(err, pcall_err(call, 'ctxpop'))
expect_err(err, call, 'ctxpop') eq(err, pcall_err(call, 'ctxpop'))
call('ctxpush') call('ctxpush')
call('ctxpush') call('ctxpush')
call('ctxpop') call('ctxpop')
call('ctxpop') call('ctxpop')
expect_err(err, call, 'ctxpop') eq(err, pcall_err(call, 'ctxpop'))
end) end)
end) end)
@@ -263,11 +263,11 @@ describe('context functions', function()
describe('ctxget()', function() describe('ctxget()', function()
it('errors out when index is out of bounds', function() it('errors out when index is out of bounds', function()
expect_err(outofbounds, call, 'ctxget') eq(outofbounds, pcall_err(call, 'ctxget'))
call('ctxpush') call('ctxpush')
expect_err(outofbounds, call, 'ctxget', 1) eq(outofbounds, pcall_err(call, 'ctxget', 1))
call('ctxpop') call('ctxpop')
expect_err(outofbounds, call, 'ctxget', 0) eq(outofbounds, pcall_err(call, 'ctxget', 0))
end) end)
it('returns context dictionary at index in context stack', function() it('returns context dictionary at index in context stack', function()
@@ -370,11 +370,11 @@ describe('context functions', function()
describe('ctxset()', function() describe('ctxset()', function()
it('errors out when index is out of bounds', function() it('errors out when index is out of bounds', function()
expect_err(outofbounds, call, 'ctxset', {dummy = 1}) eq(outofbounds, pcall_err(call, 'ctxset', {dummy = 1}))
call('ctxpush') call('ctxpush')
expect_err(outofbounds, call, 'ctxset', {dummy = 1}, 1) eq(outofbounds, pcall_err(call, 'ctxset', {dummy = 1}, 1))
call('ctxpop') call('ctxpop')
expect_err(outofbounds, call, 'ctxset', {dummy = 1}, 0) eq(outofbounds, pcall_err(call, 'ctxset', {dummy = 1}, 0))
end) end)
it('sets context dictionary at index in context stack', function() it('sets context dictionary at index in context stack', function()

View File

@@ -6,7 +6,7 @@ local clear = helpers.clear
local funcs = helpers.funcs local funcs = helpers.funcs
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local expect_err = helpers.expect_err local pcall_err = helpers.pcall_err
before_each(clear) before_each(clear)
@@ -41,11 +41,11 @@ describe('setmatches()', function()
end) end)
it('fails with -1 if highlight group is not defined', function() it('fails with -1 if highlight group is not defined', function()
expect_err('E28: No such highlight group name: 1', funcs.setmatches, eq('Vim:E28: No such highlight group name: 1',
{{group=1, pattern=2, id=3, priority=4}}) pcall_err(funcs.setmatches, {{group=1, pattern=2, id=3, priority=4}}))
eq({}, funcs.getmatches()) eq({}, funcs.getmatches())
expect_err('E28: No such highlight group name: 1', funcs.setmatches, eq('Vim:E28: No such highlight group name: 1',
{{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}}) pcall_err(funcs.setmatches, {{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}}))
eq({}, funcs.getmatches()) eq({}, funcs.getmatches())
end) end)
end) end)

View File

@@ -5,7 +5,7 @@ local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
local iswin = helpers.iswin local iswin = helpers.iswin
local ok = helpers.ok local ok = helpers.ok
local matches = helpers.matches local matches = helpers.matches
local expect_err = helpers.expect_err local pcall_err = helpers.pcall_err
local function clear_serverlist() local function clear_serverlist()
for _, server in pairs(funcs.serverlist()) do for _, server in pairs(funcs.serverlist()) do
@@ -102,8 +102,8 @@ describe('server', function()
eq(expected, funcs.serverlist()) eq(expected, funcs.serverlist())
clear_serverlist() clear_serverlist()
expect_err('Failed to start server: invalid argument', eq('Vim:Failed to start server: invalid argument',
funcs.serverstart, '127.0.0.1:65536') -- invalid port pcall_err(funcs.serverstart, '127.0.0.1:65536')) -- invalid port
eq({}, funcs.serverlist()) eq({}, funcs.serverlist())
end) end)

View File

@@ -4,12 +4,12 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eval = helpers.eval local eval = helpers.eval
local eq = helpers.eq local eq = helpers.eq
local expect_err = helpers.expect_err
local feed = helpers.feed local feed = helpers.feed
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local next_msg = helpers.next_msg local next_msg = helpers.next_msg
local nvim = helpers.nvim local nvim = helpers.nvim
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err
before_each(function() before_each(function()
clear() clear()
@@ -66,13 +66,10 @@ describe('wait()', function()
eq(5, nvim('get_var', 'counter')) eq(5, nvim('get_var', 'counter'))
end) end)
it('errors out on invalid timeout value', function() it('validates args', function()
expect_err('Invalid value for argument', call, 'wait', '', 1) eq('Vim:E475: Invalid value for argument 1', pcall_err(call, 'wait', '', 1))
end) eq('Vim:E475: Invalid value for argument 3', pcall_err(call, 'wait', 0, 1, -1))
eq('Vim:E475: Invalid value for argument 3', pcall_err(call, 'wait', 0, 1, 0))
it('errors out on invalid interval', function() eq('Vim:E475: Invalid value for argument 3', pcall_err(call, 'wait', 0, 1, ''))
expect_err('Invalid value for argument', call, 'wait', 0, 1, -1)
expect_err('Invalid value for argument', call, 'wait', 0, 1, 0)
expect_err('Invalid value for argument', call, 'wait', 0, 1, '')
end) end)
end) end)

View File

@@ -5,7 +5,6 @@ local eq, eval, expect, source =
helpers.eq, helpers.eval, helpers.expect, helpers.source helpers.eq, helpers.eval, helpers.expect, helpers.source
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local expect_err = helpers.expect_err
local feed = helpers.feed local feed = helpers.feed
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local ok = helpers.ok local ok = helpers.ok
@@ -14,6 +13,7 @@ local set_session = helpers.set_session
local spawn = helpers.spawn local spawn = helpers.spawn
local nvim_async = helpers.nvim_async local nvim_async = helpers.nvim_async
local expect_msg_seq = helpers.expect_msg_seq local expect_msg_seq = helpers.expect_msg_seq
local pcall_err = helpers.pcall_err
describe(':recover', function() describe(':recover', function()
before_each(clear) before_each(clear)
@@ -21,11 +21,11 @@ describe(':recover', function()
it('fails if given a non-existent swapfile', function() it('fails if given a non-existent swapfile', function()
local swapname = 'bogus_swapfile' local swapname = 'bogus_swapfile'
local swapname2 = 'bogus_swapfile.swp' local swapname2 = 'bogus_swapfile.swp'
expect_err('E305: No swap file found for '..swapname, eq('Vim(recover):E305: No swap file found for '..swapname,
command, 'recover '..swapname) -- Should not segfault. #2117 pcall_err(command, 'recover '..swapname)) -- Should not segfault. #2117
-- Also check filename ending with ".swp". #9504 -- Also check filename ending with ".swp". #9504
expect_err('Vim%(recover%):E306: Cannot open '..swapname2, eq('Vim(recover):E306: Cannot open '..swapname2,
command, 'recover '..swapname2) -- Should not segfault. #2117 pcall_err(command, 'recover '..swapname2)) -- Should not segfault. #2117
eq(2, eval('1+1')) -- Still alive? eq(2, eval('1+1')) -- Still alive?
end) end)

View File

@@ -687,14 +687,6 @@ function module.skip_fragile(pending_fn, cond)
return false return false
end end
function module.meth_pcall(...)
local ret = {pcall(...)}
if type(ret[2]) == 'string' then
ret[2] = ret[2]:gsub('^[^:]+:%d+: ', '')
end
return ret
end
module.funcs = module.create_callindex(module.call) module.funcs = module.create_callindex(module.call)
module.meths = module.create_callindex(module.nvim) module.meths = module.create_callindex(module.nvim)
module.uimeths = module.create_callindex(ui) module.uimeths = module.create_callindex(ui)

View File

@@ -7,12 +7,12 @@ local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local meth_pcall = helpers.meth_pcall local pcall_err = helpers.pcall_err
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
before_each(clear) before_each(clear)
describe('lua function', function() describe('lua stdlib', function()
-- İ: `tolower("İ")` is `i` which has length 1 while `İ` itself has -- İ: `tolower("İ")` is `i` which has length 1 while `İ` itself has
-- length 2 (in bytes). -- length 2 (in bytes).
-- Ⱥ: `tolower("Ⱥ")` is `ⱥ` which has length 2 while `Ⱥ` itself has -- Ⱥ: `tolower("Ⱥ")` is `ⱥ` which has length 2 while `Ⱥ` itself has
@@ -147,11 +147,11 @@ describe('lua function', function()
eq({"yy","xx"}, exec_lua("return test_table")) eq({"yy","xx"}, exec_lua("return test_table"))
-- type checked args -- type checked args
eq({false, 'Error executing lua: vim.schedule: expected function'}, eq('Error executing lua: vim.schedule: expected function',
meth_pcall(exec_lua, "vim.schedule('stringly')")) pcall_err(exec_lua, "vim.schedule('stringly')"))
eq({false, 'Error executing lua: vim.schedule: expected function'}, eq('Error executing lua: vim.schedule: expected function',
meth_pcall(exec_lua, "vim.schedule()")) pcall_err(exec_lua, "vim.schedule()"))
exec_lua([[ exec_lua([[
vim.schedule(function() vim.schedule(function()
@@ -283,4 +283,9 @@ describe('lua function', function()
assert(is_dc) assert(is_dc)
end) end)
it('vim.pesc', function()
eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]]))
eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]]))
end)
end) end)

View File

@@ -1,16 +1,17 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local expect_err = helpers.expect_err local eq = helpers.eq
local pcall_err = helpers.pcall_err
describe('search (/)', function() describe('search (/)', function()
before_each(clear) before_each(clear)
it('fails with huge column (%c) value #9930', function() it('fails with huge column (%c) value #9930', function()
expect_err("Vim:E951: \\%% value too large", eq([[Vim:E951: \% value too large]],
command, "/\\v%18446744071562067968c") pcall_err(command, "/\\v%18446744071562067968c"))
expect_err("Vim:E951: \\%% value too large", eq([[Vim:E951: \% value too large]],
command, "/\\v%2147483648c") pcall_err(command, "/\\v%2147483648c"))
end) end)
end) end)

View File

@@ -2,7 +2,8 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eval = helpers.clear, helpers.eval local clear, eval = helpers.clear, helpers.eval
local command = helpers.command local command = helpers.command
local expect_err = helpers.expect_err local eq = helpers.eq
local pcall_err = helpers.pcall_err
describe('providers', function() describe('providers', function()
before_each(function() before_each(function()
@@ -13,14 +14,14 @@ describe('providers', function()
command('set loadplugins') command('set loadplugins')
-- Using test-fixture with broken impl: -- Using test-fixture with broken impl:
-- test/functional/fixtures/autoload/provider/python.vim -- test/functional/fixtures/autoload/provider/python.vim
expect_err('Vim:provider: python: missing required variable g:loaded_python_provider', eq('Vim:provider: python: missing required variable g:loaded_python_provider',
eval, "has('python')") pcall_err(eval, "has('python')"))
end) end)
it('with g:loaded_xx_provider, missing #Call()', function() it('with g:loaded_xx_provider, missing #Call()', function()
-- Using test-fixture with broken impl: -- Using test-fixture with broken impl:
-- test/functional/fixtures/autoload/provider/ruby.vim -- test/functional/fixtures/autoload/provider/ruby.vim
expect_err('Vim:provider: ruby: g:loaded_ruby_provider=2 but provider#ruby#Call is not defined', eq('Vim:provider: ruby: g:loaded_ruby_provider=2 but provider#ruby#Call is not defined',
eval, "has('ruby')") pcall_err(eval, "has('ruby')"))
end) end)
end) end)

View File

@@ -2,18 +2,19 @@ local helpers = require('test.functional.helpers')(after_each)
local eval, command, feed = helpers.eval, helpers.command, helpers.feed local eval, command, feed = helpers.eval, helpers.command, helpers.feed
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
local expect, write_file = helpers.expect, helpers.write_file local expect, write_file = helpers.expect, helpers.write_file
local expect_err = helpers.expect_err
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local source = helpers.source local source = helpers.source
local missing_provider = helpers.missing_provider local missing_provider = helpers.missing_provider
local matches = helpers.matches
local pcall_err = helpers.pcall_err
do do
clear() clear()
if missing_provider('python3') then if missing_provider('python3') then
it(':python3 reports E319 if provider is missing', function() it(':python3 reports E319 if provider is missing', function()
local expected = [[Vim%(py3.*%):E319: No "python3" provider found.*]] local expected = [[Vim%(py3.*%):E319: No "python3" provider found.*]]
expect_err(expected, command, 'py3 print("foo")') matches(expected, pcall_err(command, 'py3 print("foo")'))
expect_err(expected, command, 'py3file foo') matches(expected, pcall_err(command, 'py3file foo'))
end) end)
pending('Python 3 (or the pynvim module) is broken/missing', function() end) pending('Python 3 (or the pynvim module) is broken/missing', function() end)
return return

View File

@@ -8,20 +8,21 @@ local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local insert = helpers.insert local insert = helpers.insert
local expect = helpers.expect local expect = helpers.expect
local expect_err = helpers.expect_err
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local write_file = helpers.write_file local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local missing_provider = helpers.missing_provider local missing_provider = helpers.missing_provider
local matches = helpers.matches
local pcall_err = helpers.pcall_err
do do
clear() clear()
if missing_provider('python') then if missing_provider('python') then
it(':python reports E319 if provider is missing', function() it(':python reports E319 if provider is missing', function()
local expected = [[Vim%(py.*%):E319: No "python" provider found.*]] local expected = [[Vim%(py.*%):E319: No "python" provider found.*]]
expect_err(expected, command, 'py print("foo")') matches(expected, pcall_err(command, 'py print("foo")'))
expect_err(expected, command, 'pyfile foo') matches(expected, pcall_err(command, 'pyfile foo'))
end) end)
pending('Python 2 (or the pynvim module) is broken/missing', function() end) pending('Python 2 (or the pynvim module) is broken/missing', function() end)
return return

View File

@@ -6,22 +6,23 @@ local curbufmeths = helpers.curbufmeths
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local expect = helpers.expect local expect = helpers.expect
local expect_err = helpers.expect_err
local feed = helpers.feed local feed = helpers.feed
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local funcs = helpers.funcs local funcs = helpers.funcs
local insert = helpers.insert local insert = helpers.insert
local meths = helpers.meths local meths = helpers.meths
local missing_provider = helpers.missing_provider local missing_provider = helpers.missing_provider
local matches = helpers.matches
local write_file = helpers.write_file local write_file = helpers.write_file
local pcall_err = helpers.pcall_err
do do
clear() clear()
if missing_provider('ruby') then if missing_provider('ruby') then
it(':ruby reports E319 if provider is missing', function() it(':ruby reports E319 if provider is missing', function()
local expected = [[Vim%(ruby.*%):E319: No "ruby" provider found.*]] local expected = [[Vim%(ruby.*%):E319: No "ruby" provider found.*]]
expect_err(expected, command, 'ruby puts "foo"') matches(expected, pcall_err(command, 'ruby puts "foo"'))
expect_err(expected, command, 'rubyfile foo') matches(expected, pcall_err(command, 'rubyfile foo'))
end) end)
pending("Missing neovim RubyGem.", function() end) pending("Missing neovim RubyGem.", function() end)
return return

View File

@@ -10,8 +10,8 @@ local wait = helpers.wait
local retry = helpers.retry local retry = helpers.retry
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local nvim = helpers.nvim local nvim = helpers.nvim
local expect_err = helpers.expect_err
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local pcall_err = helpers.pcall_err
describe(':terminal scrollback', function() describe(':terminal scrollback', function()
local screen local screen
@@ -455,8 +455,10 @@ describe("'scrollback' option", function()
end) end)
it('error if set to invalid value', function() it('error if set to invalid value', function()
expect_err('E474:', command, 'set scrollback=-2') eq('Vim(set):E474: Invalid argument: scrollback=-2',
expect_err('E474:', command, 'set scrollback=100001') pcall_err(command, 'set scrollback=-2'))
eq('Vim(set):E474: Invalid argument: scrollback=100001',
pcall_err(command, 'set scrollback=100001'))
end) end)
it('defaults to -1 on normal buffers', function() it('defaults to -1 on normal buffers', function()

View File

@@ -10,7 +10,7 @@ local meths = helpers.meths
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs local funcs = helpers.funcs
local run = helpers.run local run = helpers.run
local meth_pcall = helpers.meth_pcall local pcall_err = helpers.pcall_err
describe('floating windows', function() describe('floating windows', function()
before_each(function() before_each(function()
@@ -636,26 +636,26 @@ describe('floating windows', function()
it('API has proper error messages', function() it('API has proper error messages', function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
eq({false, "Invalid key 'bork'"}, eq("Invalid key 'bork'",
meth_pcall(meths.open_win,buf, false, {width=20,height=2,bork=true})) pcall_err(meths.open_win,buf, false, {width=20,height=2,bork=true}))
eq({false, "'win' key is only valid with relative='win'"}, eq("'win' key is only valid with relative='win'",
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,win=0})) pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,win=0}))
eq({false, "Only one of 'relative' and 'external' must be used"}, eq("Only one of 'relative' and 'external' must be used",
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,external=true})) pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,external=true}))
eq({false, "Invalid value of 'relative' key"}, eq("Invalid value of 'relative' key",
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='shell',row=0,col=0})) pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='shell',row=0,col=0}))
eq({false, "Invalid value of 'anchor' key"}, eq("Invalid value of 'anchor' key",
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,anchor='bottom'})) pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,anchor='bottom'}))
eq({false, "All of 'relative', 'row', and 'col' has to be specified at once"}, eq("All of 'relative', 'row', and 'col' has to be specified at once",
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor'})) pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor'}))
eq({false, "'width' key must be a positive Integer"}, eq("'width' key must be a positive Integer",
meth_pcall(meths.open_win,buf, false, {width=-1,height=2,relative='editor'})) pcall_err(meths.open_win,buf, false, {width=-1,height=2,relative='editor'}))
eq({false, "'height' key must be a positive Integer"}, eq("'height' key must be a positive Integer",
meth_pcall(meths.open_win,buf, false, {width=20,height=-1,relative='editor'})) pcall_err(meths.open_win,buf, false, {width=20,height=-1,relative='editor'}))
eq({false, "'height' key must be a positive Integer"}, eq("'height' key must be a positive Integer",
meth_pcall(meths.open_win,buf, false, {width=20,height=0,relative='editor'})) pcall_err(meths.open_win,buf, false, {width=20,height=0,relative='editor'}))
eq({false, "Must specify 'width' and 'height'"}, eq("Must specify 'width' and 'height'",
meth_pcall(meths.open_win,buf, false, {relative='editor'})) pcall_err(meths.open_win,buf, false, {relative='editor'}))
end) end)
it('can be placed relative window or cursor', function() it('can be placed relative window or cursor', function()
@@ -4528,8 +4528,8 @@ describe('floating windows', function()
{0:~ }| {0:~ }|
]], float_pos=expected_pos} ]], float_pos=expected_pos}
else else
eq({false, "UI doesn't support external windows"}, eq("UI doesn't support external windows",
meth_pcall(meths.win_set_config, 0, {external=true, width=30, height=2})) pcall_err(meths.win_set_config, 0, {external=true, width=30, height=2}))
return return
end end
@@ -4844,8 +4844,8 @@ describe('floating windows', function()
{0:~ }| {0:~ }|
]], float_pos=expected_pos} ]], float_pos=expected_pos}
else else
eq({false, "UI doesn't support external windows"}, eq("UI doesn't support external windows",
meth_pcall(meths.win_set_config, 0, {external=true, width=65, height=4})) pcall_err(meths.win_set_config, 0, {external=true, width=65, height=4}))
end end
feed(":tabnext<cr>") feed(":tabnext<cr>")

View File

@@ -73,12 +73,23 @@ function module.matches(pat, actual)
end end
error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual)) error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual))
end end
-- Expect an error matching pattern `pat`.
function module.expect_err(pat, ...) -- Invokes `fn` and returns the error string, or raises an error if `fn` succeeds.
local fn = select(1, ...) --
local fn_args = {...} -- Usage:
table.remove(fn_args, 1) -- -- Match exact string.
assert.error_matches(function() return fn(unpack(fn_args)) end, pat) -- 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, ...)
if status == true then
error('expected failure, but got success')
end
local errmsg = tostring(rv):gsub('^[^:]+:%d+: ', '')
return errmsg
end end
-- initial_path: directory to recurse into -- initial_path: directory to recurse into