diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-09-23 10:13:56 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-09-23 15:58:01 +0200 |
commit | 22c83a4de95dc827048448e28f1df5663e2e5f24 (patch) | |
tree | e3a1cfc1ad8cae88692b40ec5c92420d584456dd | |
parent | c3d24368a13d9d0f0b410e098a89056cb5e83c4f (diff) | |
download | rneovim-22c83a4de95dc827048448e28f1df5663e2e5f24.tar.gz rneovim-22c83a4de95dc827048448e28f1df5663e2e5f24.tar.bz2 rneovim-22c83a4de95dc827048448e28f1df5663e2e5f24.zip |
swapfile: Always show swap dialog (E325)
If swapfile dialog prompts for input, it must be displayed to the user.
fix #8840
fix #9027
-rw-r--r-- | src/nvim/memline.c | 1 | ||||
-rw-r--r-- | test/functional/ex_cmds/recover_spec.lua | 76 | ||||
-rw-r--r-- | test/functional/ex_cmds/swapfile_preserve_recover_spec.lua | 154 | ||||
-rw-r--r-- | test/functional/options/shortmess_spec.lua | 3 |
4 files changed, 155 insertions, 79 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 5602a29f50..ec0238e7c9 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -535,6 +535,7 @@ void ml_open_file(buf_T *buf) void check_need_swap(int newfile) { int old_msg_silent = msg_silent; // might be reset by an E325 message + msg_silent = 0; // If swap dialog prompts for input, user needs to see it! if (curbuf->b_may_swap && (!curbuf->b_p_ro || !newfile)) { ml_open_file(curbuf); diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua deleted file mode 100644 index cb68c29b9a..0000000000 --- a/test/functional/ex_cmds/recover_spec.lua +++ /dev/null @@ -1,76 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') -local feed_command, eq, clear, eval, feed, expect, source = - helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed, - helpers.expect, helpers.source -local command = helpers.command -local ok = helpers.ok -local rmdir = helpers.rmdir - -describe(':recover', function() - before_each(clear) - - it('fails if given a non-existent swapfile', function() - local swapname = 'bogus-swapfile' - feed_command('recover '..swapname) -- This should not segfault. #2117 - eq('E305: No swap file found for '..swapname, eval('v:errmsg')) - end) - -end) - -describe(':preserve', function() - local swapdir = lfs.currentdir()..'/testdir_recover_spec' - before_each(function() - clear() - rmdir(swapdir) - lfs.mkdir(swapdir) - end) - after_each(function() - command('%bwipeout!') - rmdir(swapdir) - end) - - it("saves to custom 'directory' and (R)ecovers (issue #1836)", function() - local testfile = 'testfile_recover_spec' - -- 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 - ]] - - source(init) - command('edit! '..testfile) - feed('isometext<esc>') - command('preserve') - source('redir => g:swapname | silent swapname | redir END') - - local swappath1 = eval('g:swapname') - - --TODO(justinmk): this is an ugly hack to force `helpers` to support - --multiple sessions. - local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, - true) - helpers.set_session(nvim2) - - source(init) - - -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. - command('autocmd SwapExists * let v:swapchoice = "r"') - command('silent edit! '..testfile) - source('redir => g:swapname | silent swapname | redir END') - - 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, '%.%.%.')) - end) - -end) diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua new file mode 100644 index 0000000000..577a26178a --- /dev/null +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -0,0 +1,154 @@ +local Screen = require('test.functional.ui.screen') +local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') +local feed_command, eq, eval, expect, source = + helpers.feed_command, helpers.eq, helpers.eval, helpers.expect, helpers.source +local clear = helpers.clear +local command = helpers.command +local feed = helpers.feed +local nvim_prog = helpers.nvim_prog +local ok = helpers.ok +local rmdir = helpers.rmdir +local set_session = helpers.set_session +local spawn = helpers.spawn + +describe(':recover', function() + before_each(clear) + + it('fails if given a non-existent swapfile', function() + local swapname = 'bogus-swapfile' + feed_command('recover '..swapname) -- This should not segfault. #2117 + eq('E305: No swap file found for '..swapname, eval('v:errmsg')) + end) + +end) + +describe(':preserve', function() + local swapdir = lfs.currentdir()..'/Xtest_recover_dir' + before_each(function() + clear() + rmdir(swapdir) + lfs.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 + ]] + + source(init) + command('edit! '..testfile) + feed('isometext<esc>') + command('preserve') + source('redir => g:swapname | silent swapname | redir END') + + local swappath1 = eval('g:swapname') + + -- Start another Nvim instance. + local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, + true) + set_session(nvim2) + + source(init) + + -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. + command('autocmd SwapExists * let v:swapchoice = "r"') + command('silent edit! '..testfile) + source('redir => g:swapname | silent swapname | redir END') + + 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, '%.%.%.')) + end) + +end) + +describe('swapfile detection', function() + local swapdir = lfs.currentdir()..'/Xtest_swapdialog_dir' + before_each(function() + clear() + rmdir(swapdir) + lfs.mkdir(swapdir) + end) + after_each(function() + command('%bwipeout!') + rmdir(swapdir) + end) + + it('always show swapfile dialog #8840 #9027', function() + local testfile = 'Xtest_swapdialog_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 hidden + ]] + + 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' + + source(init) + command('edit! '..testfile) + feed('isometext<esc>') + command('preserve') + + -- Start another Nvim instance. + local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, + true) + set_session(nvim2) + local screen2 = Screen.new(256, 40) + screen2:attach() + source(init) + + -- 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) + + -- With API (via eval/VimL) 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"]]} + feed('e') -- Chose "Edit" at the swap dialog. + feed('<c-c>') + screen2:expect(expected_no_dialog) + end) +end) diff --git a/test/functional/options/shortmess_spec.lua b/test/functional/options/shortmess_spec.lua index 5d3863ad0b..8ea9a19464 100644 --- a/test/functional/options/shortmess_spec.lua +++ b/test/functional/options/shortmess_spec.lua @@ -1,14 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local command = helpers.command local clear = helpers.clear local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -if helpers.pending_win32(pending) then return end - describe("'shortmess'", function() local screen |