diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-01-12 19:40:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-12 19:40:58 +0000 |
commit | 07a7c0ec999102f223a6aca17e93d33e18c02b94 (patch) | |
tree | 221ea513b45596f8e63035955494167fc20bf826 /test/functional/core | |
parent | 7f249936a989dbc21ad03e394197afc07cb9c0bf (diff) | |
parent | 795f896a5772d5e0795f86642bdf90c82efac45c (diff) | |
download | rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.gz rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.bz2 rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.zip |
Merge pull request #26994 from lewis6991/vimhelpers
test: big cleanup
Diffstat (limited to 'test/functional/core')
-rw-r--r-- | test/functional/core/channels_spec.lua | 30 | ||||
-rw-r--r-- | test/functional/core/exit_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/core/fileio_spec.lua | 73 | ||||
-rw-r--r-- | test/functional/core/job_spec.lua | 273 | ||||
-rw-r--r-- | test/functional/core/main_spec.lua | 32 | ||||
-rw-r--r-- | test/functional/core/path_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/core/remote_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/core/spellfile_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 114 |
9 files changed, 286 insertions, 290 deletions
diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 0b58e8bc54..ce13c4755d 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source -local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths -local sleep = helpers.sleep +local command, fn, api = helpers.command, helpers.fn, helpers.api +local sleep = vim.uv.sleep local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv local set_session = helpers.set_session local nvim_prog = helpers.nvim_prog @@ -33,12 +33,12 @@ describe('channels', function() pending('can connect to socket', function() local server = spawn(nvim_argv, nil, nil, true) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local client = spawn(nvim_argv, nil, nil, true) set_session(client) source(init) - meths.set_var('address', address) + api.nvim_set_var('address', address) command("let g:id = sockconnect('pipe', address, {'on_data':'OnEvent'})") local id = eval('g:id') ok(id > 0) @@ -46,7 +46,7 @@ describe('channels', function() command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))") set_session(server) retry(nil, 1000, function() - eq(23, meths.get_var('code')) + eq(23, api.nvim_get_var('code')) end) set_session(client) @@ -67,8 +67,8 @@ describe('channels', function() \ 'on_exit': function('OnEvent'), \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ function! OnEvent(id, data, event) dict @@ -117,8 +117,8 @@ describe('channels', function() \ 'on_exit': function('OnEvent'), \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ function! OnStdin(id, data, event) dict @@ -165,8 +165,8 @@ describe('channels', function() \ 'pty': v:true, \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ function! OnEvent(id, data, event) dict @@ -220,8 +220,8 @@ describe('channels', function() \ 'rpc': v:true, \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ let id = stdioopen({'rpc':v:true}) @@ -250,7 +250,7 @@ describe('channels', function() end) it('can use buffered output mode', function() - skip(funcs.executable('grep') == 0, 'missing "grep" command') + skip(fn.executable('grep') == 0, 'missing "grep" command') source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -285,7 +285,7 @@ describe('channels', function() end) it('can use buffered output mode with no stream callback', function() - skip(funcs.executable('grep') == 0, 'missing "grep" command') + skip(fn.executable('grep') == 0, 'missing "grep" command') source([[ function! OnEvent(id, data, event) dict call rpcnotify(1, a:event, a:id, a:data, self.stdout) diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 2c3ebf62aa..b74ebb2367 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -7,7 +7,7 @@ local feed = helpers.feed local eval = helpers.eval local eq = helpers.eq local run = helpers.run -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err local exec_capture = helpers.exec_capture @@ -18,7 +18,7 @@ describe('v:exiting', function() before_each(function() helpers.clear() - cid = helpers.nvim('get_api_info')[1] + cid = helpers.api.nvim_get_api_info()[1] end) it('defaults to v:null', function() @@ -68,7 +68,7 @@ describe(':cquit', function() poke_eventloop() assert_alive() else - funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline }) + fn.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline }) eq(exit_code, eval('v:shell_error')) end end diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 1b9a97648c..928cab525c 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log @@ -9,18 +9,18 @@ local eq = helpers.eq local neq = helpers.neq local ok = helpers.ok local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local request = helpers.request local retry = helpers.retry local rmdir = helpers.rmdir local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local mkdir = helpers.mkdir -local sleep = helpers.sleep +local sleep = vim.uv.sleep local read_file = helpers.read_file -local trim = helpers.trim -local currentdir = helpers.funcs.getcwd +local trim = vim.trim +local currentdir = helpers.fn.getcwd local assert_alive = helpers.assert_alive local check_close = helpers.check_close local expect_exit = helpers.expect_exit @@ -100,8 +100,8 @@ describe('fileio', function() eq('foozubbaz', trim(read_file('Xtest_startup_file1'))) -- 4. Exit caused by deadly signal (+ 'swapfile'). - local j = funcs.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true }) - funcs.rpcrequest( + local j = fn.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true }) + fn.rpcrequest( j, 'nvim_exec2', [[ @@ -112,8 +112,8 @@ describe('fileio', function() ]], {} ) - eq('Xtest_startup_swapdir', funcs.rpcrequest(j, 'nvim_eval', '&directory')) - funcs.jobstop(j) -- Send deadly signal. + eq('Xtest_startup_swapdir', fn.rpcrequest(j, 'nvim_eval', '&directory')) + fn.jobstop(j) -- Send deadly signal. local screen = startup() feed(':recover Xtest_startup_file2<cr>') @@ -210,7 +210,7 @@ describe('fileio', function() local backup_file_name = link_file_name .. '~' write_file('Xtest_startup_file1', initial_content, false) - luv.fs_symlink('Xtest_startup_file1', link_file_name) + uv.fs_symlink('Xtest_startup_file1', link_file_name) command('set backup') command('set backupcopy=yes') command('edit ' .. link_file_name) @@ -233,7 +233,7 @@ describe('fileio', function() local backup_file_name = backup_dir .. sep .. link_file_name .. '~' write_file('Xtest_startup_file1', initial_content, false) - luv.fs_symlink('Xtest_startup_file1', link_file_name) + uv.fs_symlink('Xtest_startup_file1', link_file_name) mkdir(backup_dir) command('set backup') command('set backupcopy=yes') @@ -258,9 +258,9 @@ describe('fileio', function() '', } local fname = 'Xtest_тест.md' - funcs.writefile(text, fname, 's') + fn.writefile(text, fname, 's') table.insert(text, '') - eq(text, funcs.readfile(fname, 'b')) + eq(text, fn.readfile(fname, 'b')) end) it("read invalid u8 over INT_MAX doesn't segfault", function() clear() @@ -295,7 +295,6 @@ describe('fileio', function() local future_time = cur_unix_time + 999999 -- Set the file's access/update time to be -- greater than the time at which it was created. - local uv = require('luv') uv.fs_utime('Xtest-overwrite-forced', future_time, future_time) -- use async feed_command because nvim basically hangs on the prompt feed_command('w') @@ -342,7 +341,7 @@ describe('tmpdir', function() -- Tempfiles typically look like: "…/nvim.<user>/xxx/0". -- - "…/nvim.<user>/xxx/" is the per-process tmpdir, not shared with other Nvims. -- - "…/nvim.<user>/" is the tmpdir root, shared by all Nvims (normally). - local tmproot = (funcs.tempname()):match(tmproot_pat) + local tmproot = (fn.tempname()):match(tmproot_pat) ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot) return tmproot end @@ -361,7 +360,7 @@ describe('tmpdir', function() rmdir(tmproot) write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. assert_log('tempdir root not a directory', testlog, 100) @@ -370,9 +369,9 @@ describe('tmpdir', function() os.remove(testlog) os.remove(tmproot) mkdir(tmproot) - funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. + fn.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. assert_log('tempdir root has invalid permissions', testlog, 100) end) @@ -381,8 +380,8 @@ describe('tmpdir', function() local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666)) mkdir(bigname) clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = bigname } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). - local len = (funcs.tempname()):len() + matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir(). + local len = (fn.tempname()):len() ok(len > 4 and len < 256, '4 < len < 256', tostring(len)) end) @@ -391,33 +390,33 @@ describe('tmpdir', function() assert_nolog('tempdir disappeared', testlog) local function rm_tmpdir() - local tmpname1 = funcs.tempname() - local tmpdir1 = funcs.fnamemodify(tmpname1, ':h') - eq(funcs.stdpath('run'), tmpdir1) + local tmpname1 = fn.tempname() + local tmpdir1 = fn.fnamemodify(tmpname1, ':h') + eq(fn.stdpath('run'), tmpdir1) rmdir(tmpdir1) retry(nil, 1000, function() - eq(0, funcs.isdirectory(tmpdir1)) + eq(0, fn.isdirectory(tmpdir1)) end) - local tmpname2 = funcs.tempname() - local tmpdir2 = funcs.fnamemodify(tmpname2, ':h') + local tmpname2 = fn.tempname() + local tmpdir2 = fn.fnamemodify(tmpname2, ':h') neq(tmpdir1, tmpdir2) end -- Your antivirus hates you... rm_tmpdir() assert_log('tempdir disappeared', testlog, 100) - funcs.tempname() - funcs.tempname() - funcs.tempname() - eq('', meths.get_vvar('errmsg')) + fn.tempname() + fn.tempname() + fn.tempname() + eq('', api.nvim_get_vvar('errmsg')) rm_tmpdir() - funcs.tempname() - funcs.tempname() - funcs.tempname() - eq('E5431: tempdir disappeared (2 times)', meths.get_vvar('errmsg')) + fn.tempname() + fn.tempname() + fn.tempname() + eq('E5431: tempdir disappeared (2 times)', api.nvim_get_vvar('errmsg')) rm_tmpdir() - eq('E5431: tempdir disappeared (3 times)', meths.get_vvar('errmsg')) + eq('E5431: tempdir disappeared (3 times)', api.nvim_get_vvar('errmsg')) end) it('$NVIM_APPNAME relative path', function() @@ -428,6 +427,6 @@ describe('tmpdir', function() TMPDIR = os_tmpdir, }, }) - matches([=[.*[/\\]a%%b%.[^/\\]+]=], funcs.tempname()) + matches([=[.*[/\\]a%%b%.[^/\\]+]=], fn.tempname()) end) end) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 9c82d0bc7c..c6885d0b7c 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -1,29 +1,28 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim, testprg, ok, source, write_file, mkdir, rmdir = - helpers.clear, - helpers.eq, - helpers.eval, - helpers.exc_exec, - helpers.feed_command, - helpers.feed, - helpers.insert, - helpers.neq, - helpers.next_msg, - helpers.nvim, - helpers.testprg, - helpers.ok, - helpers.source, - helpers.write_file, - helpers.mkdir, - helpers.rmdir + +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local exc_exec = helpers.exc_exec +local feed_command = helpers.feed_command +local feed = helpers.feed +local insert = helpers.insert +local neq = helpers.neq +local next_msg = helpers.next_msg +local testprg = helpers.testprg +local ok = helpers.ok +local source = helpers.source +local write_file = helpers.write_file +local mkdir = helpers.mkdir +local rmdir = helpers.rmdir local assert_alive = helpers.assert_alive local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local os_kill = helpers.os_kill local retry = helpers.retry -local meths = helpers.meths -local NIL = helpers.NIL +local api = helpers.api +local NIL = vim.NIL local poke_eventloop = helpers.poke_eventloop local get_pathsep = helpers.get_pathsep local pathroot = helpers.pathroot @@ -43,8 +42,8 @@ describe('jobs', function() before_each(function() clear() - channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) source([[ function! Normalize(data) abort " Windows: remove ^M and term escape sequences @@ -69,22 +68,22 @@ describe('jobs', function() command('let g:job_opts.env = v:true') local _, err = pcall(function() if is_os('win') then - nvim('command', "let j = jobstart('set', g:job_opts)") + command("let j = jobstart('set', g:job_opts)") else - nvim('command', "let j = jobstart('env', g:job_opts)") + command("let j = jobstart('env', g:job_opts)") end end) ok(string.find(err, 'E475: Invalid argument: env') ~= nil) end) it('append environment #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command("let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end expect_msg_seq({ @@ -97,14 +96,14 @@ describe('jobs', function() end) it('append environment with pty #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', 'let g:job_opts.pty = v:true') - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command('let g:job_opts.pty = v:true') + command("let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world abc' } } }, @@ -116,10 +115,10 @@ describe('jobs', function() end) it('replace environment #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - nvim('command', 'let g:job_opts.clear_env = 1') + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command("let g:job_opts.env = {'TOTO': 'hello world'}") + command('let g:job_opts.clear_env = 1') -- libuv ensures that certain "required" environment variables are -- preserved if the user doesn't provide them in a custom environment @@ -129,13 +128,13 @@ describe('jobs', function() -- Rather than expecting a completely empty environment, ensure that $VAR -- is *not* in the environment but $TOTO is. if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world %VAR%', '' } } }, }) else - nvim('command', 'set shell=/bin/sh') - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command('set shell=/bin/sh') + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world', '' } } }, }) @@ -143,17 +142,17 @@ describe('jobs', function() end) it('handles case-insensitively matching #env vars', function() - nvim('command', "let $TOTO = 'abc'") + command("let $TOTO = 'abc'") -- Since $Toto is being set in the job, it should take precedence over the -- global $TOTO on Windows - nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") + command("let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") if is_os('win') then - nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]]) + command([[let j = jobstart('set | find /I "toto="', g:job_opts)]]) else - nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) + command([[let j = jobstart('env | grep -i toto=', g:job_opts)]]) end - nvim('command', 'call jobwait([j])') - nvim('command', 'let g:output = Normalize(g:job_opts.stdout)') + command('call jobwait([j])') + command('let g:output = Normalize(g:job_opts.stdout)') local actual = eval('g:output') local expected if is_os('win') then @@ -169,11 +168,11 @@ describe('jobs', function() end) it('uses &shell and &shellcmdflag if passed a string', function() - nvim('command', "let $VAR = 'abc'") + command("let $VAR = 'abc'") if is_os('win') then - nvim('command', "let j = jobstart('echo %VAR%', g:job_opts)") + command("let j = jobstart('echo %VAR%', g:job_opts)") else - nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") + command("let j = jobstart('echo $VAR', g:job_opts)") end eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) @@ -181,11 +180,11 @@ describe('jobs', function() end) it('changes to given / directory', function() - nvim('command', "let g:job_opts.cwd = '/'") + command("let g:job_opts.cwd = '/'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end eq({ 'notification', 'stdout', { 0, { pathroot(), '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) @@ -195,11 +194,11 @@ describe('jobs', function() it('changes to given `cwd` directory', function() local dir = eval('resolve(tempname())'):gsub('/', get_pathsep()) mkdir(dir) - nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") + command("let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end expect_msg_seq( { @@ -221,11 +220,11 @@ describe('jobs', function() it('fails to change to invalid `cwd`', function() local dir = eval('resolve(tempname())."-bogus"') local _, err = pcall(function() - nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") + command("let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end end) ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil) @@ -236,10 +235,10 @@ describe('jobs', function() local dir = 'Xtest_not_executable_dir' mkdir(dir) - funcs.setfperm(dir, 'rw-------') + fn.setfperm(dir, 'rw-------') matches( '^Vim%(call%):E903: Process failed to start: permission denied: .*', - pcall_err(nvim, 'command', "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") + pcall_err(command, "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") ) rmdir(dir) end) @@ -269,8 +268,8 @@ describe('jobs', function() end) it('invokes callbacks when the job writes and exits', function() - nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") - nvim('command', [[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) + command("let g:job_opts.on_stderr = function('OnEvent')") + command([[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) expect_twostreams({ { 'notification', 'stdout', { 0, { '', '' } } }, { 'notification', 'stdout', { 0, { '' } } }, @@ -279,11 +278,11 @@ describe('jobs', function() end) it('interactive commands', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) - nvim('command', 'call jobsend(j, "abc\\n")') + command('call jobsend(j, "abc\\n")') eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) - nvim('command', 'call jobsend(j, "123\\nxyz\\n")') + command('call jobsend(j, "123\\nxyz\\n")') expect_msg_seq( { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: @@ -292,7 +291,7 @@ describe('jobs', function() { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', 'call jobsend(j, [123, "xyz", ""])') + command('call jobsend(j, [123, "xyz", ""])') expect_msg_seq( { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: @@ -301,7 +300,7 @@ describe('jobs', function() { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) @@ -311,75 +310,75 @@ describe('jobs', function() local filename = helpers.tmpname() write_file(filename, 'abc\0def\n') - nvim('command', "let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") + command("let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") eq({ 'notification', 'stdout', { 0, { 'abc\ndef', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) os.remove(filename) -- jobsend() preserves NULs. - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', [[call jobsend(j, ["123\n456",""])]]) + command("let j = jobstart(['cat', '-'], g:job_opts)") + command([[call jobsend(j, ["123\n456",""])]]) eq({ 'notification', 'stdout', { 0, { '123\n456', '' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') end) it('emits partial lines (does NOT buffer data lacking newlines)', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, "abc\\nxyz")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, "abc\\nxyz")') eq({ 'notification', 'stdout', { 0, { 'abc', 'xyz' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('preserves newlines', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') eq({ 'notification', 'stdout', { 0, { 'a', '', 'c', '', '', '', 'b', '', '' } } }, next_msg()) end) it('preserves NULs', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') eq({ 'notification', 'stdout', { 0, { '\n123\n', 'abc\nxyz\n', '' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('avoids sending final newline', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, ["some data", "without\nfinal nl"])') eq({ 'notification', 'stdout', { 0, { 'some data', 'without\nfinal nl' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('closes the job streams with jobclose', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobclose(j, "stdin")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobclose(j, "stdin")') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) it('disallows jobsend on a job that closed stdin', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobclose(j, "stdin")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobclose(j, "stdin")') eq( false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') + command('call jobsend(j, ["some data"])') end) ) command("let g:job_opts.stdin = 'null'") - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") eq( false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') + command('call jobsend(j, ["some data"])') end) ) end) @@ -390,55 +389,53 @@ describe('jobs', function() end) it('jobstop twice on the stopped or exited job return 0', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) eq(1, eval('jobstop(j)')) eq(0, eval('jobstop(j)')) end) it('will not leak memory if we leave a job running', function() - nvim('command', "call jobstart(['cat', '-'], g:job_opts)") + command("call jobstart(['cat', '-'], g:job_opts)") end) it('can get the pid value using getpid', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") local pid = eval('jobpid(j)') - neq(NIL, meths.get_proc(pid)) - nvim('command', 'call jobstop(j)') + neq(NIL, api.nvim_get_proc(pid)) + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) - eq(NIL, meths.get_proc(pid)) + eq(NIL, api.nvim_get_proc(pid)) end) it('disposed on Nvim exit', function() -- use sleep, which doesn't die on stdin close - nvim( - 'command', + command( "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" ) local pid = eval('jobpid(g:j)') - neq(NIL, meths.get_proc(pid)) + neq(NIL, api.nvim_get_proc(pid)) clear() - eq(NIL, meths.get_proc(pid)) + eq(NIL, api.nvim_get_proc(pid)) end) it('can survive the exit of nvim with "detach"', function() - nvim('command', 'let g:job_opts.detach = 1') - nvim( - 'command', + command('let g:job_opts.detach = 1') + command( "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" ) local pid = eval('jobpid(g:j)') - neq(NIL, meths.get_proc(pid)) + neq(NIL, api.nvim_get_proc(pid)) clear() - neq(NIL, meths.get_proc(pid)) + neq(NIL, api.nvim_get_proc(pid)) -- clean up after ourselves eq(0, os_kill(pid)) end) it('can pass user data to the callback', function() - nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') + command([[call jobstart('echo foo', g:job_opts)]]) local data = { n = 5, s = 'str', l = { 1 } } expect_msg_seq( { @@ -456,16 +453,16 @@ describe('jobs', function() end) it('can omit data callbacks', function() - nvim('command', 'unlet g:job_opts.on_stdout') - nvim('command', 'let g:job_opts.user = 5') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('unlet g:job_opts.on_stdout') + command('let g:job_opts.user = 5') + command([[call jobstart('echo foo', g:job_opts)]]) eq({ 'notification', 'exit', { 5, 0 } }, next_msg()) end) it('can omit exit callback', function() - nvim('command', 'unlet g:job_opts.on_exit') - nvim('command', 'let g:job_opts.user = 5') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('unlet g:job_opts.on_exit') + command('let g:job_opts.user = 5') + command([[call jobstart('echo foo', g:job_opts)]]) expect_msg_seq( { { 'notification', 'stdout', { 5, { 'foo', '' } } }, @@ -481,8 +478,8 @@ describe('jobs', function() end) it('will pass return code with the exit event', function() - nvim('command', 'let g:job_opts.user = 5') - nvim('command', "call jobstart('exit 55', g:job_opts)") + command('let g:job_opts.user = 5') + command("call jobstart('exit 55', g:job_opts)") eq({ 'notification', 'stdout', { 5, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 5, 55 } }, next_msg()) end) @@ -883,7 +880,7 @@ describe('jobs', function() r = next_msg() eq('job ' .. i .. ' exited', r[3][1]) end - eq(10, nvim('eval', 'g:counter')) + eq(10, api.nvim_eval('g:counter')) end) describe('with timeout argument', function() @@ -948,15 +945,15 @@ describe('jobs', function() ]], } feed('<CR>') - funcs.jobstop(meths.get_var('id')) + fn.jobstop(api.nvim_get_var('id')) end) end) pending('exit event follows stdout, stderr', function() - nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('eval', 'jobsend(j, "abcdef")') - nvim('eval', 'jobstop(j)') + command("let g:job_opts.on_stderr = function('OnEvent')") + command("let j = jobstart(['cat', '-'], g:job_opts)") + api.nvim_eval('jobsend(j, "abcdef")') + api.nvim_eval('jobstop(j)') expect_msg_seq( { { 'notification', 'stdout', { 0, { 'abcdef' } } }, @@ -1062,11 +1059,11 @@ describe('jobs', function() end local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30') local j = eval("jobstart('" .. sleep_cmd .. ' | ' .. sleep_cmd .. ' | ' .. sleep_cmd .. "')") - local ppid = funcs.jobpid(j) + local ppid = fn.jobpid(j) local children if is_os('win') then local status, result = pcall(retry, nil, nil, function() - children = meths.get_proc_children(ppid) + children = api.nvim_get_proc_children(ppid) -- On Windows conhost.exe may exist, and -- e.g. vctip.exe might appear. #10783 ok(#children >= 3 and #children <= 5) @@ -1078,28 +1075,28 @@ describe('jobs', function() end else retry(nil, nil, function() - children = meths.get_proc_children(ppid) + children = api.nvim_get_proc_children(ppid) eq(3, #children) end) end -- Assert that nvim_get_proc() sees the children. for _, child_pid in ipairs(children) do - local info = meths.get_proc(child_pid) + local info = api.nvim_get_proc(child_pid) -- eq((is_os('win') and 'nvim.exe' or 'nvim'), info.name) eq(ppid, info.ppid) end -- Kill the root of the tree. - eq(1, funcs.jobstop(j)) + eq(1, fn.jobstop(j)) -- Assert that the children were killed. retry(nil, nil, function() for _, child_pid in ipairs(children) do - eq(NIL, meths.get_proc(child_pid)) + eq(NIL, api.nvim_get_proc(child_pid)) end end) end) it('jobstop on same id before stopped', function() - nvim('command', 'let j = jobstart(["cat", "-"], g:job_opts)') + command('let j = jobstart(["cat", "-"], g:job_opts)') neq(0, eval('j')) eq({ 1, 0 }, eval('[jobstop(j), jobstop(j)]')) @@ -1129,7 +1126,7 @@ describe('jobs', function() local j local function send(str) -- check no nvim_chan_free double free with pty job (#14198) - meths.chan_send(j, str) + api.nvim_chan_send(j, str) end before_each(function() @@ -1140,9 +1137,9 @@ describe('jobs', function() endfunction ]]) insert(testprg('tty-test')) - nvim('command', 'let g:job_opts.pty = 1') - nvim('command', 'let exec = [expand("<cfile>:p")]') - nvim('command', 'let j = jobstart(exec, g:job_opts)') + command('let g:job_opts.pty = 1') + command('let exec = [expand("<cfile>:p")]') + command('let j = jobstart(exec, g:job_opts)') j = eval 'j' eq('tty ready', next_chunk()) end) @@ -1153,14 +1150,14 @@ describe('jobs', function() end) it('resizing window', function() - nvim('command', 'call jobresize(j, 40, 10)') + command('call jobresize(j, 40, 10)') eq('rows: 10, cols: 40', next_chunk()) - nvim('command', 'call jobresize(j, 10, 40)') + command('call jobresize(j, 10, 40)') eq('rows: 40, cols: 10', next_chunk()) end) it('jobclose() sends SIGHUP', function() - nvim('command', 'call jobclose(j)') + command('call jobclose(j)') local msg = next_msg() msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any. eq({ 'notification', 'exit', { 0, 42 } }, msg) @@ -1177,7 +1174,7 @@ describe('jobs', function() -- Have to wait so that the SIGHUP can be processed by tty-test on time. -- Can't wait for the next message in case this test fails, if it fails -- there won't be any more messages, and the test would hang. - helpers.sleep(100) + vim.uv.sleep(100) local err = exc_exec('call jobpid(j)') eq('Vim(call):E900: Invalid channel id', err) @@ -1244,7 +1241,7 @@ describe('pty process teardown', function() it('does not prevent/delay exit. #4798 #4900', function() skip(is_os('win')) -- Use a nested nvim (in :term) to test without --headless. - funcs.termopen({ + fn.termopen({ helpers.nvim_prog, '-u', 'NONE', diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 4a9943be20..1d2261ee05 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') @@ -7,7 +7,7 @@ local matches = helpers.matches local feed = helpers.feed local eval = helpers.eval local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog_abs = helpers.nvim_prog_abs local write_file = helpers.write_file local is_os = helpers.is_os @@ -32,8 +32,8 @@ describe('command-line option', function() end) it('treats - as stdin', function() - eq(nil, luv.fs_stat(fname)) - funcs.system({ + eq(nil, uv.fs_stat(fname)) + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -47,15 +47,15 @@ describe('command-line option', function() fname, }, { ':call setline(1, "42")', ':wqall!', '' }) eq(0, eval('v:shell_error')) - local attrs = luv.fs_stat(fname) + local attrs = uv.fs_stat(fname) eq(#'42\n', attrs.size) end) it('does not expand $VAR', function() - eq(nil, luv.fs_stat(fname)) + eq(nil, uv.fs_stat(fname)) eq(true, not not dollar_fname:find('%$%w+')) write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n') - funcs.system({ + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -69,7 +69,7 @@ describe('command-line option', function() fname, }) eq(0, eval('v:shell_error')) - local attrs = luv.fs_stat(fname) + local attrs = uv.fs_stat(fname) eq(#'100500\n', attrs.size) end) @@ -91,7 +91,7 @@ describe('command-line option', function() -- Need to explicitly pipe to stdin so that the embedded Nvim instance doesn't try to read -- data from the terminal #18181 - funcs.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), { + fn.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) screen:expect( @@ -128,7 +128,7 @@ describe('command-line option', function() it('errors out when trying to use nonexistent file with -s', function() eq( 'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n', - funcs.system({ + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -151,7 +151,7 @@ describe('command-line option', function() write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n') eq( 'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n', - funcs.system({ + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -170,14 +170,14 @@ describe('command-line option', function() }) ) eq(2, eval('v:shell_error')) - eq(nil, luv.fs_stat(fname_2)) + eq(nil, uv.fs_stat(fname_2)) end) end) it('nvim -v, :version', function() - matches('Run ":verbose version"', funcs.execute(':version')) - matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version')) - matches('Run "nvim %-V1 %-v"', funcs.system({ nvim_prog_abs(), '-v' })) - matches('Compilation: .*Run :checkhealth', funcs.system({ nvim_prog_abs(), '-V1', '-v' })) + matches('Run ":verbose version"', fn.execute(':version')) + matches('Compilation: .*Run :checkhealth', fn.execute(':verbose version')) + matches('Run "nvim %-V1 %-v"', fn.system({ nvim_prog_abs(), '-v' })) + matches('Compilation: .*Run :checkhealth', fn.system({ nvim_prog_abs(), '-V1', '-v' })) end) end) diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 21364d7c03..e98bfc0d45 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir @@ -167,7 +167,7 @@ describe('file search', function() else write_file(expected, '') end - eq(expected, funcs[funcname](item, d:gsub(' ', [[\ ]]))) + eq(expected, fn[funcname](item, d:gsub(' ', [[\ ]]))) end it('finddir()', function() diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index 5eb520ef4f..a48534f51b 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local expect = helpers.expect -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local nvim_prog = helpers.nvim_prog local new_argv = helpers.new_argv @@ -42,7 +42,7 @@ describe('Remote', function() -- Run a `nvim --remote*` command and return { stdout, stderr } of the process local function run_remote(...) set_session(server) - local addr = funcs.serverlist()[1] + local addr = fn.serverlist()[1] -- Create an nvim instance just to run the remote-invoking nvim. We want -- to wait for the remote instance to exit and calling jobwait blocks @@ -81,20 +81,20 @@ describe('Remote', function() it('edit a single file', function() eq({ '', '' }, run_remote('--remote', fname)) expect(contents) - eq(2, #funcs.getbufinfo()) + eq(2, #fn.getbufinfo()) end) it('tab edit a single file with a non-changed buffer', function() eq({ '', '' }, run_remote('--remote-tab', fname)) expect(contents) - eq(1, #funcs.gettabinfo()) + eq(1, #fn.gettabinfo()) end) it('tab edit a single file with a changed buffer', function() insert('hello') eq({ '', '' }, run_remote('--remote-tab', fname)) expect(contents) - eq(2, #funcs.gettabinfo()) + eq(2, #fn.gettabinfo()) end) it('edit multiple files', function() @@ -102,15 +102,15 @@ describe('Remote', function() expect(contents) command('next') expect(other_contents) - eq(3, #funcs.getbufinfo()) + eq(3, #fn.getbufinfo()) end) it('send keys', function() eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. '<CR><C-W>v')) expect(contents) - eq(2, #funcs.getwininfo()) + eq(2, #fn.getwininfo()) -- Only a single buffer as we're using edit and not drop like --remote does - eq(1, #funcs.getbufinfo()) + eq(1, #fn.getbufinfo()) end) it('evaluate expressions', function() @@ -127,7 +127,7 @@ describe('Remote', function() it('creates server if not found', function() clear('--remote', fname) expect(contents) - eq(1, #funcs.getbufinfo()) + eq(1, #fn.getbufinfo()) -- Since we didn't pass silent, we should get a complaint neq(nil, string.find(exec_capture('messages'), 'E247:')) end) @@ -135,8 +135,8 @@ describe('Remote', function() it('creates server if not found with tabs', function() clear('--remote-tab-silent', fname, other_fname) expect(contents) - eq(2, #funcs.gettabinfo()) - eq(2, #funcs.getbufinfo()) + eq(2, #fn.gettabinfo()) + eq(2, #fn.getbufinfo()) -- We passed silent, so no message should be issued about the server not being found eq(nil, string.find(exec_capture('messages'), 'E247:')) end) diff --git a/test/functional/core/spellfile_spec.lua b/test/functional/core/spellfile_spec.lua index 60cdf88fe3..7dcdfac315 100644 --- a/test/functional/core/spellfile_spec.lua +++ b/test/functional/core/spellfile_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local clear = helpers.clear -local meths = helpers.meths +local api = helpers.api local exc_exec = helpers.exc_exec local rmdir = helpers.rmdir local write_file = helpers.write_file @@ -24,7 +24,7 @@ describe('spellfile', function() -- │ ┌ Spell file version (#VIMSPELLVERSION) local spellheader = 'VIMspell\050' it('errors out when prefcond section is truncated', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_PREFCOND) @@ -35,11 +35,11 @@ describe('spellfile', function() -- │ ┌ Condition length (1 byte) -- │ │ ┌ Condition regex (missing!) .. '\000\001\001') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E758: Truncated spell file', exc_exec('set spell')) end) it('errors out when prefcond regexp contains NUL byte', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_PREFCOND) @@ -55,11 +55,11 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when region contains NUL byte', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_REGION) @@ -72,11 +72,11 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when SAL section contains NUL byte', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_SAL) @@ -96,13 +96,13 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when spell header contains NUL bytes', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell')) end) end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index ebf9deb86b..fd3748a985 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -13,8 +13,8 @@ local exec = helpers.exec local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local feed = helpers.feed -local funcs = helpers.funcs -local pesc = helpers.pesc +local fn = helpers.fn +local pesc = vim.pesc local mkdir = helpers.mkdir local mkdir_p = helpers.mkdir_p local nvim_prog = helpers.nvim_prog @@ -22,24 +22,24 @@ local nvim_set = helpers.nvim_set local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir -local sleep = helpers.sleep -local startswith = helpers.startswith +local sleep = vim.uv.sleep +local startswith = vim.startswith local write_file = helpers.write_file -local meths = helpers.meths +local api = helpers.api local alter_slashes = helpers.alter_slashes local is_os = helpers.is_os local dedent = helpers.dedent -local tbl_map = helpers.tbl_map -local tbl_filter = helpers.tbl_filter -local endswith = helpers.endswith +local tbl_map = vim.tbl_map +local tbl_filter = vim.tbl_filter +local endswith = vim.endswith describe('startup', function() it('--clean', function() clear() ok( string.find( - alter_slashes(meths.get_option_value('runtimepath', {})), - funcs.stdpath('config'), + alter_slashes(api.nvim_get_option_value('runtimepath', {})), + fn.stdpath('config'), 1, true ) ~= nil @@ -47,8 +47,8 @@ describe('startup', function() clear('--clean') ok( string.find( - alter_slashes(meths.get_option_value('runtimepath', {})), - funcs.stdpath('config'), + alter_slashes(api.nvim_get_option_value('runtimepath', {})), + fn.stdpath('config'), 1, true ) == nil @@ -60,7 +60,7 @@ describe('startup', function() local screen screen = Screen.new(84, 3) screen:attach() - funcs.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) + fn.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) screen:expect([[ ^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) | |*2 @@ -82,7 +82,7 @@ describe('startup', function() local screen screen = Screen.new(60, 7) screen:attach() - local id = funcs.termopen({ + local id = fn.termopen({ nvim_prog, '-u', 'NONE', @@ -105,7 +105,7 @@ describe('startup', function() > | | ]]) - funcs.chansend(id, 'cont\n') + fn.chansend(id, 'cont\n') screen:expect([[ ^ | ~ |*3 @@ -124,13 +124,13 @@ describe('startup', function() vim.list_extend(args, nvim_args or {}) vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, lua_args or {}) - local out = funcs.system(args, input):gsub('\r\n', '\n') + local out = fn.system(args, input):gsub('\r\n', '\n') return eq(dedent(expected), out) end it('failure modes', function() -- nvim -l <empty> - matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + matches('nvim%.?e?x?e?: Argument missing after: "%-l"', fn.system({ nvim_prog, '-l' })) eq(1, eval('v:shell_error')) end) @@ -161,12 +161,12 @@ describe('startup', function() eq(0, eval('v:shell_error')) matches( 'E5113: .* my pearls!!', - funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) + fn.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) ) eq(1, eval('v:shell_error')) matches( 'E5113: .* %[string "error%("whoa"%)"%]:1: whoa', - funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")') + fn.system({ nvim_prog, '-l', '-' }, 'error("whoa")') ) eq(1, eval('v:shell_error')) end) @@ -286,7 +286,7 @@ describe('startup', function() end) it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function() - local out = funcs.system({ + local out = fn.system({ nvim_prog, '-u', 'NONE', @@ -305,7 +305,7 @@ describe('startup', function() it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() -- system() puts a pipe at both ends. - local out = funcs.system({ + local out = fn.system({ nvim_prog, '-u', 'NONE', @@ -340,7 +340,7 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - funcs.termopen({ + fn.termopen({ nvim_prog, '-u', 'NONE', @@ -372,7 +372,7 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - funcs.termopen( + fn.termopen( ( [["%s" -u NONE -i NONE --cmd "%s"]] .. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] @@ -402,7 +402,7 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - funcs.termopen( + fn.termopen( ( [[echo foo | ]] -- Input from a pipe. .. [["%s" -u NONE -i NONE --cmd "%s"]] @@ -431,7 +431,7 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - funcs.termopen( + fn.termopen( ( [[echo foo | ]] .. [["%s" -u NONE -i NONE --cmd "%s"]] @@ -454,7 +454,7 @@ describe('startup', function() it('input from pipe + file args #7679', function() eq( 'ohyeah\r\n0 0 bufs=3', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -475,7 +475,7 @@ describe('startup', function() it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function() eq( '\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -501,7 +501,7 @@ describe('startup', function() -- eq( 'partylikeits1999\n', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -513,16 +513,16 @@ describe('startup', function() 'test/functional/fixtures/tty-test.c', }, { 'partylikeits1999', '' }) ) - eq(inputstr, funcs.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) + eq(inputstr, fn.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) -- with `-u NORC` eq( 'thepartycontinues\n', - funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' }) + fn.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' }) ) -- without `-u` eq( 'thepartycontinues\n', - funcs.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' }) + fn.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' }) ) -- @@ -530,7 +530,7 @@ describe('startup', function() -- eq( ' encoding=utf-8\n', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -541,19 +541,19 @@ describe('startup', function() 'test/functional/fixtures/tty-test.c', }, { 'set encoding', '' }) ) - eq('line1\nline2\n', funcs.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input)) + eq('line1\nline2\n', fn.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input)) -- with `-u NORC` eq( ' encoding=utf-8\n', - funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' }) + fn.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' }) ) -- without `-u` - eq(' encoding=utf-8\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) + eq(' encoding=utf-8\n', fn.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) end) it('-es/-Es disables swapfile, user config #8540', function() for _, arg in ipairs({ '-es', '-Es' }) do - local out = funcs.system({ + local out = fn.system({ nvim_prog, arg, '+set swapfile? updatecount? shadafile?', @@ -572,15 +572,15 @@ describe('startup', function() it('fails on --embed with -es/-Es/-l', function() matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({ nvim_prog, '--embed', '-es' }) + fn.system({ nvim_prog, '--embed', '-es' }) ) matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({ nvim_prog, '--embed', '-Es' }) + fn.system({ nvim_prog, '--embed', '-Es' }) ) matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) + fn.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) ) end) @@ -588,7 +588,7 @@ describe('startup', function() local screen screen = Screen.new(60, 6) screen:attach() - local id = funcs.termopen({ + local id = fn.termopen({ nvim_prog, '-u', 'NONE', @@ -611,7 +611,7 @@ describe('startup', function() Press ENTER or type command to continue | | ]]) - funcs.chansend(id, '\n') + fn.chansend(id, '\n') screen:expect([[ ^ | ~ |*2 @@ -651,7 +651,7 @@ describe('startup', function() expected, -- FIXME(codehex): We should really set a timeout for the system function. -- If this test fails, there will be a waiting input state. - funcs.system({ + fn.system({ nvim_prog, '-u', 'NONE', @@ -663,7 +663,7 @@ describe('startup', function() end) it('get command line arguments from v:argv', function() - local out = funcs.system({ + local out = fn.system({ nvim_prog, '-u', 'NONE', @@ -715,7 +715,7 @@ describe('startup', function() :put =mode(1) | ]]) - eq('cv\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' })) + eq('cv\n', fn.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' })) end) it('-d does not diff non-arglist windows #13720 #21289', function() @@ -737,11 +737,11 @@ describe('startup', function() os.remove('Xdiff.vim') end) clear { args = { '-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim' } } - eq(true, meths.get_option_value('diff', { win = funcs.win_getid(1) })) - eq(true, meths.get_option_value('diff', { win = funcs.win_getid(2) })) - local float_win = funcs.win_getid(3) - eq('editor', meths.win_get_config(float_win).relative) - eq(false, meths.get_option_value('diff', { win = float_win })) + eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(1) })) + eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(2) })) + local float_win = fn.win_getid(3) + eq('editor', api.nvim_win_get_config(float_win).relative) + eq(false, api.nvim_get_option_value('diff', { win = float_win })) end) it('does not crash if --embed is given twice', function() @@ -870,7 +870,7 @@ describe('startup', function() exec_lua [[ return _G.test_loadorder ]] ) - local rtp = meths.get_option_value('rtp', {}) + local rtp = api.nvim_get_option_value('rtp', {}) ok( startswith( rtp, @@ -963,9 +963,9 @@ describe('startup', function() os.remove('Xtab2.noft') end) clear({ args = { '-p', 'Xtab1.noft', 'Xtab2.noft' } }) - eq(81, meths.win_get_width(0)) + eq(81, api.nvim_win_get_width(0)) command('tabnext') - eq(81, meths.win_get_width(0)) + eq(81, api.nvim_win_get_width(0)) end) end) @@ -1062,7 +1062,7 @@ describe('user config init', function() clear { args_rm = { '-u' }, env = xenv } eq(1, eval('g:lua_rc')) - eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) + eq(fn.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) end) describe('loads existing', function() @@ -1122,7 +1122,7 @@ describe('user config init', function() local screen = Screen.new(50, 8) screen:attach() - funcs.termopen({ nvim_prog }, { + fn.termopen({ nvim_prog }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -1245,7 +1245,7 @@ describe('runtime:', function() -- Check if plugin_file_path is listed in getscriptinfo() local scripts = tbl_map(function(s) return s.name - end, funcs.getscriptinfo()) + end, fn.getscriptinfo()) ok(#tbl_filter(function(s) return endswith(s, plugin_file_path) end, scripts) > 0) @@ -1369,13 +1369,13 @@ describe('inccommand on ex mode', function() local screen screen = Screen.new(60, 10) screen:attach() - local id = funcs.termopen( + local id = fn.termopen( { nvim_prog, '-u', 'NONE', '-c', 'set termguicolors', '-E', 'test/README.md' }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, } ) - funcs.chansend(id, '%s/N') + fn.chansend(id, '%s/N') screen:expect { grid = [[ {1:^ }| |