Skip to content

Commit

Permalink
feat(nvim_exec2): update functional tests to use nvim_exec2()
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Mar 16, 2023
1 parent 6648eb5 commit 050b2e5
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 67 deletions.
2 changes: 1 addition & 1 deletion test/deprecated.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
local M = {}

function M.redir_exec()
error('redir_exec is deprecated, use nvim_exec() or pcall_err()')
error('redir_exec is deprecated, use nvim_exec2() or pcall_err()')
end

return M
6 changes: 3 additions & 3 deletions test/functional/api/extmark_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1413,12 +1413,12 @@ describe('API/extmarks', function()
end)

it('does not crash with append/delete/undo sequence', function()
meths.exec([[
meths.exec2([[
let ns = nvim_create_namespace('myplugin')
call nvim_buf_set_extmark(0, ns, 0, 0, {})
call append(0, '')
%delete
undo]],false)
undo]], { output = false })
assert_alive()
end)

Expand Down Expand Up @@ -1450,7 +1450,7 @@ describe('API/extmarks', function()

feed('u')
-- handles pasting
meths.exec([[let @a='asdfasdf']], false)
meths.exec2([[let @a='asdfasdf']], { output = false })
feed([["ap]])
eq({ {1, 0, 0}, {2, 0, 8} },
meths.buf_get_extmarks(0, ns, 0, -1, {}))
Expand Down
6 changes: 3 additions & 3 deletions test/functional/api/keymap_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)

it('can set <expr> mappings whose RHS change dynamically', function()
meths.exec([[
meths.exec2([[
function! FlipFlop() abort
if !exists('g:flip') | let g:flip = 0 | endif
let g:flip = !g:flip
return g:flip
endfunction
]], true)
]], { output = true })
eq(1, meths.call_function('FlipFlop', {}))
eq(0, meths.call_function('FlipFlop', {}))
eq(1, meths.call_function('FlipFlop', {}))
Expand Down Expand Up @@ -827,7 +827,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
exec_lua [[
vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
]]
assert.truthy(string.match(exec_lua[[return vim.api.nvim_exec(':nmap asdf', true)]],
assert.truthy(string.match(exec_lua[[return vim.api.nvim_exec2(':nmap asdf', { output = true })]],
"^\nn asdf <Lua %d+>"))
end)

Expand Down
20 changes: 10 additions & 10 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('API', function()
]]}
exec([[
func Print()
call nvim_exec('echo "hello"', v:true)
call nvim_exec2('echo "hello"', { 'output': v:true })
endfunc
]])
feed([[:echon 1 | call Print() | echon 5<CR>]])
Expand Down Expand Up @@ -581,7 +581,7 @@ describe('API', function()

it('sets previous directory', function()
meths.set_current_dir("Xtestdir")
meths.exec('cd -', false)
meths.exec2('cd -', { output = false })
eq(funcs.getcwd(), start_dir)
end)
end)
Expand Down Expand Up @@ -2655,7 +2655,7 @@ describe('API', function()
eq(' 1 %a "[No Name]" line 1\n'..
' 3 h "[Scratch]" line 0\n'..
' 4 h "[Scratch]" line 0',
meths.exec('ls', true))
meths.exec2('ls', { output = true }))
-- current buffer didn't change
eq({id=1}, meths.get_current_buf())

Expand Down Expand Up @@ -2769,7 +2769,7 @@ describe('API', function()
end)

it('should not crash when echoed', function()
meths.exec("echo nvim_get_all_options_info()", true)
meths.exec2("echo nvim_get_all_options_info()", { output = true })
end)
end)

Expand Down Expand Up @@ -2922,13 +2922,13 @@ describe('API', function()
it('can save message history', function()
nvim('command', 'set cmdheight=2') -- suppress Press ENTER
nvim("echo", {{"msg\nmsg"}, {"msg"}}, true, {})
eq("msg\nmsgmsg", meths.exec('messages', true))
eq("msg\nmsgmsg", meths.exec2('messages', { output = true }))
end)

it('can disable saving message history', function()
nvim('command', 'set cmdheight=2') -- suppress Press ENTER
nvim_async("echo", {{"msg\nmsg"}, {"msg"}}, false, {})
eq("", meths.exec("messages", true))
eq("", meths.exec2("messages", { output = true }))
end)
end)

Expand Down Expand Up @@ -3917,7 +3917,7 @@ describe('API', function()

it('sets correct script context', function()
meths.cmd({ cmd = "set", args = { "cursorline" } }, {})
local str = meths.exec([[verbose set cursorline?]], true)
local str = meths.exec2([[verbose set cursorline?]], { output = true })
neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)"))
end)

Expand Down Expand Up @@ -3967,7 +3967,7 @@ describe('API', function()
line6
]]
meths.cmd({ cmd = "del", range = { 2, 4 }, reg = 'a' }, {})
meths.exec("1put a", false)
meths.exec2("1put a", { output = false })
expect [[
line1
line2
Expand Down Expand Up @@ -4032,11 +4032,11 @@ describe('API', function()
{ output = true }))
end)
it('splits arguments correctly', function()
meths.exec([[
meths.exec2([[
function! FooFunc(...)
echo a:000
endfunction
]], false)
]], { output = false })
meths.create_user_command("Foo", "call FooFunc(<f-args>)", { nargs = '+' })
eq([=[['a quick', 'brown fox', 'jumps over the', 'lazy dog']]=],
meths.cmd({ cmd = "Foo", args = { "a quick", "brown fox", "jumps over the", "lazy dog"}},
Expand Down
2 changes: 1 addition & 1 deletion test/functional/autocmd/autocmd_oldtest_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local meths = helpers.meths
local funcs = helpers.funcs

local exec = function(str)
meths.exec(str, false)
meths.exec2(str, { output = false })
end

describe('oldtests', function()
Expand Down
6 changes: 3 additions & 3 deletions test/functional/core/exit_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ describe(':cquit', function()
end)

it('exits with redir msg for multiple exit codes after :cquit 1 2', function()
test_cq('cquit 1 2', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2')
test_cq('cquit 1 2', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2')
end)

it('exits with redir msg for non-number exit code after :cquit X', function()
test_cq('cquit X', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: X: cquit X')
test_cq('cquit X', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: X: cquit X')
end)

it('exits with redir msg for negative exit code after :cquit -1', function()
test_cq('cquit -1', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: -1: cquit -1')
test_cq('cquit -1', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: -1: cquit -1')
end)
end)
4 changes: 2 additions & 2 deletions test/functional/core/remote_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Remote', function()
expect(contents)
eq(1, #funcs.getbufinfo())
-- Since we didn't pass silent, we should get a complaint
neq(nil, string.find(meths.exec('messages', true), 'E247'))
neq(nil, string.find(meths.exec2('messages', { output = true }), 'E247'))
end)

it('creates server if not found with tabs', function()
Expand All @@ -110,7 +110,7 @@ describe('Remote', function()
eq(2, #funcs.gettabinfo())
eq(2, #funcs.getbufinfo())
-- We passed silent, so no message should be issued about the server not being found
eq(nil, string.find(meths.exec('messages', true), 'E247'))
eq(nil, string.find(meths.exec2('messages', { output = true }), 'E247'))
end)

pending('exits with error on', function()
Expand Down
7 changes: 3 additions & 4 deletions test/functional/core/startup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('startup', function()
^ |
|
Entering Debug mode. Type "cont" to continue. |
nvim_exec() |
nvim_exec2() |
cmd: aunmenu * |
> |
|
Expand Down Expand Up @@ -691,7 +691,6 @@ describe('sysinit', function()
eq('loaded 1 xdg 0 vim 1',
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
end)

end)

describe('user config init', function()
Expand Down Expand Up @@ -824,7 +823,7 @@ describe('user config init', function()
clear{ args_rm={'-u'}, env=xenv }
feed('<cr><c-c>') -- Dismiss "Conflicting config …" message.
eq(1, eval('g:lua_rc'))
matches('^E5422: Conflicting configs', meths.exec('messages', true))
matches('^E5422: Conflicting configs', meths.exec2('messages', { output = true }))
end)
end)
end)
Expand Down Expand Up @@ -873,7 +872,7 @@ describe('runtime:', function()

eq(2, eval('g:lua_plugin'))
-- Check if plugin_file_path is listed in :scriptname
local scripts = meths.exec(':scriptnames', true)
local scripts = meths.exec2(':scriptnames', { output = true })
assert(scripts:find(plugin_file_path))

-- Check if plugin_file_path is listed in startup profile
Expand Down
24 changes: 12 additions & 12 deletions test/functional/editor/mark_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,59 +40,59 @@ describe('named marks', function()
it("errors when set out of range with :mark", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "1000mark x")
eq("nvim_exec(): Vim(mark):E16: Invalid range: 1000mark x", err)
eq("nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x", err)
end)

it("errors when set out of range with :k", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "1000kx")
eq("nvim_exec(): Vim(k):E16: Invalid range: 1000kx", err)
eq("nvim_exec2(): Vim(k):E16: Invalid range: 1000kx", err)
end)

it("errors on unknown mark name with :mark", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "mark #")
eq("nvim_exec(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err)
eq("nvim_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err)
end)

it("errors on unknown mark name with '", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! '#")
eq("nvim_exec(): Vim(normal):E78: Unknown mark", err)
eq("nvim_exec2(): Vim(normal):E78: Unknown mark", err)
end)

it("errors on unknown mark name with `", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! `#")
eq("nvim_exec(): Vim(normal):E78: Unknown mark", err)
eq("nvim_exec2(): Vim(normal):E78: Unknown mark", err)
end)

it("errors when moving to a mark that is not set with '", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! 'z")
eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
err = pcall_err(helpers.exec_capture, "normal! '.")
eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)

it("errors when moving to a mark that is not set with `", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! `z")
eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
err = pcall_err(helpers.exec_capture, "normal! `>")
eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)

it("errors when moving to a global mark that is not set with '", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! 'Z")
eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)

it("errors when moving to a global mark that is not set with `", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! `Z")
eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)

it("can move to them using '", function()
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('named marks', function()
command("next")
command("bw! " .. file1 )
local err = pcall_err(helpers.exec_capture, "normal! 'A")
eq("nvim_exec(): Vim(normal):E92: Buffer 1 not found", err)
eq("nvim_exec2(): Vim(normal):E92: Buffer 1 not found", err)
os.remove(file1)
end)

Expand Down
4 changes: 2 additions & 2 deletions test/functional/ex_cmds/script_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('script_get-based command', function()
%s %s
endif
]])):format(cmd, garbage)))
eq('', meths.exec('messages', true))
eq('', meths.exec2('messages', { output = true }))
if check_neq then
neq(0, exc_exec(dedent([[
%s %s
Expand All @@ -49,7 +49,7 @@ describe('script_get-based command', function()
EOF
endif
]])):format(cmd, garbage)))
eq('', meths.exec('messages', true))
eq('', meths.exec2('messages', { output = true }))
if check_neq then
eq(true, pcall(source, (dedent([[
let g:exc = 0
Expand Down
20 changes: 10 additions & 10 deletions test/functional/ex_cmds/source_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ describe(':source', function()
let d = s:s]])

command('source')
eq('2', meths.exec('echo a', true))
eq("{'k': 'v'}", meths.exec('echo b', true))
eq('2', meths.exec2('echo a', { output = true }))
eq("{'k': 'v'}", meths.exec2('echo b', { output = true }))

-- Script items are created only on script var access
eq("1", meths.exec('echo c', true))
eq("0zBEEFCAFE", meths.exec('echo d', true))
eq("1", meths.exec2('echo c', { output = true }))
eq("0zBEEFCAFE", meths.exec2('echo d', { output = true }))

exec('set cpoptions+=C')
eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source'))
Expand All @@ -124,14 +124,14 @@ describe(':source', function()
-- Source the 2nd line only
feed('ggjV')
feed_command(':source')
eq('3', meths.exec('echo a', true))
eq('3', meths.exec2('echo a', { output = true }))

-- Source from 2nd line to end of file
feed('ggjVG')
feed_command(':source')
eq('4', meths.exec('echo a', true))
eq("{'K': 'V'}", meths.exec('echo b', true))
eq("<SNR>1_C()", meths.exec('echo D()', true))
eq('4', meths.exec2('echo a', { output = true }))
eq("{'K': 'V'}", meths.exec2('echo b', { output = true }))
eq("<SNR>1_C()", meths.exec2('echo D()', { output = true }))

-- Source last line only
feed_command(':$source')
Expand All @@ -147,7 +147,7 @@ describe(':source', function()
let a = 123
]]
command('source')
eq('123', meths.exec('echo a', true))
eq('123', meths.exec2('echo a', { output = true }))
end)

it('multiline heredoc command', function()
Expand All @@ -157,7 +157,7 @@ describe(':source', function()
EOF]])

command('source')
eq('4', meths.exec('echo luaeval("y")', true))
eq('4', meths.exec2('echo luaeval("y")', { output = true }))
end)

it('can source lua files', function()
Expand Down
4 changes: 2 additions & 2 deletions test/functional/ex_cmds/verbose_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ vim.opt.number = true
vim.api.nvim_set_keymap('n', '<leader>key1', ':echo "test"<cr>', {noremap = true})
vim.keymap.set('n', '<leader>key2', ':echo "test"<cr>')
vim.api.nvim_exec("augroup test_group\
vim.api.nvim_exec2("augroup test_group\
autocmd!\
autocmd FileType c setl cindent\
augroup END\
", false)
", { output = false })
vim.api.nvim_command("command Bdelete :bd")
vim.api.nvim_create_user_command("TestCommand", ":echo 'Hello'", {})
Expand Down
Loading

0 comments on commit 050b2e5

Please sign in to comment.