2018-04-22 19:43:00 -07:00
|
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
|
|
local clear = helpers.clear
|
|
|
|
|
local command = helpers.command
|
|
|
|
|
local eq = helpers.eq
|
|
|
|
|
local feed = helpers.feed
|
|
|
|
|
local funcs = helpers.funcs
|
|
|
|
|
local nvim_prog = helpers.nvim_prog
|
2018-04-23 15:27:09 -07:00
|
|
|
|
local request = helpers.request
|
|
|
|
|
local retry = helpers.retry
|
2018-04-22 19:43:00 -07:00
|
|
|
|
local rmdir = helpers.rmdir
|
2019-11-18 00:38:27 -07:00
|
|
|
|
local mkdir = helpers.mkdir
|
2018-04-22 19:43:00 -07:00
|
|
|
|
local sleep = helpers.sleep
|
2019-03-23 16:21:26 -07:00
|
|
|
|
local read_file = helpers.read_file
|
2019-03-30 10:14:20 -07:00
|
|
|
|
local trim = helpers.trim
|
2019-11-18 00:38:27 -07:00
|
|
|
|
local currentdir = helpers.funcs.getcwd
|
|
|
|
|
local iswin = helpers.iswin
|
2021-11-23 21:07:47 -07:00
|
|
|
|
local assert_alive = helpers.assert_alive
|
2022-06-08 14:22:50 -07:00
|
|
|
|
local expect_exit = helpers.expect_exit
|
2018-04-22 19:43:00 -07:00
|
|
|
|
|
|
|
|
|
describe('fileio', function()
|
|
|
|
|
before_each(function()
|
|
|
|
|
end)
|
|
|
|
|
after_each(function()
|
2022-06-08 14:22:50 -07:00
|
|
|
|
expect_exit(command, ':qall!')
|
2018-04-22 19:43:00 -07:00
|
|
|
|
os.remove('Xtest_startup_shada')
|
|
|
|
|
os.remove('Xtest_startup_file1')
|
2019-03-23 16:21:26 -07:00
|
|
|
|
os.remove('Xtest_startup_file1~')
|
2018-04-22 19:43:00 -07:00
|
|
|
|
os.remove('Xtest_startup_file2')
|
2019-07-23 11:56:27 -07:00
|
|
|
|
os.remove('Xtest_тест.md')
|
2021-11-23 21:07:47 -07:00
|
|
|
|
os.remove('Xtest-u8-int-max')
|
2018-04-22 19:43:00 -07:00
|
|
|
|
rmdir('Xtest_startup_swapdir')
|
2019-11-18 00:38:27 -07:00
|
|
|
|
rmdir('Xtest_backupdir')
|
2018-04-22 19:43:00 -07:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('fsync() codepaths #8304', function()
|
|
|
|
|
clear({ args={ '-i', 'Xtest_startup_shada',
|
|
|
|
|
'--cmd', 'set directory=Xtest_startup_swapdir' } })
|
|
|
|
|
|
|
|
|
|
-- These cases ALWAYS force fsync (regardless of 'fsync' option):
|
|
|
|
|
|
|
|
|
|
-- 1. Idle (CursorHold) with modified buffers (+ 'swapfile').
|
|
|
|
|
command('write Xtest_startup_file1')
|
|
|
|
|
feed('ifoo<esc>h')
|
2018-04-23 15:27:09 -07:00
|
|
|
|
command('write')
|
|
|
|
|
eq(0, request('nvim__stats').fsync) -- 'nofsync' is the default.
|
|
|
|
|
command('set swapfile')
|
|
|
|
|
command('set updatetime=1')
|
|
|
|
|
feed('izub<esc>h') -- File is 'modified'.
|
|
|
|
|
sleep(3) -- Allow 'updatetime' to expire.
|
|
|
|
|
retry(3, nil, function()
|
|
|
|
|
eq(1, request('nvim__stats').fsync)
|
|
|
|
|
end)
|
|
|
|
|
command('set updatetime=9999')
|
2018-04-22 19:43:00 -07:00
|
|
|
|
|
|
|
|
|
-- 2. Exit caused by deadly signal (+ 'swapfile').
|
|
|
|
|
local j = funcs.jobstart({ nvim_prog, '-u', 'NONE', '-i',
|
|
|
|
|
'Xtest_startup_shada', '--headless',
|
|
|
|
|
'-c', 'set swapfile',
|
|
|
|
|
'-c', 'write Xtest_startup_file2',
|
|
|
|
|
'-c', 'put =localtime()', })
|
|
|
|
|
sleep(10) -- Let Nvim start.
|
|
|
|
|
funcs.jobstop(j) -- Send deadly signal.
|
|
|
|
|
|
|
|
|
|
-- 3. SIGPWR signal.
|
|
|
|
|
-- ??
|
|
|
|
|
|
|
|
|
|
-- 4. Explicit :preserve command.
|
|
|
|
|
command('preserve')
|
2018-04-23 15:27:09 -07:00
|
|
|
|
eq(2, request('nvim__stats').fsync)
|
2018-04-22 19:43:00 -07:00
|
|
|
|
|
|
|
|
|
-- 5. Enable 'fsync' option, write file.
|
|
|
|
|
command('set fsync')
|
|
|
|
|
feed('ibaz<esc>h')
|
|
|
|
|
command('write')
|
2018-04-23 15:27:09 -07:00
|
|
|
|
eq(4, request('nvim__stats').fsync)
|
2018-04-22 19:43:00 -07:00
|
|
|
|
end)
|
2019-03-23 16:21:26 -07:00
|
|
|
|
|
2019-05-20 13:33:19 -07:00
|
|
|
|
it('backup #9709', function()
|
2019-03-23 16:21:26 -07:00
|
|
|
|
clear({ args={ '-i', 'Xtest_startup_shada',
|
|
|
|
|
'--cmd', 'set directory=Xtest_startup_swapdir' } })
|
|
|
|
|
|
|
|
|
|
command('write Xtest_startup_file1')
|
|
|
|
|
feed('ifoo<esc>')
|
|
|
|
|
command('set backup')
|
|
|
|
|
command('set backupcopy=yes')
|
|
|
|
|
command('write')
|
|
|
|
|
feed('Abar<esc>')
|
|
|
|
|
command('write')
|
|
|
|
|
|
2019-03-30 10:14:20 -07:00
|
|
|
|
local foobar_contents = trim(read_file('Xtest_startup_file1'))
|
|
|
|
|
local bar_contents = trim(read_file('Xtest_startup_file1~'))
|
2019-03-23 16:21:26 -07:00
|
|
|
|
|
2019-03-30 10:14:20 -07:00
|
|
|
|
eq('foobar', foobar_contents);
|
|
|
|
|
eq('foo', bar_contents);
|
2019-07-23 11:56:27 -07:00
|
|
|
|
end)
|
2019-03-23 16:21:26 -07:00
|
|
|
|
|
2019-11-18 00:38:27 -07:00
|
|
|
|
it('backup with full path #11214', function()
|
|
|
|
|
clear()
|
|
|
|
|
mkdir('Xtest_backupdir')
|
|
|
|
|
command('set backup')
|
|
|
|
|
command('set backupdir=Xtest_backupdir//')
|
|
|
|
|
command('write Xtest_startup_file1')
|
|
|
|
|
feed('ifoo<esc>')
|
|
|
|
|
command('write')
|
|
|
|
|
feed('Abar<esc>')
|
|
|
|
|
command('write')
|
|
|
|
|
|
|
|
|
|
-- Backup filename = fullpath, separators replaced with "%".
|
|
|
|
|
local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1',
|
|
|
|
|
iswin() and '[:/\\]' or '/', '%%') .. '~'
|
|
|
|
|
local foo_contents = trim(read_file('Xtest_backupdir/'..backup_file_name))
|
|
|
|
|
local foobar_contents = trim(read_file('Xtest_startup_file1'))
|
|
|
|
|
|
|
|
|
|
eq('foobar', foobar_contents);
|
|
|
|
|
eq('foo', foo_contents);
|
|
|
|
|
end)
|
|
|
|
|
|
2019-07-23 11:56:27 -07:00
|
|
|
|
it('readfile() on multibyte filename #10586', function()
|
|
|
|
|
clear()
|
|
|
|
|
local text = {
|
|
|
|
|
'line1',
|
|
|
|
|
' ...line2... ',
|
|
|
|
|
'',
|
|
|
|
|
'line3!',
|
|
|
|
|
'тест yay тест.',
|
|
|
|
|
'',
|
|
|
|
|
}
|
|
|
|
|
local fname = 'Xtest_тест.md'
|
|
|
|
|
funcs.writefile(text, fname, 's')
|
|
|
|
|
table.insert(text, '')
|
|
|
|
|
eq(text, funcs.readfile(fname, 'b'))
|
2019-03-23 16:21:26 -07:00
|
|
|
|
end)
|
2021-11-23 21:07:47 -07:00
|
|
|
|
it('read invalid u8 over INT_MAX doesn\'t segfault', function()
|
|
|
|
|
clear()
|
|
|
|
|
command('call writefile(0zFFFFFFFF, "Xtest-u8-int-max")')
|
|
|
|
|
-- This should not segfault
|
|
|
|
|
command('edit ++enc=utf32 Xtest-u8-int-max')
|
|
|
|
|
assert_alive()
|
|
|
|
|
end)
|
2018-04-22 19:43:00 -07:00
|
|
|
|
end)
|
|
|
|
|
|