diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /test/functional/ex_cmds | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'test/functional/ex_cmds')
22 files changed, 434 insertions, 271 deletions
diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index fadb5c9b42..4134eed87e 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -8,6 +8,7 @@ local clear = helpers.clear local funcs = helpers.funcs local command = helpers.command local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local Screen = require('test.functional.ui.screen') local cmdtest = function(cmd, prep, ret1) @@ -42,7 +43,7 @@ local cmdtest = function(cmd, prep, ret1) eq(hisline, funcs.histget(':', -2)) eq(cmd, funcs.histget(':')) -- Test that command-line window was launched - eq('nofile', curbufmeths.get_option('buftype')) + eq('nofile', meths.get_option_value('buftype', {})) eq('n', funcs.mode(1)) feed('<CR>') eq('c', funcs.mode(1)) diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index 5ed71651c7..b6a3713158 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -1,6 +1,6 @@ -- Specs for :cd, :tcd, :lcd and getcwd() -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq @@ -11,6 +11,7 @@ local exc_exec = helpers.exc_exec local pathsep = helpers.get_pathsep() local skip = helpers.skip local is_os = helpers.is_os +local mkdir = helpers.mkdir -- These directories will be created for testing local directories = { @@ -36,14 +37,14 @@ for _, cmd in ipairs {'cd', 'chdir'} do before_each(function() clear() for _, d in pairs(directories) do - lfs.mkdir(d) + mkdir(d) end directories.start = cwd() end) after_each(function() for _, d in pairs(directories) do - lfs.rmdir(d) + luv.fs_rmdir(d) end end) @@ -273,7 +274,7 @@ end describe("getcwd()", function () before_each(function() clear() - lfs.mkdir(directories.global) + mkdir(directories.global) end) after_each(function() diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index 919d167712..2a2628350d 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -90,7 +90,7 @@ describe('mappings with <Cmd>', function() {1:~ }| {1:~ }| {1:~ }| - {2:E5521: <Cmd> mapping must end with <CR> before second <Cmd>} | + {2:E1136: <Cmd> mapping must end with <CR> before second <Cmd>} | ]]) command('noremap <F3> <Cmd>let x = 3') @@ -103,7 +103,7 @@ describe('mappings with <Cmd>', function() {1:~ }| {1:~ }| {1:~ }| - {2:E5520: <Cmd> mapping must end with <CR>} | + {2:E1255: <Cmd> mapping must end with <CR>} | ]]) eq(0, eval('x')) end) @@ -451,7 +451,7 @@ describe('mappings with <Cmd>', function() ]]) eq('s', funcs.mode(1)) - -- visual mapping in select mode restart selct mode after operator + -- visual mapping in select mode restart select mode after operator feed('<F5>') eq('s', funcs.mode(1)) eq({'some short l'}, funcs.getreg('a',1,1)) diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index afa6b519d5..6a0b40bd88 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -9,7 +9,7 @@ local command = helpers.command local eval = helpers.eval -describe('VimL dictionary notifications', function() +describe('Vimscript dictionary notifications', function() local channel before_each(function() diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index e243f3c524..a92329ede5 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -2,6 +2,7 @@ local helpers = require("test.functional.helpers")(after_each) local command = helpers.command local eq = helpers.eq local clear = helpers.clear +local funcs = helpers.funcs local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -10,21 +11,43 @@ describe('Ex cmds', function() clear() end) + local function check_excmd_err(cmd, err) + eq(err .. ': ' .. cmd, pcall_err(command, cmd)) + end + it('handle integer overflow from user-input #5555', function() command(':9999999999999999999999999999999999999999') command(':later 9999999999999999999999999999999999999999') command(':echo expand("#<9999999999999999999999999999999999999999")') command(':lockvar 9999999999999999999999999999999999999999') command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999') - eq('Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999', - pcall_err(command, ':tabnext 9999999999999999999999999999999999999999')) - eq('Vim(Next):E939: Positive count required', - pcall_err(command, ':N 9999999999999999999999999999999999999999')) + check_excmd_err(':tabnext 9999999999999999999999999999999999999999', + 'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999') + check_excmd_err(':N 9999999999999999999999999999999999999999', + 'Vim(Next):E939: Positive count required') + check_excmd_err(':bdelete 9999999999999999999999999999999999999999', + 'Vim(bdelete):E939: Positive count required') eq('Vim(menu):E329: No menu "9999999999999999999999999999999999999999"', pcall_err(command, ':menu 9999999999999999999999999999999999999999')) - eq('Vim(bdelete):E939: Positive count required', - pcall_err(command, ':bdelete 9999999999999999999999999999999999999999')) assert_alive() end) -end) + it('listing long user command does not crash', function() + command('execute "command" repeat("T", 255) ":"') + command('command') + end) + + it(':def is an unknown command #23149', function() + eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) + eq(1, funcs.exists(':d')) + eq('delete', funcs.fullcommand('d')) + eq(1, funcs.exists(':de')) + eq('delete', funcs.fullcommand('de')) + eq(0, funcs.exists(':def')) + eq('', funcs.fullcommand('def')) + eq(1, funcs.exists(':defe')) + eq('defer', funcs.fullcommand('defe')) + eq(2, funcs.exists(':defer')) + eq('defer', funcs.fullcommand('defer')) + end) +end) diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua index 771c283134..131661828e 100644 --- a/test/functional/ex_cmds/file_spec.lua +++ b/test/functional/ex_cmds/file_spec.lua @@ -1,17 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local clear = helpers.clear local command = helpers.command local eq = helpers.eq local funcs = helpers.funcs local rmdir = helpers.rmdir +local mkdir = helpers.mkdir describe(':file', function() - local swapdir = lfs.currentdir()..'/Xtest-file_spec' + local swapdir = luv.cwd()..'/Xtest-file_spec' before_each(function() clear() rmdir(swapdir) - lfs.mkdir(swapdir) + mkdir(swapdir) end) after_each(function() command('%bwipeout!') diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua index 0ec7249218..aca0cbbaa6 100644 --- a/test/functional/ex_cmds/help_spec.lua +++ b/test/functional/ex_cmds/help_spec.lua @@ -4,6 +4,10 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local funcs = helpers.funcs +local meths = helpers.meths +local mkdir = helpers.mkdir +local rmdir = helpers.rmdir +local write_file = helpers.write_file describe(':help', function() before_each(clear) @@ -25,4 +29,17 @@ describe(':help', function() -- Before #9773, Nvim would crash on quitting the help window. eq(1002, funcs.win_getid()) end) + + it('multibyte help tags work #23975', function() + mkdir('Xhelptags') + finally(function() + rmdir('Xhelptags') + end) + mkdir('Xhelptags/doc') + write_file('Xhelptags/doc/Xhelptags.txt', '*…*') + command('helptags Xhelptags/doc') + command('set rtp+=Xhelptags') + command('help …') + eq('*…*', meths.get_current_line()) + end) end) diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 1cd6759a53..958dd99226 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -3,6 +3,9 @@ local helpers = require("test.functional.helpers")(after_each) local eq, command = helpers.eq, helpers.command local clear = helpers.clear local eval, exc_exec = helpers.eval, helpers.exc_exec +local exec = helpers.exec +local funcs = helpers.funcs +local meths = helpers.meths describe(':highlight', function() local screen @@ -21,7 +24,7 @@ describe(':highlight', function() end) it('invalid group name', function() - eq('Vim(highlight):E411: highlight group not found: foo', + eq('Vim(highlight):E411: Highlight group not found: foo', exc_exec("highlight foo")) end) @@ -36,4 +39,29 @@ describe(':highlight', function() command('highlight normal ctermbg=red') eq('9', eval('synIDattr(hlID("Normal"), "bg", "cterm")')) end) + + it('only the last underline style takes effect #22371', function() + command('highlight NonText gui=underline,undercurl') + eq('', eval('synIDattr(hlID("NonText"), "underline", "gui")')) + eq('1', eval('synIDattr(hlID("NonText"), "undercurl", "gui")')) + command('highlight NonText gui=undercurl,underline') + eq('', eval('synIDattr(hlID("NonText"), "undercurl", "gui")')) + eq('1', eval('synIDattr(hlID("NonText"), "underline", "gui")')) + end) + + it('clear', function() + meths.set_var('colors_name', 'foo') + eq(1, funcs.exists('g:colors_name')) + command('hi clear') + eq(0, funcs.exists('g:colors_name')) + meths.set_var('colors_name', 'foo') + eq(1, funcs.exists('g:colors_name')) + exec([[ + func HiClear() + hi clear + endfunc + ]]) + funcs.HiClear() + eq(0, funcs.exists('g:colors_name')) + end) end) diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua index 2583d80269..d02af21731 100644 --- a/test/functional/ex_cmds/ls_spec.lua +++ b/test/functional/ex_cmds/ls_spec.lua @@ -14,7 +14,7 @@ describe(':ls', function() end) it('R, F for :terminal buffers', function() - nvim('set_option', 'shell', string.format('"%s" INTERACT', testprg('shell-test'))) + nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('edit foo') command('set hidden') diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index bf585ee44c..d82f59ddf9 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -22,20 +22,18 @@ describe(':make', function() end) it('captures stderr & non zero exit code #14349', function () - nvim('set_option', 'makeprg', testprg('shell-test')..' foo') + nvim('set_option_value', 'makeprg', testprg('shell-test')..' foo', {}) local out = eval('execute("make")') - -- Make program exit code correctly captured - matches('\nshell returned 3', out) -- Error message is captured in the file and printed in the footer - matches('\n.*%: Unknown first argument%: foo', out) + matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out) end) it('captures stderr & zero exit code #14349', function () - nvim('set_option', 'makeprg', testprg('shell-test')) + nvim('set_option_value', 'makeprg', testprg('shell-test'), {}) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between - -- command and last line (indicating zero exit) - matches('LastExitCode%s+[(]', out) + -- command and last line (indicating zero exit) + matches('LastExitCode%s+ready [$]%s+[(]', out) matches('\n.*%: ready [$]', out) end) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index ec912053b2..a580e88b93 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -18,7 +18,7 @@ describe(':*map', function() it('are not affected by &isident', function() meths.set_var('counter', 0) command('nnoremap <C-x> :let counter+=1<CR>') - meths.set_option('isident', ('%u'):format(('>'):byte())) + meths.set_option_value('isident', ('%u'):format(('>'):byte()), {}) command('nnoremap <C-y> :let counter+=1<CR>') -- &isident used to disable keycode parsing here as well feed('\24\25<C-x><C-y>') @@ -152,7 +152,7 @@ describe('Screen', function() ~ | ~ | ~ | - > | + -- INSERT -- | ]]) end) diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 0a0c7ca410..7522d4a99c 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -1,4 +1,3 @@ -local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') @@ -15,16 +14,19 @@ local sleep = helpers.sleep local meths = helpers.meths local skip = helpers.skip local is_os = helpers.is_os +local mkdir = helpers.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' +if helpers.skip(helpers.is_os('win')) then return end + describe(':mksession', function() local session_file = file_prefix .. '.vim' local tab_dir = file_prefix .. '.d' before_each(function() clear() - lfs.mkdir(tab_dir) + mkdir(tab_dir) end) after_each(function() @@ -79,13 +81,13 @@ describe(':mksession', function() local buf_count = #meths.list_bufs() eq(2, buf_count) - eq('terminal', meths.buf_get_option(0, 'buftype')) + eq('terminal', meths.get_option_value('buftype', {})) test_terminal_session_disabled(2) -- no terminal should be set. As a side effect we end up with a blank buffer - eq('', meths.buf_get_option(meths.list_bufs()[1], 'buftype')) - eq('', meths.buf_get_option(meths.list_bufs()[2], 'buftype')) + eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[1] })) + eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[2] })) end ) @@ -110,7 +112,7 @@ describe(':mksession', function() it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() command('terminal') - eq('terminal', meths.buf_get_option(0, 'buftype')) + eq('terminal', meths.get_option_value('buftype', {})) local buf_count = #meths.list_bufs() eq(1, buf_count) @@ -118,7 +120,7 @@ describe(':mksession', function() test_terminal_session_disabled(1) -- no terminal should be set - eq('', meths.buf_get_option(0, 'buftype')) + eq('', meths.get_option_value('buftype', {})) end) it('restores tab-local working directories', function() @@ -247,7 +249,7 @@ describe(':mksession', function() style = 'minimal', } meths.open_win(buf, false, config) - local cmdheight = meths.get_option('cmdheight') + local cmdheight = meths.get_option_value('cmdheight', {}) command('mksession ' .. session_file) -- Create a new test instance of Nvim. @@ -260,7 +262,7 @@ describe(':mksession', function() -- window was not restored. eq(1, funcs.winnr('$')) -- The command-line height should remain the same as it was. - eq(cmdheight, meths.get_option('cmdheight')) + eq(cmdheight, meths.get_option_value('cmdheight', {})) os.remove(tmpfile) end) diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua index fef8065b2e..f71b826210 100644 --- a/test/functional/ex_cmds/mkview_spec.lua +++ b/test/functional/ex_cmds/mkview_spec.lua @@ -1,4 +1,3 @@ -local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear @@ -7,6 +6,7 @@ local get_pathsep = helpers.get_pathsep local eq = helpers.eq local funcs = helpers.funcs local rmdir = helpers.rmdir +local mkdir = helpers.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec' @@ -17,8 +17,8 @@ describe(':mkview', function() before_each(function() clear() - lfs.mkdir(view_dir) - lfs.mkdir(local_dir) + mkdir(view_dir) + mkdir(local_dir) end) after_each(function() diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 5f87c3cdd9..19611429e0 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -2,6 +2,8 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear +local command = helpers.command +local expect_exit = helpers.expect_exit local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local ok = helpers.ok @@ -19,6 +21,7 @@ describe(':oldfiles', function() before_each(_clear) after_each(function() + expect_exit(command, 'qall!') os.remove(shada_file) end) @@ -42,6 +45,7 @@ describe(':oldfiles', function() | Press ENTER or type command to continue^ | ]]) + feed('<CR>') end) it('can be filtered with :filter', function() @@ -107,6 +111,7 @@ describe(':browse oldfiles', function() end) after_each(function() + expect_exit(command, 'qall!') os.remove(shada_file) end) diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua index 2b92f8d0de..249373a9c4 100644 --- a/test/functional/ex_cmds/profile_spec.lua +++ b/test/functional/ex_cmds/profile_spec.lua @@ -1,5 +1,5 @@ require('os') -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eval = helpers.eval @@ -12,25 +12,24 @@ local read_file = helpers.read_file -- tmpname() also creates the file on POSIX systems. Remove it again. -- We just need the name, ignoring any race conditions. -if lfs.attributes(tempfile, 'uid') then +if luv.fs_stat(tempfile).uid then os.remove(tempfile) end local function assert_file_exists(filepath) - -- Use 2-argument lfs.attributes() so no extra table gets created. - -- We don't really care for the uid. - neq(nil, lfs.attributes(filepath, 'uid')) + neq(nil, luv.fs_stat(filepath).uid) end local function assert_file_exists_not(filepath) - eq(nil, lfs.attributes(filepath, 'uid')) + eq(nil, luv.fs_stat(filepath)) end describe(':profile', function() before_each(helpers.clear) after_each(function() - if lfs.attributes(tempfile, 'uid') ~= nil then + helpers.expect_exit(command, 'qall!') + if luv.fs_stat(tempfile).uid ~= nil then os.remove(tempfile) end end) diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index bf69ada820..62249caa5e 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local neq = helpers.neq local command = helpers.command +local exec_capture = helpers.exec_capture local write_file = helpers.write_file local meths = helpers.meths local clear = helpers.clear @@ -34,7 +35,7 @@ describe('script_get-based command', function() %s %s endif ]])):format(cmd, garbage))) - eq('', meths.exec('messages', true)) + eq('', exec_capture('messages')) if check_neq then neq(0, exc_exec(dedent([[ %s %s @@ -49,7 +50,7 @@ describe('script_get-based command', function() EOF endif ]])):format(cmd, garbage))) - eq('', meths.exec('messages', true)) + eq('', exec_capture('messages')) if check_neq then eq(true, pcall(source, (dedent([[ let g:exc = 0 diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 64c3464be7..24987354a4 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -7,6 +7,7 @@ local meths = helpers.meths local feed = helpers.feed local feed_command = helpers.feed_command local write_file = helpers.write_file +local tmpname = helpers.tmpname local exec = helpers.exec local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua @@ -48,7 +49,7 @@ describe(':source', function() pending("'shellslash' only works on Windows") return end - meths.set_option('shellslash', false) + meths.set_option_value('shellslash', false, {}) mkdir('Xshellslash') write_file([[Xshellslash/Xstack.vim]], [[ @@ -96,12 +97,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', exec_capture('echo a')) + eq("{'k': 'v'}", exec_capture('echo b')) -- 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", exec_capture('echo c')) + eq("0zBEEFCAFE", exec_capture('echo d')) exec('set cpoptions+=C') eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) @@ -124,14 +125,14 @@ describe(':source', function() -- Source the 2nd line only feed('ggjV') feed_command(':source') - eq('3', meths.exec('echo a', true)) + eq('3', exec_capture('echo a')) -- 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', exec_capture('echo a')) + eq("{'K': 'V'}", exec_capture('echo b')) + eq("<SNR>1_C()", exec_capture('echo D()')) -- Source last line only feed_command(':$source') @@ -147,7 +148,7 @@ describe(':source', function() let a = 123 ]] command('source') - eq('123', meths.exec('echo a', true)) + eq('123', exec_capture('echo a')) end) it('multiline heredoc command', function() @@ -157,7 +158,7 @@ describe(':source', function() EOF]]) command('source') - eq('4', meths.exec('echo luaeval("y")', true)) + eq('4', exec_capture('echo luaeval("y")')) end) it('can source lua files', function() @@ -179,56 +180,65 @@ describe(':source', function() os.remove(test_file) end) - it('can source selected region in lua file', function() - local test_file = 'test.lua' - - write_file (test_file, [[ - vim.g.b = 5 - vim.g.b = 6 - vim.g.b = 7 - a = [=[ - "\ a - \ b]=] - ]]) - - command('edit '..test_file) - - feed('ggjV') - feed_command(':source') - eq(6, eval('g:b')) - - feed('GVkk') - feed_command(':source') - eq(' "\\ a\n \\ b', exec_lua('return _G.a')) - - os.remove(test_file) - end) - - it('can source current lua buffer without argument', function() - local test_file = 'test.lua' - - write_file(test_file, [[ - vim.g.c = 10 - vim.g.c = 11 - vim.g.c = 12 - a = [=[ - \ 1 - "\ 2]=] - vim.g.sfile_value = vim.fn.expand('<sfile>') - vim.g.stack_value = vim.fn.expand('<stack>') - vim.g.script_value = vim.fn.expand('<script>') - ]]) - - command('edit '..test_file) - feed_command(':source') - - eq(12, eval('g:c')) - eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) - eq(':source (no file)', meths.get_var('sfile_value')) - eq(':source (no file)', meths.get_var('stack_value')) - eq(':source (no file)', meths.get_var('script_value')) + describe('can source current buffer', function() + local function test_source_lua_curbuf() + it('selected region', function() + insert([[ + vim.g.b = 5 + vim.g.b = 6 + vim.g.b = 7 + a = [=[ + "\ a + \ b]=] + ]]) + feed('dd') + + feed('ggjV') + feed_command(':source') + eq(6, eval('g:b')) + + feed('GVkk') + feed_command(':source') + eq(' "\\ a\n \\ b', exec_lua('return _G.a')) + end) + + it('whole buffer', function() + insert([[ + vim.g.c = 10 + vim.g.c = 11 + vim.g.c = 12 + a = [=[ + \ 1 + "\ 2]=] + vim.g.sfile_value = vim.fn.expand('<sfile>') + vim.g.stack_value = vim.fn.expand('<stack>') + vim.g.script_value = vim.fn.expand('<script>') + ]]) + feed('dd') + + feed_command(':source') + + eq(12, eval('g:c')) + eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) + eq(':source (no file)', meths.get_var('sfile_value')) + eq(':source (no file)', meths.get_var('stack_value')) + eq(':source (no file)', meths.get_var('script_value')) + end) + end - os.remove(test_file) + describe('with ft=lua', function() + before_each(function() + command('setlocal ft=lua') + end) + test_source_lua_curbuf() + end) + + describe('with .lua extension', function() + before_each(function() + command('edit ' .. tmpname() .. '.lua') + end) + test_source_lua_curbuf() + end) end) it("doesn't throw E484 for lua parsing/runtime errors", function() diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index 8eed00c973..436873b464 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -1,6 +1,5 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') local luv = require('luv') local eq, eval, expect, exec = helpers.eq, helpers.eval, helpers.expect, helpers.exec @@ -13,13 +12,19 @@ local nvim_prog = helpers.nvim_prog local ok = helpers.ok local rmdir = helpers.rmdir local new_argv = helpers.new_argv +local new_pipename = helpers.new_pipename local pesc = helpers.pesc local os_kill = helpers.os_kill local set_session = helpers.set_session local spawn = helpers.spawn -local nvim_async = helpers.nvim_async +local async_meths = helpers.async_meths local expect_msg_seq = helpers.expect_msg_seq local pcall_err = helpers.pcall_err +local mkdir = helpers.mkdir +local poke_eventloop = helpers.poke_eventloop +local meths = helpers.meths +local retry = helpers.retry +local write_file = helpers.write_file describe(':recover', function() before_each(clear) @@ -37,40 +42,40 @@ describe(':recover', function() end) -describe(':preserve', function() - local swapdir = lfs.currentdir()..'/Xtest_recover_dir' +describe("preserve and (R)ecover with custom 'directory'", function() + local swapdir = luv.cwd()..'/Xtest_recover_dir' + local testfile = 'Xtest_recover_file1' + -- Put swapdir at the start of the 'directory' list. #1836 + -- Note: `set swapfile` *must* go after `set directory`: otherwise it may + -- attempt to create a swapfile in different directory. + local init = [[ + set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// + set swapfile fileformat=unix undolevels=-1 + ]] + + local nvim0 before_each(function() - clear() + nvim0 = spawn(new_argv()) + set_session(nvim0) rmdir(swapdir) - lfs.mkdir(swapdir) + mkdir(swapdir) end) after_each(function() command('%bwipeout!') rmdir(swapdir) end) - it("saves to custom 'directory' and (R)ecovers #1836", function() - local testfile = 'Xtest_recover_file1' - -- Put swapdir at the start of the 'directory' list. #1836 - -- Note: `set swapfile` *must* go after `set directory`: otherwise it may - -- attempt to create a swapfile in different directory. - local init = [[ - set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// - set swapfile fileformat=unix undolevels=-1 - ]] - + local function setup_swapname() exec(init) command('edit! '..testfile) feed('isometext<esc>') - command('preserve') exec('redir => g:swapname | silent swapname | redir END') + return eval('g:swapname') + end - local swappath1 = eval('g:swapname') - - os_kill(eval('getpid()')) + local function test_recover(swappath1) -- Start another Nvim instance. - local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, - true) + local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true) set_session(nvim2) exec(init) @@ -90,12 +95,41 @@ describe(':preserve', function() -- Verify that :swapname was not truncated (:help 'shortmess'). ok(nil == string.find(swappath1, '%.%.%.')) ok(nil == string.find(swappath2, '%.%.%.')) + end + + it('with :preserve and SIGKILL', function() + local swappath1 = setup_swapname() + command('preserve') + os_kill(eval('getpid()')) + test_recover(swappath1) + end) + + it('closing stdio channel without :preserve #22096', function() + local swappath1 = setup_swapname() + nvim0:close() + test_recover(swappath1) + end) + + it('killing TUI process without :preserve #22096', function() + helpers.skip(helpers.is_os('win')) + local screen0 = Screen.new() + screen0:attach() + local child_server = new_pipename() + funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server}) + screen0:expect({any = pesc('[No Name]')}) -- Wait for the child process to start. + local child_session = helpers.connect(child_server) + set_session(child_session) + local swappath1 = setup_swapname() + set_session(nvim0) + command('call chanclose(&channel)') -- Kill the child process. + screen0:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop. + test_recover(swappath1) end) end) describe('swapfile detection', function() - local swapdir = lfs.currentdir()..'/Xtest_swapdialog_dir' + local swapdir = luv.cwd()..'/Xtest_swapdialog_dir' local nvim0 -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may @@ -108,7 +142,7 @@ describe('swapfile detection', function() nvim0 = spawn(new_argv()) set_session(nvim0) rmdir(swapdir) - lfs.mkdir(swapdir) + mkdir(swapdir) end) after_each(function() set_session(nvim0) @@ -137,6 +171,7 @@ describe('swapfile detection', function() local screen2 = Screen.new(256, 40) screen2:attach() exec(init) + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). -- With shortmess+=F command('set shortmess+=F') @@ -160,7 +195,7 @@ describe('swapfile detection', function() feed('e') -- Chose "Edit" at the swap dialog. screen2:expect(expected_no_dialog) - -- With API (via eval/VimL) call and shortmess+=F + -- With API (via eval/Vimscript) call and shortmess+=F feed(':call nvim_command("edit %")<CR>') screen2:expect{any=[[Found a swap file by the name ".*]] ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} @@ -169,7 +204,7 @@ describe('swapfile detection', function() screen2:expect(expected_no_dialog) -- With API call and shortmess+=F - nvim_async('command', 'edit %') + async_meths.command('edit %') screen2:expect{any=[[Found a swap file by the name ".*]] ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} feed('e') -- Chose "Edit" at the swap dialog. @@ -185,11 +220,29 @@ describe('swapfile detection', function() nvim2:close() end) + it('default SwapExists handler selects "(E)dit" and skips prompt', function() + exec(init) + command('edit Xfile1') + command("put ='some text...'") + command('preserve') -- Make sure the swap file exists. + local nvimpid = funcs.getpid() + + local nvim1 = spawn(new_argv(), true, nil, true) + set_session(nvim1) + local screen = Screen.new(75, 18) + screen:attach() + exec(init) + feed(':edit Xfile1\n') + + screen:expect({ any = ('W325: Ignoring swapfile from Nvim process %d'):format(nvimpid) }) + nvim1:close() + end) + -- oldtest: Test_swap_prompt_splitwin() it('selecting "q" in the attention prompt', function() exec(init) command('edit Xfile1') - command('preserve') -- should help to make sure the swap file exists + command('preserve') -- Make sure the swap file exists. local screen = Screen.new(75, 18) screen:set_default_attr_ids({ @@ -201,7 +254,9 @@ describe('swapfile detection', function() set_session(nvim1) screen:attach() exec(init) + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). feed(':split Xfile1\n') + -- The default SwapExists handler does _not_ skip this prompt. screen:expect({ any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^') }) @@ -233,6 +288,7 @@ describe('swapfile detection', function() set_session(nvim2) screen:attach() exec(init) + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). command('set more') command('au bufadd * let foo_w = wincol()') feed(':e Xfile1<CR>') @@ -266,8 +322,9 @@ describe('swapfile detection', function() nvim2:close() end) - -- oldtest: Test_nocatch_process_still_running() - it('allows deleting swapfile created before boot vim-patch:8.2.2586', function() + --- @param swapexists boolean Enable the default SwapExists handler. + --- @param on_swapfile_running fun(screen: any) Called after swapfile ("STILL RUNNING") prompt. + local function test_swapfile_after_reboot(swapexists, on_swapfile_running) local screen = Screen.new(75, 30) screen:set_default_attr_ids({ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText @@ -277,6 +334,9 @@ describe('swapfile detection', function() screen:attach() exec(init) + if not swapexists then + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). + end command('set nohidden') exec([=[ @@ -313,12 +373,7 @@ describe('swapfile detection', function() os.rename('Xswap', swname) feed(':edit Xswaptest<CR>') - screen:expect({any = table.concat({ - pesc('{2:E325: ATTENTION}'), - 'file name: .*Xswaptest', - 'process ID: %d* %(STILL RUNNING%)', - pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), - }, '.*')}) + on_swapfile_running(screen) feed('e') @@ -330,7 +385,8 @@ describe('swapfile detection', function() ]]) -- pretend that the swapfile was created before boot - lfs.touch(swname, os.time() - luv.uptime() - 10) + local atime = os.time() - luv.uptime() - 10 + luv.fs_utime(swname, atime, atime) feed(':edit Xswaptest<CR>') screen:expect({any = table.concat({ @@ -339,5 +395,112 @@ describe('swapfile detection', function() }, '.*')}) feed('e') + end + + -- oldtest: Test_nocatch_process_still_running() + it('swapfile created before boot vim-patch:8.2.2586', function() + test_swapfile_after_reboot(false, function(screen) + screen:expect({any = table.concat({ + pesc('{2:E325: ATTENTION}'), + 'file name: .*Xswaptest', + 'process ID: %d* %(STILL RUNNING%)', + pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), + }, '.*')}) + end) + end) + + it('swapfile created before boot + default SwapExists handler', function() + test_swapfile_after_reboot(true, function(screen) + screen:expect({ any = 'W325: Ignoring swapfile from Nvim process' }) + end) + end) + +end) + +describe('quitting swapfile dialog on startup stops TUI properly', function() + local swapdir = luv.cwd()..'/Xtest_swapquit_dir' + local testfile = 'Xtest_swapquit_file1' + local otherfile = 'Xtest_swapquit_file2' + -- Put swapdir at the start of the 'directory' list. #1836 + -- Note: `set swapfile` *must* go after `set directory`: otherwise it may + -- attempt to create a swapfile in different directory. + local init_dir = [[set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//]] + local init_set = [[set swapfile fileformat=unix nomodified undolevels=-1 nohidden]] + + before_each(function() + clear({args = {'--cmd', init_dir, '--cmd', init_set}}) + rmdir(swapdir) + mkdir(swapdir) + write_file(testfile, [[ + first + second + third + + ]]) + command('edit! '..testfile) + feed('Gisometext<esc>') + poke_eventloop() + clear() -- Leaves a swap file behind + meths.ui_attach(80, 30, {}) + end) + after_each(function() + rmdir(swapdir) + os.remove(testfile) + os.remove(otherfile) + end) + + it('(Q)uit at first file argument', function() + local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', + '--cmd', init_dir, '--cmd', init_set, + testfile}) + retry(nil, nil, function() + eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', + eval("getline('$')->trim(' ', 2)")) + end) + meths.chan_send(chan, 'q') + retry(nil, nil, function() + eq({'', '[Process exited 1]', ''}, + eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})")) + end) + end) + + it('(A)bort at second file argument with -p', function() + local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', + '--cmd', init_dir, '--cmd', init_set, + '-p', otherfile, testfile}) + retry(nil, nil, function() + eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', + eval("getline('$')->trim(' ', 2)")) + end) + meths.chan_send(chan, 'a') + retry(nil, nil, function() + eq({'', '[Process exited 1]', ''}, + eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})")) + end) + end) + + it('(Q)uit at file opened by -t', function() + write_file(otherfile, ([[ + !_TAG_FILE_ENCODING utf-8 // + first %s /^ \zsfirst$/ + second %s /^ \zssecond$/ + third %s /^ \zsthird$/]]):format(testfile, testfile, testfile)) + local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', + '--cmd', init_dir, '--cmd', init_set, + '--cmd', 'set tags='..otherfile, '-tsecond'}) + retry(nil, nil, function() + eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', + eval("getline('$')->trim(' ', 2)")) + end) + meths.chan_send(chan, 'q') + retry(nil, nil, function() + eq('Press ENTER or type command to continue', + eval("getline('$')->trim(' ', 2)")) + end) + meths.chan_send(chan, '\r') + retry(nil, nil, function() + eq({'', '[Process exited 1]', ''}, + eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})")) + end) end) end) diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua index 10ee02a790..fe13bd7cd2 100644 --- a/test/functional/ex_cmds/trust_spec.lua +++ b/test/functional/ex_cmds/trust_spec.lua @@ -1,9 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) -local Screen = require('test.functional.ui.screen') local eq = helpers.eq local clear = helpers.clear local command = helpers.command +local exec_capture = helpers.exec_capture +local matches = helpers.matches local pathsep = helpers.get_pathsep() local is_os = helpers.is_os local funcs = helpers.funcs @@ -29,147 +30,49 @@ describe(':trust', function() end) it('trust then deny then remove a file using current buffer', function() - local screen = Screen.new(80, 8) - screen:attach() - screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - }) - local cwd = funcs.getcwd() local hash = funcs.sha256(helpers.read_file('test_file')) command('edit test_file') - command('trust') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}| - ]]) + matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++deny') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| - ]]) + matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++remove') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| - ]]) + matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then trust then remove a file using current buffer', function() - local screen = Screen.new(80, 8) - screen:attach() - screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - }) - local cwd = funcs.getcwd() local hash = funcs.sha256(helpers.read_file('test_file')) command('edit test_file') - command('trust ++deny') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| - ]]) + matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}| - ]]) + matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++remove') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| - ]]) + matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then remove a file using file path', function() - local screen = Screen.new(80, 8) - screen:attach() - screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - }) - local cwd = funcs.getcwd() - command('trust ++deny test_file') - screen:expect([[ - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| - ]]) + matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file')) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++remove test_file') - screen:expect([[ - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| - ]]) + matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove test_file')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index 000e746f1c..50077e9e0c 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture local write_file = helpers.write_file local call_viml_function = helpers.meths.call_function -describe('lua :verbose', function() +local function last_set_tests(cmd) local script_location, script_file -- All test cases below use the same nvim instance. setup(function() @@ -18,17 +18,17 @@ describe('lua :verbose', function() script_location = table.concat{current_dir, helpers.get_pathsep(), script_file} write_file(script_file, [[ -vim.api.nvim_set_option('hlsearch', false) +vim.api.nvim_set_option_value('hlsearch', false, {}) vim.bo.expandtab = true 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) + ", {}) vim.api.nvim_command("command Bdelete :bd") vim.api.nvim_create_user_command("TestCommand", ":echo 'Hello'", {}) @@ -46,7 +46,7 @@ endfunction\ let &tw = s:return80()\ ", true) ]]) - exec(':source '..script_file) + exec(cmd .. ' ' .. script_file) end) teardown(function() @@ -106,6 +106,9 @@ test_group FileType end) it('"Last set" for command defined by nvim_command', function() + if cmd == 'luafile' then + pending('nvim_command does not set the script context') + end local result = exec_capture(':verbose command Bdelete') eq(string.format([[ Name Args Address Complete Definition @@ -123,7 +126,7 @@ test_group FileType script_location), result) end) - it('"Last set for function', function() + it('"Last set" for function', function() local result = exec_capture(':verbose function Close_Window') eq(string.format([[ function Close_Window() abort @@ -140,6 +143,14 @@ test_group FileType Last set from %s line 22]], script_location), result) end) +end + +describe('lua :verbose when using :source', function() + last_set_tests('source') +end) + +describe('lua :verbose when using :luafile', function() + last_set_tests('luafile') end) describe('lua verbose:', function() @@ -149,7 +160,7 @@ describe('lua verbose:', function() clear() script_file = 'test_luafile.lua' write_file(script_file, [[ - vim.api.nvim_set_option('hlsearch', false) + vim.api.nvim_set_option_value('hlsearch', false, {}) ]]) exec(':source '..script_file) end) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 1ccd27875e..0b8ce93b09 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local eq, eval, clear, write_file, source, insert = helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.source, helpers.insert @@ -129,18 +129,18 @@ describe(':write', function() eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), pcall_err(command, 'write .')) end - meths.set_option('writeany', true) + meths.set_option_value('writeany', true, {}) -- Message from buf_write eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .')) funcs.mkdir(fname_bak) - meths.set_option('backupdir', '.') - meths.set_option('backup', true) + meths.set_option_value('backupdir', '.', {}) + meths.set_option_value('backup', true, {}) write_file(fname, 'content0') command('edit ' .. fname) funcs.setline(1, 'TTY') eq('Vim(write):E510: Can\'t make backup file (add ! to override)', pcall_err(command, 'write')) - meths.set_option('backup', false) + meths.set_option_value('backup', false, {}) funcs.setfperm(fname, 'r--------') eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', pcall_err(command, 'write')) @@ -153,7 +153,7 @@ describe(':write', function() end write_file(fname_bak, 'TTYX') skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) - lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true) + luv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname) eq('Vim(write):E166: Can\'t open linked file for writing', pcall_err(command, 'write!')) end) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 861a977ea6..7525343891 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local clear = helpers.clear local command, eq, neq, write_file = helpers.command, helpers.eq, helpers.neq, helpers.write_file @@ -21,10 +21,10 @@ describe(':wshada', function() it('creates a shada file', function() -- file should _not_ exist - eq(nil, lfs.attributes(shada_file)) + eq(nil, luv.fs_stat(shada_file)) command('wsh! '..shada_file) -- file _should_ exist - neq(nil, lfs.attributes(shada_file)) + neq(nil, luv.fs_stat(shada_file)) end) it('overwrites existing files', function() @@ -35,7 +35,7 @@ describe(':wshada', function() -- sanity check eq(text, read_file(shada_file)) - neq(nil, lfs.attributes(shada_file)) + neq(nil, luv.fs_stat(shada_file)) command('wsh! '..shada_file) |