diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-09-24 16:29:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-24 16:29:07 +0800 |
commit | 9637b7dae417f336ca72cfcb201cb37247d794a8 (patch) | |
tree | 62f810d4e4d16e77a41e5cd38de2f1e46ab66d72 /test | |
parent | ac1c23442fd2688f89d75310b8c769e91d81e715 (diff) | |
download | rneovim-9637b7dae417f336ca72cfcb201cb37247d794a8.tar.gz rneovim-9637b7dae417f336ca72cfcb201cb37247d794a8.tar.bz2 rneovim-9637b7dae417f336ca72cfcb201cb37247d794a8.zip |
fix(startup): stop TUI properly when quitting at swap dialog (#25337)
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/ex_cmds/swapfile_preserve_recover_spec.lua | 105 |
1 files changed, 98 insertions, 7 deletions
diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index 206838408f..76c0e77e76 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -21,6 +21,11 @@ local nvim_async = helpers.nvim_async 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 trim = helpers.trim +local write_file = helpers.write_file describe(':recover', function() before_each(clear) @@ -49,10 +54,10 @@ describe("preserve and (R)ecover with custom 'directory'", function() set swapfile fileformat=unix undolevels=-1 ]] - local nvim1 + local nvim0 before_each(function() - nvim1 = spawn(new_argv()) - set_session(nvim1) + nvim0 = spawn(new_argv()) + set_session(nvim0) rmdir(swapdir) mkdir(swapdir) end) @@ -71,8 +76,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() 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) @@ -103,7 +107,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() it('closing stdio channel without :preserve #22096', function() local swappath1 = setup_swapname() - nvim1:close() + nvim0:close() test_recover(swappath1) end) @@ -117,7 +121,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() local child_session = helpers.connect(child_server) set_session(child_session) local swappath1 = setup_swapname() - set_session(nvim1) + set_session(nvim0) 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) @@ -373,3 +377,90 @@ describe('swapfile detection', function() feed('e') 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:', trim(funcs.getline('$'))) + end) + meths.chan_send(chan, 'q') + retry(nil, nil, function() + eq({'', '[Process exited 1]', ''}, { + trim(funcs.getline(1)), trim(funcs.getline(2)), trim(funcs.getline('$')), + }) + 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:', trim(funcs.getline('$'))) + end) + meths.chan_send(chan, 'a') + retry(nil, nil, function() + eq({'', '[Process exited 1]', ''}, { + trim(funcs.getline(1)), trim(funcs.getline(2)), trim(funcs.getline('$')), + }) + 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:', trim(funcs.getline('$'))) + end) + meths.chan_send(chan, 'q') + retry(nil, nil, function() + eq('Press ENTER or type command to continue', trim(funcs.getline('$'))) + end) + meths.chan_send(chan, '\r') + retry(nil, nil, function() + eq({'', '[Process exited 1]', ''}, { + trim(funcs.getline(1)), trim(funcs.getline(2)), trim(funcs.getline('$')), + }) + end) + end) +end) |