aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-02-11 18:25:01 +0800
committerGitHub <noreply@github.com>2023-02-11 18:25:01 +0800
commit7d58de11f49c574a8a305e28e96b9ff810493012 (patch)
treea3fc6cd9cbb6e689d7f1bd1be776f493ee3802b8 /test/functional/ex_cmds
parent4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b (diff)
downloadrneovim-7d58de11f49c574a8a305e28e96b9ff810493012.tar.gz
rneovim-7d58de11f49c574a8a305e28e96b9ff810493012.tar.bz2
rneovim-7d58de11f49c574a8a305e28e96b9ff810493012.zip
fix(rpc)!: preseve files when stdio channel is closed (#22137)
BREAKING CHANGE: Unsaved changes are now preserved rather than discarded when stdio channel is closed.
Diffstat (limited to 'test/functional/ex_cmds')
-rw-r--r--test/functional/ex_cmds/oldfiles_spec.lua5
-rw-r--r--test/functional/ex_cmds/profile_spec.lua1
-rw-r--r--test/functional/ex_cmds/swapfile_preserve_recover_spec.lua63
3 files changed, 53 insertions, 16 deletions
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..bf045a4d1d 100644
--- a/test/functional/ex_cmds/profile_spec.lua
+++ b/test/functional/ex_cmds/profile_spec.lua
@@ -30,6 +30,7 @@ describe(':profile', function()
before_each(helpers.clear)
after_each(function()
+ helpers.expect_exit(command, 'qall!')
if lfs.attributes(tempfile, 'uid') ~= nil then
os.remove(tempfile)
end
diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
index 8eed00c973..ad59025d47 100644
--- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
+++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
@@ -13,6 +13,7 @@ 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
@@ -37,10 +38,21 @@ describe(':recover', function()
end)
-describe(':preserve', function()
+describe("preserve and (R)ecover with custom 'directory'", function()
local swapdir = lfs.currentdir()..'/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 nvim1
before_each(function()
- clear()
+ nvim1 = spawn(new_argv())
+ set_session(nvim1)
rmdir(swapdir)
lfs.mkdir(swapdir)
end)
@@ -49,25 +61,15 @@ describe(':preserve', function()
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)
@@ -90,6 +92,35 @@ 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()
+ nvim1:close()
+ test_recover(swappath1)
+ end)
+
+ it('killing TUI process without :preserve #22096', function()
+ helpers.skip(helpers.is_os('win'))
+ local screen = Screen.new()
+ screen:attach()
+ local child_server = new_pipename()
+ funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server})
+ screen: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(nvim1)
+ command('call chanclose(&channel)') -- Kill the child process.
+ screen:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop.
+ test_recover(swappath1)
end)
end)