2018-09-23 01:13:56 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2022-11-17 05:37:07 -07:00
|
|
|
local luv = require('luv')
|
2022-08-30 18:41:00 -07:00
|
|
|
local eq, eval, expect, exec =
|
|
|
|
helpers.eq, helpers.eval, helpers.expect, helpers.exec
|
2021-09-01 09:42:53 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
2018-09-23 01:13:56 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
|
|
|
local feed = helpers.feed
|
2022-11-17 05:37:07 -07:00
|
|
|
local funcs = helpers.funcs
|
2018-09-23 01:13:56 -07:00
|
|
|
local nvim_prog = helpers.nvim_prog
|
|
|
|
local ok = helpers.ok
|
|
|
|
local rmdir = helpers.rmdir
|
2022-08-30 18:41:00 -07:00
|
|
|
local new_argv = helpers.new_argv
|
2023-02-11 03:25:01 -07:00
|
|
|
local new_pipename = helpers.new_pipename
|
2022-08-30 18:41:00 -07:00
|
|
|
local pesc = helpers.pesc
|
2022-03-23 04:52:50 -07:00
|
|
|
local os_kill = helpers.os_kill
|
2018-09-23 01:13:56 -07:00
|
|
|
local set_session = helpers.set_session
|
|
|
|
local spawn = helpers.spawn
|
2023-09-24 07:03:54 -07:00
|
|
|
local async_meths = helpers.async_meths
|
2019-04-12 17:13:29 -07:00
|
|
|
local expect_msg_seq = helpers.expect_msg_seq
|
2019-09-06 17:17:37 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
2023-04-04 12:59:06 -07:00
|
|
|
local mkdir = helpers.mkdir
|
2023-09-24 01:29:07 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
|
|
|
local meths = helpers.meths
|
|
|
|
local retry = helpers.retry
|
|
|
|
local write_file = helpers.write_file
|
2018-09-23 01:13:56 -07:00
|
|
|
|
|
|
|
describe(':recover', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('fails if given a non-existent swapfile', function()
|
2019-01-14 07:09:47 -07:00
|
|
|
local swapname = 'bogus_swapfile'
|
|
|
|
local swapname2 = 'bogus_swapfile.swp'
|
2019-09-06 17:17:37 -07:00
|
|
|
eq('Vim(recover):E305: No swap file found for '..swapname,
|
|
|
|
pcall_err(command, 'recover '..swapname)) -- Should not segfault. #2117
|
2019-01-14 07:09:47 -07:00
|
|
|
-- Also check filename ending with ".swp". #9504
|
2019-09-06 17:17:37 -07:00
|
|
|
eq('Vim(recover):E306: Cannot open '..swapname2,
|
|
|
|
pcall_err(command, 'recover '..swapname2)) -- Should not segfault. #2117
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2018-09-23 01:13:56 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
2023-02-11 03:25:01 -07:00
|
|
|
describe("preserve and (R)ecover with custom 'directory'", function()
|
2023-04-04 12:59:06 -07:00
|
|
|
local swapdir = luv.cwd()..'/Xtest_recover_dir'
|
2023-02-11 03:25:01 -07:00
|
|
|
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
|
|
|
|
]]
|
|
|
|
|
2023-09-24 01:29:07 -07:00
|
|
|
local nvim0
|
2018-09-23 01:13:56 -07:00
|
|
|
before_each(function()
|
2023-09-24 01:29:07 -07:00
|
|
|
nvim0 = spawn(new_argv())
|
|
|
|
set_session(nvim0)
|
2018-09-23 01:13:56 -07:00
|
|
|
rmdir(swapdir)
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir(swapdir)
|
2018-09-23 01:13:56 -07:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
command('%bwipeout!')
|
|
|
|
rmdir(swapdir)
|
|
|
|
end)
|
|
|
|
|
2023-02-11 03:25:01 -07:00
|
|
|
local function setup_swapname()
|
2022-08-30 18:41:00 -07:00
|
|
|
exec(init)
|
2018-09-23 01:13:56 -07:00
|
|
|
command('edit! '..testfile)
|
|
|
|
feed('isometext<esc>')
|
2022-08-30 18:41:00 -07:00
|
|
|
exec('redir => g:swapname | silent swapname | redir END')
|
2023-02-11 03:25:01 -07:00
|
|
|
return eval('g:swapname')
|
|
|
|
end
|
2018-09-23 01:13:56 -07:00
|
|
|
|
2023-02-11 03:25:01 -07:00
|
|
|
local function test_recover(swappath1)
|
2018-09-23 01:13:56 -07:00
|
|
|
-- Start another Nvim instance.
|
2023-09-24 01:29:07 -07:00
|
|
|
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true)
|
2018-09-23 01:13:56 -07:00
|
|
|
set_session(nvim2)
|
|
|
|
|
2022-08-30 18:41:00 -07:00
|
|
|
exec(init)
|
2018-09-23 01:13:56 -07:00
|
|
|
|
|
|
|
-- Use the "SwapExists" event to choose the (R)ecover choice at the dialog.
|
|
|
|
command('autocmd SwapExists * let v:swapchoice = "r"')
|
|
|
|
command('silent edit! '..testfile)
|
2022-08-30 18:41:00 -07:00
|
|
|
exec('redir => g:swapname | silent swapname | redir END')
|
2018-09-23 01:13:56 -07:00
|
|
|
|
|
|
|
local swappath2 = eval('g:swapname')
|
|
|
|
|
|
|
|
expect('sometext')
|
|
|
|
-- swapfile from session 1 should end in .swp
|
|
|
|
eq(testfile..'.swp', string.match(swappath1, '[^%%]+$'))
|
|
|
|
-- swapfile from session 2 should end in .swo
|
|
|
|
eq(testfile..'.swo', string.match(swappath2, '[^%%]+$'))
|
|
|
|
-- Verify that :swapname was not truncated (:help 'shortmess').
|
|
|
|
ok(nil == string.find(swappath1, '%.%.%.'))
|
|
|
|
ok(nil == string.find(swappath2, '%.%.%.'))
|
2023-02-11 03:25:01 -07:00
|
|
|
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()
|
2023-09-24 01:29:07 -07:00
|
|
|
nvim0:close()
|
2023-02-11 03:25:01 -07:00
|
|
|
test_recover(swappath1)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('killing TUI process without :preserve #22096', function()
|
|
|
|
helpers.skip(helpers.is_os('win'))
|
2023-09-24 07:03:54 -07:00
|
|
|
local screen0 = Screen.new()
|
|
|
|
screen0:attach()
|
2023-02-11 03:25:01 -07:00
|
|
|
local child_server = new_pipename()
|
2023-12-07 17:00:27 -07:00
|
|
|
funcs.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server }, {
|
|
|
|
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }
|
|
|
|
})
|
2023-09-24 07:03:54 -07:00
|
|
|
screen0:expect({any = pesc('[No Name]')}) -- Wait for the child process to start.
|
2023-02-11 03:25:01 -07:00
|
|
|
local child_session = helpers.connect(child_server)
|
|
|
|
set_session(child_session)
|
|
|
|
local swappath1 = setup_swapname()
|
2023-09-24 01:29:07 -07:00
|
|
|
set_session(nvim0)
|
2023-02-11 03:25:01 -07:00
|
|
|
command('call chanclose(&channel)') -- Kill the child process.
|
2023-09-24 07:03:54 -07:00
|
|
|
screen0:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop.
|
2023-02-11 03:25:01 -07:00
|
|
|
test_recover(swappath1)
|
2018-09-23 01:13:56 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('swapfile detection', function()
|
2023-04-04 12:59:06 -07:00
|
|
|
local swapdir = luv.cwd()..'/Xtest_swapdialog_dir'
|
2022-08-30 18:41:00 -07:00
|
|
|
local nvim0
|
|
|
|
-- 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([[\]], [[\\]])..[[//
|
2022-11-17 05:37:07 -07:00
|
|
|
set swapfile fileformat=unix nomodified undolevels=-1 nohidden
|
2022-08-30 18:41:00 -07:00
|
|
|
]]
|
2018-09-23 01:13:56 -07:00
|
|
|
before_each(function()
|
2022-08-30 18:41:00 -07:00
|
|
|
nvim0 = spawn(new_argv())
|
|
|
|
set_session(nvim0)
|
2018-09-23 01:13:56 -07:00
|
|
|
rmdir(swapdir)
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir(swapdir)
|
2018-09-23 01:13:56 -07:00
|
|
|
end)
|
|
|
|
after_each(function()
|
2022-08-30 18:41:00 -07:00
|
|
|
set_session(nvim0)
|
2018-09-23 01:13:56 -07:00
|
|
|
command('%bwipeout!')
|
|
|
|
rmdir(swapdir)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('always show swapfile dialog #8840 #9027', function()
|
|
|
|
local testfile = 'Xtest_swapdialog_file1'
|
|
|
|
|
|
|
|
local expected_no_dialog = '^'..(' '):rep(256)..'|\n'
|
|
|
|
for _=1,37 do
|
|
|
|
expected_no_dialog = expected_no_dialog..'~'..(' '):rep(255)..'|\n'
|
|
|
|
end
|
|
|
|
expected_no_dialog = expected_no_dialog..testfile..(' '):rep(216)..'0,0-1 All|\n'
|
|
|
|
expected_no_dialog = expected_no_dialog..(' '):rep(256)..'|\n'
|
|
|
|
|
2022-08-30 18:41:00 -07:00
|
|
|
exec(init)
|
2018-09-23 01:13:56 -07:00
|
|
|
command('edit! '..testfile)
|
|
|
|
feed('isometext<esc>')
|
|
|
|
command('preserve')
|
|
|
|
|
|
|
|
-- Start another Nvim instance.
|
2022-08-30 18:41:00 -07:00
|
|
|
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true, nil, true)
|
2018-09-23 01:13:56 -07:00
|
|
|
set_session(nvim2)
|
|
|
|
local screen2 = Screen.new(256, 40)
|
|
|
|
screen2:attach()
|
2022-08-30 18:41:00 -07:00
|
|
|
exec(init)
|
2023-10-04 06:31:25 -07:00
|
|
|
command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
|
2018-09-23 01:13:56 -07:00
|
|
|
|
|
|
|
-- With shortmess+=F
|
|
|
|
command('set shortmess+=F')
|
|
|
|
feed(':edit '..testfile..'<CR>')
|
|
|
|
screen2:expect{any=[[E325: ATTENTION.*]]..'\n'..[[Found a swap file by the name ".*]]
|
|
|
|
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
|
|
|
feed('e') -- Chose "Edit" at the swap dialog.
|
|
|
|
screen2:expect(expected_no_dialog)
|
|
|
|
|
|
|
|
-- With :silent and shortmess+=F
|
|
|
|
feed(':silent edit %<CR>')
|
|
|
|
screen2:expect{any=[[Found a swap file by the name ".*]]
|
|
|
|
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
|
|
|
feed('e') -- Chose "Edit" at the swap dialog.
|
|
|
|
screen2:expect(expected_no_dialog)
|
|
|
|
|
|
|
|
-- With :silent! and shortmess+=F
|
|
|
|
feed(':silent! edit %<CR>')
|
|
|
|
screen2:expect{any=[[Found a swap file by the name ".*]]
|
|
|
|
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
|
|
|
feed('e') -- Chose "Edit" at the swap dialog.
|
|
|
|
screen2:expect(expected_no_dialog)
|
|
|
|
|
2023-06-22 04:09:14 -07:00
|
|
|
-- With API (via eval/Vimscript) call and shortmess+=F
|
2018-09-23 01:13:56 -07:00
|
|
|
feed(':call nvim_command("edit %")<CR>')
|
|
|
|
screen2:expect{any=[[Found a swap file by the name ".*]]
|
|
|
|
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
|
|
|
feed('e') -- Chose "Edit" at the swap dialog.
|
|
|
|
feed('<c-c>')
|
|
|
|
screen2:expect(expected_no_dialog)
|
2018-11-30 18:41:31 -07:00
|
|
|
|
|
|
|
-- With API call and shortmess+=F
|
2023-09-24 07:03:54 -07:00
|
|
|
async_meths.command('edit %')
|
2018-11-30 18:41:31 -07:00
|
|
|
screen2:expect{any=[[Found a swap file by the name ".*]]
|
|
|
|
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
|
|
|
feed('e') -- Chose "Edit" at the swap dialog.
|
2019-04-12 17:13:29 -07:00
|
|
|
expect_msg_seq({
|
|
|
|
ignore={'redraw'},
|
|
|
|
seqs={
|
|
|
|
{ {'notification', 'nvim_error_event', {0, 'Vim(edit):E325: ATTENTION'}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
feed('<cr>')
|
2022-08-30 18:41:00 -07:00
|
|
|
|
|
|
|
nvim2:close()
|
|
|
|
end)
|
|
|
|
|
2023-10-04 06:31:25 -07:00
|
|
|
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)
|
|
|
|
|
2022-08-30 18:41:00 -07:00
|
|
|
-- oldtest: Test_swap_prompt_splitwin()
|
|
|
|
it('selecting "q" in the attention prompt', function()
|
|
|
|
exec(init)
|
|
|
|
command('edit Xfile1')
|
2023-10-04 06:31:25 -07:00
|
|
|
command('preserve') -- Make sure the swap file exists.
|
2022-08-30 18:41:00 -07:00
|
|
|
|
|
|
|
local screen = Screen.new(75, 18)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
|
|
|
|
[1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
|
|
|
|
})
|
|
|
|
|
|
|
|
local nvim1 = spawn(new_argv(), true, nil, true)
|
|
|
|
set_session(nvim1)
|
|
|
|
screen:attach()
|
|
|
|
exec(init)
|
2023-10-04 06:31:25 -07:00
|
|
|
command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
|
2022-08-30 18:41:00 -07:00
|
|
|
feed(':split Xfile1\n')
|
2023-10-04 06:31:25 -07:00
|
|
|
-- The default SwapExists handler does _not_ skip this prompt.
|
2022-08-30 18:41:00 -07:00
|
|
|
screen:expect({
|
|
|
|
any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^')
|
|
|
|
})
|
|
|
|
feed('q')
|
|
|
|
feed(':<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{0:~ }|*16
|
2022-08-30 18:41:00 -07:00
|
|
|
: |
|
|
|
|
]])
|
|
|
|
nvim1:close()
|
|
|
|
|
|
|
|
local nvim2 = spawn(new_argv(), true, nil, true)
|
|
|
|
set_session(nvim2)
|
|
|
|
screen:attach()
|
|
|
|
exec(init)
|
2023-10-04 06:31:25 -07:00
|
|
|
command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
|
2022-08-30 18:41:00 -07:00
|
|
|
command('set more')
|
|
|
|
command('au bufadd * let foo_w = wincol()')
|
|
|
|
feed(':e Xfile1<CR>')
|
|
|
|
screen:expect({any = pesc('{1:-- More --}^')})
|
|
|
|
feed('<Space>')
|
|
|
|
screen:expect({
|
|
|
|
any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^')
|
|
|
|
})
|
|
|
|
feed('q')
|
|
|
|
command([[echo 'hello']])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{0:~ }|*16
|
2022-08-30 18:41:00 -07:00
|
|
|
hello |
|
|
|
|
]])
|
|
|
|
nvim2:close()
|
2018-09-23 01:13:56 -07:00
|
|
|
end)
|
2022-11-17 05:37:07 -07:00
|
|
|
|
2023-10-04 06:31:25 -07:00
|
|
|
--- @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)
|
2022-11-17 05:37:07 -07:00
|
|
|
local screen = Screen.new(75, 30)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
|
|
|
|
[1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
|
|
|
|
[2] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg
|
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
|
|
|
|
exec(init)
|
2023-10-04 06:31:25 -07:00
|
|
|
if not swapexists then
|
|
|
|
command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
|
|
|
|
end
|
2022-11-17 05:37:07 -07:00
|
|
|
command('set nohidden')
|
|
|
|
|
|
|
|
exec([=[
|
|
|
|
" Make a copy of the current swap file to "Xswap".
|
|
|
|
" Return the name of the swap file.
|
|
|
|
func CopySwapfile()
|
|
|
|
preserve
|
|
|
|
" get the name of the swap file
|
|
|
|
let swname = split(execute("swapname"))[0]
|
|
|
|
let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '')
|
|
|
|
" make a copy of the swap file in Xswap
|
|
|
|
set binary
|
|
|
|
exe 'sp ' . fnameescape(swname)
|
|
|
|
w! Xswap
|
|
|
|
set nobinary
|
|
|
|
return swname
|
|
|
|
endfunc
|
|
|
|
]=])
|
|
|
|
|
|
|
|
-- Edit a file and grab its swapfile.
|
|
|
|
exec([[
|
|
|
|
edit Xswaptest
|
|
|
|
call setline(1, ['a', 'b', 'c'])
|
|
|
|
]])
|
|
|
|
local swname = funcs.CopySwapfile()
|
|
|
|
|
|
|
|
-- Forget we edited this file
|
|
|
|
exec([[
|
|
|
|
new
|
|
|
|
only!
|
|
|
|
bwipe! Xswaptest
|
|
|
|
]])
|
|
|
|
|
|
|
|
os.rename('Xswap', swname)
|
|
|
|
|
|
|
|
feed(':edit Xswaptest<CR>')
|
2023-10-04 06:31:25 -07:00
|
|
|
on_swapfile_running(screen)
|
2022-11-17 05:37:07 -07:00
|
|
|
|
|
|
|
feed('e')
|
|
|
|
|
|
|
|
-- Forget we edited this file
|
|
|
|
exec([[
|
|
|
|
new
|
|
|
|
only!
|
|
|
|
bwipe! Xswaptest
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- pretend that the swapfile was created before boot
|
2023-04-04 12:59:06 -07:00
|
|
|
local atime = os.time() - luv.uptime() - 10
|
|
|
|
luv.fs_utime(swname, atime, atime)
|
2022-11-17 05:37:07 -07:00
|
|
|
|
|
|
|
feed(':edit Xswaptest<CR>')
|
|
|
|
screen:expect({any = table.concat({
|
|
|
|
pesc('{2:E325: ATTENTION}'),
|
|
|
|
pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: }^'),
|
|
|
|
}, '.*')})
|
|
|
|
|
|
|
|
feed('e')
|
2023-10-04 06:31:25 -07:00
|
|
|
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)
|
2022-11-17 05:37:07 -07:00
|
|
|
end)
|
2023-10-04 06:31:25 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-09-23 01:13:56 -07:00
|
|
|
end)
|
2023-09-24 01:29:07 -07:00
|
|
|
|
|
|
|
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,
|
2023-12-07 17:00:27 -07:00
|
|
|
testfile}, {
|
|
|
|
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }
|
|
|
|
})
|
2023-09-24 01:29:07 -07:00
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
|
|
|
|
eval("getline('$')->trim(' ', 2)"))
|
2023-09-24 01:29:07 -07:00
|
|
|
end)
|
|
|
|
meths.chan_send(chan, 'q')
|
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq({'', '[Process exited 1]', ''},
|
|
|
|
eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
|
2023-09-24 01:29:07 -07:00
|
|
|
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,
|
2023-12-07 17:00:27 -07:00
|
|
|
'-p', otherfile, testfile}, {
|
|
|
|
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }
|
|
|
|
})
|
2023-09-24 01:29:07 -07:00
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
|
|
|
|
eval("getline('$')->trim(' ', 2)"))
|
2023-09-24 01:29:07 -07:00
|
|
|
end)
|
|
|
|
meths.chan_send(chan, 'a')
|
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq({'', '[Process exited 1]', ''},
|
|
|
|
eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
|
2023-09-24 01:29:07 -07:00
|
|
|
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,
|
2023-12-07 17:00:27 -07:00
|
|
|
'--cmd', 'set tags='..otherfile, '-tsecond'}, {
|
|
|
|
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }
|
|
|
|
})
|
2023-09-24 01:29:07 -07:00
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
|
|
|
|
eval("getline('$')->trim(' ', 2)"))
|
2023-09-24 01:29:07 -07:00
|
|
|
end)
|
|
|
|
meths.chan_send(chan, 'q')
|
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq('Press ENTER or type command to continue',
|
|
|
|
eval("getline('$')->trim(' ', 2)"))
|
2023-09-24 01:29:07 -07:00
|
|
|
end)
|
|
|
|
meths.chan_send(chan, '\r')
|
|
|
|
retry(nil, nil, function()
|
2023-09-24 07:03:54 -07:00
|
|
|
eq({'', '[Process exited 1]', ''},
|
|
|
|
eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
|
2023-09-24 01:29:07 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|