Skip to content

Commit

Permalink
Update functional tests to use nvim_exec2() instead of nvim_exec().
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Aug 5, 2022
1 parent 1a82043 commit 2baad34
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 50 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 @@ -1398,12 +1398,12 @@ describe('API/extmarks', function()
end)

it('does not crash with append/delete/undo seqence', 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 @@ -1435,7 +1435,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 @@ -675,13 +675,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 @@ -821,7 +821,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
18 changes: 9 additions & 9 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,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 @@ -2597,7 +2597,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 @@ -2711,7 +2711,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 @@ -2846,13 +2846,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 @@ -3673,7 +3673,7 @@ describe('API', function()
end)
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)
it('works with range', function()
Expand Down Expand Up @@ -3722,7 +3722,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 @@ -3767,11 +3767,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
4 changes: 2 additions & 2 deletions test/functional/core/remote_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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 @@ -109,7 +109,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
6 changes: 3 additions & 3 deletions test/functional/core/startup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ describe('sysinit', function()
screen:expect([[
^ |
Entering Debug mode. Type "cont" to continue. |
nvim_exec() |
nvim_exec2() |
cmd: aunmenu * |
> |
<" -u NONE -i NONE --cmd "set noruler" -D 1,1 All|
Expand Down Expand Up @@ -600,7 +600,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 @@ -649,7 +649,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
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 @@ -51,12 +51,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):E15: Invalid expression: #{', exc_exec('source'))
Expand All @@ -79,14 +79,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 @@ -102,7 +102,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 @@ -112,7 +112,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
6 changes: 3 additions & 3 deletions test/functional/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ function module.feed_command(...)
end
end

-- @deprecated use nvim_exec()
-- @deprecated use nvim_exec2()
function module.source(code)
module.exec(dedent(code))
end
Expand Down Expand Up @@ -790,11 +790,11 @@ module.curwinmeths = module.create_callindex(module.curwin)
module.curtabmeths = module.create_callindex(module.curtab)

function module.exec(code)
return module.meths.exec(code, false)
return module.meths.exec2(code, { output = false })
end

function module.exec_capture(code)
return module.meths.exec(code, true)
return module.meths.exec2(code, { output = true })
end

function module.exec_lua(code, ...)
Expand Down
8 changes: 4 additions & 4 deletions test/functional/legacy/assert_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ describe('assert function:', function()
call assert_true('', 'file two')
]])
expected_errors({
"nvim_exec(): equal assertion failed: Expected 1 but got 100",
"nvim_exec(): true assertion failed: Expected False but got 'true'",
"nvim_exec(): false assertion failed: Expected True but got 'false'",
"nvim_exec(): file two: Expected True but got ''",
"nvim_exec2(): equal assertion failed: Expected 1 but got 100",
"nvim_exec2(): true assertion failed: Expected False but got 'true'",
"nvim_exec2(): false assertion failed: Expected True but got 'false'",
"nvim_exec2(): file two: Expected True but got ''",
})
end)
end)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/options/keymap_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("'keymap' / :lmap", function()
command('lmapclear <buffer>')
command('set keymap=dvorak')
command('set nomore')
local bindings = funcs.nvim_exec('lmap', true)
local bindings = funcs.nvim_exec2('lmap', { output = true })
eq(dedent([[
l " @_
Expand Down
8 changes: 4 additions & 4 deletions test/functional/ui/cmdline_highlight_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ describe('Command-line coloring', function()
{EOB:~ }|
:e^ |
]])
eq('', meths.exec('messages', true))
eq('', meths.exec2('messages', { output = true }))
end)
it('silences :echon', function()
set_color_cb('Echoning')
Expand All @@ -377,7 +377,7 @@ describe('Command-line coloring', function()
{EOB:~ }|
:e^ |
]])
eq('', meths.exec('messages', true))
eq('', meths.exec2('messages', { output = true }))
end)
it('silences :echomsg', function()
set_color_cb('Echomsging')
Expand All @@ -392,7 +392,7 @@ describe('Command-line coloring', function()
{EOB:~ }|
:e^ |
]])
eq('', meths.exec('messages', true))
eq('', meths.exec2('messages', { output = true }))
end)
it('does the right thing when throwing', function()
set_color_cb('Throwing')
Expand Down Expand Up @@ -858,7 +858,7 @@ describe('Ex commands coloring', function()
]])
feed('<CR>')
eq('Error detected while processing :\nE605: Exception not caught: 42\nE749: empty buffer',
meths.exec('messages', true))
meths.exec2('messages', { output = true }))
end)
it('errors out when failing to get callback', function()
meths.set_var('Nvim_color_cmdline', 42)
Expand Down
4 changes: 2 additions & 2 deletions test/functional/ui/messages_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ describe('ui/builtin messages', function()

-- screen size doesn't affect internal output #10285
eq('ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red',
meths.exec("hi ErrorMsg", true))
meths.exec2("hi ErrorMsg", { output = true }))
end)

it(':syntax list langGroup output', function()
Expand Down Expand Up @@ -1014,7 +1014,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
match /\<endif\s\+".*$/ms=s+5,lc=5 contains=@vimCommentGroup,vimCommentString
match /\<else\s\+".*$/ms=s+4,lc=4 contains=@vimCommentGroup,vimCommentString
links to Comment]],
meths.exec('syntax list vimComment', true))
meths.exec2('syntax list vimComment', { output = true }))
-- luacheck: pop
end)

Expand Down

0 comments on commit 2baad34

Please sign in to comment.