win/test: Enable recover_spec.lua

This commit is contained in:
Justin M. Keyes 2017-04-10 19:53:19 +02:00
parent 4a63d9e5f8
commit dab3f86d09

View File

@ -1,12 +1,11 @@
-- Tests for :recover
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local lfs = require('lfs') local lfs = require('lfs')
local feed_command, eq, clear, eval, feed, expect, source = local feed_command, eq, clear, eval, feed, expect, source =
helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed,
helpers.expect, helpers.source helpers.expect, helpers.source
local command = helpers.command
if helpers.pending_win32(pending) then return end local ok = helpers.ok
local rmdir = helpers.rmdir
describe(':recover', function() describe(':recover', function()
before_each(clear) before_each(clear)
@ -23,30 +22,29 @@ describe(':preserve', function()
local swapdir = lfs.currentdir()..'/testdir_recover_spec' local swapdir = lfs.currentdir()..'/testdir_recover_spec'
before_each(function() before_each(function()
clear() clear()
helpers.rmdir(swapdir) rmdir(swapdir)
lfs.mkdir(swapdir) lfs.mkdir(swapdir)
end) end)
after_each(function() after_each(function()
helpers.rmdir(swapdir) command('%bwipeout!')
rmdir(swapdir)
end) end)
it("saves to custom 'directory' and (R)ecovers (issue #1836)", function() it("saves to custom 'directory' and (R)ecovers (issue #1836)", function()
local testfile = 'testfile_recover_spec' 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 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may
-- attempt to create a swapfile in different directory. -- attempt to create a swapfile in different directory.
local init = [[ local init = [[
set directory^=]]..swapdir..[[// set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
set swapfile fileformat=unix undolevels=-1 set swapfile fileformat=unix undolevels=-1
]] ]]
source(init) source(init)
feed_command('set swapfile fileformat=unix undolevels=-1') command('edit! '..testfile)
-- Put swapdir at the start of the 'directory' list. #1836
feed_command('set directory^='..swapdir..'//')
feed_command('edit '..testfile)
feed('isometext<esc>') feed('isometext<esc>')
feed_command('preserve') command('preserve')
source('redir => g:swapname | swapname | redir END') source('redir => g:swapname | silent swapname | redir END')
local swappath1 = eval('g:swapname') local swappath1 = eval('g:swapname')
@ -59,19 +57,20 @@ describe(':preserve', function()
source(init) source(init)
-- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog.
feed_command('autocmd SwapExists * let v:swapchoice = "r"') command('autocmd SwapExists * let v:swapchoice = "r"')
feed_command('silent edit '..testfile) command('silent edit! '..testfile)
source('redir => g:swapname | swapname | redir END') source('redir => g:swapname | silent swapname | redir END')
local swappath2 = eval('g:swapname') local swappath2 = eval('g:swapname')
-- swapfile from session 1 should end in .swp
assert(testfile..'.swp' == string.match(swappath1, '[^%%]+$'))
-- swapfile from session 2 should end in .swo
assert(testfile..'.swo' == string.match(swappath2, '[^%%]+$'))
expect('sometext') 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)
end) end)