2017-06-06 04:02:48 -07:00
|
|
|
local lfs = require('lfs')
|
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
|
|
|
local get_pathsep = helpers.get_pathsep
|
|
|
|
local eq = helpers.eq
|
2022-01-29 07:08:44 -07:00
|
|
|
local neq = helpers.neq
|
2017-06-06 04:02:48 -07:00
|
|
|
local funcs = helpers.funcs
|
2020-01-26 01:24:42 -07:00
|
|
|
local matches = helpers.matches
|
|
|
|
local pesc = helpers.pesc
|
2018-01-31 19:12:37 -07:00
|
|
|
local rmdir = helpers.rmdir
|
2022-05-18 01:07:16 -07:00
|
|
|
local sleep = helpers.sleep
|
2017-06-06 04:02:48 -07:00
|
|
|
|
|
|
|
local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec'
|
|
|
|
|
|
|
|
describe(':mksession', function()
|
|
|
|
local session_file = file_prefix .. '.vim'
|
|
|
|
local tab_dir = file_prefix .. '.d'
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
lfs.mkdir(tab_dir)
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
os.remove(session_file)
|
2018-01-31 19:12:37 -07:00
|
|
|
rmdir(tab_dir)
|
2017-06-06 04:02:48 -07:00
|
|
|
end)
|
|
|
|
|
2020-01-26 03:43:12 -07:00
|
|
|
it('restores same :terminal buf in splits', function()
|
|
|
|
-- If the same :terminal is displayed in multiple windows, :mksession
|
|
|
|
-- should restore it as such.
|
|
|
|
|
2022-01-29 07:08:44 -07:00
|
|
|
-- Create three windows: first two from top show same terminal, third -
|
|
|
|
-- another one (created earlier).
|
2020-01-26 03:43:12 -07:00
|
|
|
command('terminal')
|
|
|
|
command('split')
|
|
|
|
command('terminal')
|
|
|
|
command('split')
|
|
|
|
command('mksession '..session_file)
|
|
|
|
|
|
|
|
-- Create a new test instance of Nvim.
|
|
|
|
command('qall!')
|
|
|
|
clear()
|
|
|
|
-- Restore session.
|
|
|
|
command('source '..session_file)
|
|
|
|
|
2022-01-29 07:08:44 -07:00
|
|
|
eq(funcs.winbufnr(1), funcs.winbufnr(2))
|
|
|
|
neq(funcs.winbufnr(1), funcs.winbufnr(3))
|
2020-01-26 03:43:12 -07:00
|
|
|
end)
|
|
|
|
|
2017-06-06 04:02:48 -07:00
|
|
|
it('restores tab-local working directories', function()
|
|
|
|
local tmpfile_base = file_prefix .. '-tmpfile'
|
|
|
|
local cwd_dir = funcs.getcwd()
|
|
|
|
|
|
|
|
-- :mksession does not save empty tabs, so create some buffers.
|
|
|
|
command('edit ' .. tmpfile_base .. '1')
|
|
|
|
command('tabnew')
|
|
|
|
command('edit ' .. tmpfile_base .. '2')
|
|
|
|
command('tcd ' .. tab_dir)
|
|
|
|
command('tabfirst')
|
|
|
|
command('mksession ' .. session_file)
|
|
|
|
|
|
|
|
-- Create a new test instance of Nvim.
|
|
|
|
clear()
|
|
|
|
|
|
|
|
command('source ' .. session_file)
|
|
|
|
-- First tab should have the original working directory.
|
|
|
|
command('tabnext 1')
|
|
|
|
eq(cwd_dir, funcs.getcwd())
|
|
|
|
-- Second tab should have the tab-local working directory.
|
|
|
|
command('tabnext 2')
|
|
|
|
eq(cwd_dir .. get_pathsep() .. tab_dir, funcs.getcwd())
|
|
|
|
end)
|
2019-03-21 03:53:38 -07:00
|
|
|
|
2020-01-26 01:24:42 -07:00
|
|
|
it('restores buffers with tab-local CWD', function()
|
2019-03-21 03:53:38 -07:00
|
|
|
local tmpfile_base = file_prefix .. '-tmpfile'
|
|
|
|
local cwd_dir = funcs.getcwd()
|
|
|
|
local session_path = cwd_dir .. get_pathsep() .. session_file
|
|
|
|
|
|
|
|
command('edit ' .. tmpfile_base .. '1')
|
|
|
|
command('tcd ' .. tab_dir)
|
|
|
|
command('tabnew')
|
|
|
|
command('edit ' .. cwd_dir .. get_pathsep() .. tmpfile_base .. '2')
|
|
|
|
command('tabfirst')
|
|
|
|
command('mksession ' .. session_path)
|
|
|
|
|
|
|
|
-- Create a new test instance of Nvim.
|
|
|
|
clear()
|
|
|
|
|
|
|
|
-- Use :silent to avoid press-enter prompt due to long path
|
|
|
|
command('silent source ' .. session_path)
|
|
|
|
command('tabnext 1')
|
|
|
|
eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', funcs.expand('%:p'))
|
|
|
|
command('tabnext 2')
|
2022-01-29 07:08:44 -07:00
|
|
|
eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', funcs.expand('%:p'))
|
2019-03-21 03:53:38 -07:00
|
|
|
end)
|
2020-01-26 01:24:42 -07:00
|
|
|
|
|
|
|
it('restores CWD for :terminal buffers #11288', function()
|
|
|
|
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
|
2020-01-26 15:26:01 -07:00
|
|
|
cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes.
|
|
|
|
local session_path = cwd_dir..'/'..session_file
|
2020-01-26 01:24:42 -07:00
|
|
|
|
|
|
|
command('cd '..tab_dir)
|
2022-05-18 01:07:16 -07:00
|
|
|
command('terminal')
|
2020-01-26 01:24:42 -07:00
|
|
|
command('cd '..cwd_dir)
|
|
|
|
command('mksession '..session_path)
|
2022-05-18 01:07:16 -07:00
|
|
|
command('bd!')
|
|
|
|
sleep(100) -- Make sure the process exits.
|
2020-01-26 01:24:42 -07:00
|
|
|
command('qall!')
|
|
|
|
|
|
|
|
-- Create a new test instance of Nvim.
|
|
|
|
clear()
|
|
|
|
command('silent source '..session_path)
|
|
|
|
|
2020-01-26 15:26:01 -07:00
|
|
|
local expected_cwd = cwd_dir..'/'..tab_dir
|
2020-01-26 01:24:42 -07:00
|
|
|
matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%'))
|
2022-05-18 01:07:16 -07:00
|
|
|
command('bd!')
|
|
|
|
sleep(100) -- Make sure the process exits.
|
2020-01-26 01:24:42 -07:00
|
|
|
end)
|
2017-06-06 04:02:48 -07:00
|
|
|
end)
|