aboutsummaryrefslogtreecommitdiff
path: root/test/functional/core/fileio_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:29 +0100
commit04f2f864e270e772c6326cefdf24947f0130e492 (patch)
tree46f83f909b888a66c741032ab955afc6eab84292 /test/functional/core/fileio_spec.lua
parent59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff)
downloadrneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip
refactor: format test/*
Diffstat (limited to 'test/functional/core/fileio_spec.lua')
-rw-r--r--test/functional/core/fileio_spec.lua142
1 files changed, 79 insertions, 63 deletions
diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua
index 5ae468e560..1b9a97648c 100644
--- a/test/functional/core/fileio_spec.lua
+++ b/test/functional/core/fileio_spec.lua
@@ -34,8 +34,7 @@ local spawn = helpers.spawn
local set_session = helpers.set_session
describe('fileio', function()
- before_each(function()
- end)
+ before_each(function() end)
after_each(function()
check_close()
os.remove('Xtest_startup_shada')
@@ -51,25 +50,25 @@ describe('fileio', function()
rmdir('Xtest_backupdir with spaces')
end)
- local args = { nvim_prog, '--clean', '--cmd', 'set nofsync directory=Xtest_startup_swapdir', }
+ local args = { nvim_prog, '--clean', '--cmd', 'set nofsync directory=Xtest_startup_swapdir' }
--- Starts a new nvim session and returns an attached screen.
local function startup(extra_args)
extra_args = extra_args or {}
- local argv = vim.tbl_flatten({args, '--embed', extra_args})
+ local argv = vim.tbl_flatten({ args, '--embed', extra_args })
local screen_nvim = spawn(argv)
set_session(screen_nvim)
local screen = Screen.new(70, 10)
screen:attach()
screen:set_default_attr_ids({
- [1] = {foreground = Screen.colors.NvimDarkGrey4};
- [2] = {background = Screen.colors.NvimDarkGrey1, foreground = Screen.colors.NvimLightGrey3};
- [3] = {foreground = Screen.colors.NvimLightCyan};
+ [1] = { foreground = Screen.colors.NvimDarkGrey4 },
+ [2] = { background = Screen.colors.NvimDarkGrey1, foreground = Screen.colors.NvimLightGrey3 },
+ [3] = { foreground = Screen.colors.NvimLightCyan },
})
return screen
end
it("fsync() with 'nofsync' #8304", function()
- clear({ args={ '--cmd', 'set nofsync directory=Xtest_startup_swapdir', } })
+ clear({ args = { '--cmd', 'set nofsync directory=Xtest_startup_swapdir' } })
-- These cases ALWAYS force fsync (regardless of 'fsync' option):
@@ -80,8 +79,8 @@ describe('fileio', function()
eq(0, request('nvim__stats').fsync)
command('set swapfile')
command('set updatetime=1')
- feed('Azub<esc>h') -- File is 'modified'.
- sleep(3) -- Allow 'updatetime' to expire.
+ feed('Azub<esc>h') -- File is 'modified'.
+ sleep(3) -- Allow 'updatetime' to expire.
retry(3, nil, function()
eq(1, request('nvim__stats').fsync)
end)
@@ -101,21 +100,26 @@ describe('fileio', function()
eq('foozubbaz', trim(read_file('Xtest_startup_file1')))
-- 4. Exit caused by deadly signal (+ 'swapfile').
- local j = funcs.jobstart(vim.tbl_flatten({args, '--embed'}), {rpc=true})
- funcs.rpcrequest(j, 'nvim_exec2', [[
+ local j = funcs.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true })
+ funcs.rpcrequest(
+ j,
+ 'nvim_exec2',
+ [[
set nofsync directory=Xtest_startup_swapdir
edit Xtest_startup_file2
write
put ='fsyncd text'
- ]], {})
+ ]],
+ {}
+ )
eq('Xtest_startup_swapdir', funcs.rpcrequest(j, 'nvim_eval', '&directory'))
- funcs.jobstop(j) -- Send deadly signal.
+ funcs.jobstop(j) -- Send deadly signal.
local screen = startup()
feed(':recover Xtest_startup_file2<cr>')
- screen:expect({any = [[Using swap file "Xtest_startup_swapdir[/\]Xtest_startup_file2%.swp"]]})
+ screen:expect({ any = [[Using swap file "Xtest_startup_swapdir[/\]Xtest_startup_file2%.swp"]] })
feed('<cr>')
- screen:expect({any = 'fsyncd text'})
+ screen:expect({ any = 'fsyncd text' })
-- 5. SIGPWR signal.
-- oldtest: Test_signal_PWR()
@@ -123,8 +127,14 @@ describe('fileio', function()
it('backup #9709', function()
skip(is_ci('cirrus'))
- clear({ args={ '-i', 'Xtest_startup_shada',
- '--cmd', 'set directory=Xtest_startup_swapdir' } })
+ clear({
+ args = {
+ '-i',
+ 'Xtest_startup_shada',
+ '--cmd',
+ 'set directory=Xtest_startup_swapdir',
+ },
+ })
command('write Xtest_startup_file1')
feed('ifoo<esc>')
@@ -137,8 +147,8 @@ describe('fileio', function()
local foobar_contents = trim(read_file('Xtest_startup_file1'))
local bar_contents = trim(read_file('Xtest_startup_file1~'))
- eq('foobar', foobar_contents);
- eq('foo', bar_contents);
+ eq('foobar', foobar_contents)
+ eq('foo', bar_contents)
end)
it('backup with full path #11214', function()
@@ -154,13 +164,16 @@ describe('fileio', function()
command('write')
-- Backup filename = fullpath, separators replaced with "%".
- local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1',
- is_os('win') and '[:/\\]' or '/', '%%') .. '~'
- local foo_contents = trim(read_file('Xtest_backupdir/'..backup_file_name))
+ local backup_file_name = string.gsub(
+ currentdir() .. '/Xtest_startup_file1',
+ is_os('win') 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);
+ eq('foobar', foobar_contents)
+ eq('foo', foo_contents)
end)
it('backup with full path with spaces', function()
@@ -176,13 +189,16 @@ describe('fileio', function()
command('write')
-- Backup filename = fullpath, separators replaced with "%".
- local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1',
- is_os('win') and '[:/\\]' or '/', '%%') .. '~'
- local foo_contents = trim(read_file('Xtest_backupdir with spaces/'..backup_file_name))
+ local backup_file_name = string.gsub(
+ currentdir() .. '/Xtest_startup_file1',
+ is_os('win') and '[:/\\]' or '/',
+ '%%'
+ ) .. '~'
+ local foo_contents = trim(read_file('Xtest_backupdir with spaces/' .. backup_file_name))
local foobar_contents = trim(read_file('Xtest_startup_file1'))
- eq('foobar', foobar_contents);
- eq('foo', foo_contents);
+ eq('foobar', foobar_contents)
+ eq('foo', foo_contents)
end)
it('backup symlinked files #11349', function()
@@ -202,11 +218,10 @@ describe('fileio', function()
command('write')
local backup_raw = read_file(backup_file_name)
- neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. "to exist but did not")
+ neq(nil, backup_raw, 'Expected backup file ' .. backup_file_name .. 'to exist but did not')
eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents')
end)
-
it('backup symlinked files in first available backupdir #11349', function()
skip(is_ci('cirrus'))
clear()
@@ -228,7 +243,7 @@ describe('fileio', function()
command('write')
local backup_raw = read_file(backup_file_name)
- neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. " to exist but did not")
+ neq(nil, backup_raw, 'Expected backup file ' .. backup_file_name .. ' to exist but did not')
eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents')
end)
@@ -247,7 +262,7 @@ describe('fileio', function()
table.insert(text, '')
eq(text, funcs.readfile(fname, 'b'))
end)
- it('read invalid u8 over INT_MAX doesn\'t segfault', function()
+ it("read invalid u8 over INT_MAX doesn't segfault", function()
clear()
command('call writefile(0zFFFFFFFF, "Xtest-u8-int-max")')
-- This should not segfault
@@ -257,18 +272,18 @@ describe('fileio', function()
it(':w! does not show "file has been changed" warning', function()
clear()
- write_file("Xtest-overwrite-forced", 'foobar')
+ write_file('Xtest-overwrite-forced', 'foobar')
command('set nofixendofline')
- local screen = Screen.new(40,4)
+ local screen = Screen.new(40, 4)
screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
- [3] = {bold = true, foreground = Screen.colors.SeaGreen4}
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
+ [3] = { bold = true, foreground = Screen.colors.SeaGreen4 },
})
screen:attach()
- command("set shortmess-=F")
+ command('set shortmess-=F')
- command("e Xtest-overwrite-forced")
+ command('e Xtest-overwrite-forced')
screen:expect([[
^foobar |
{1:~ }|*2
@@ -276,14 +291,14 @@ describe('fileio', function()
]])
-- Get current unix time.
- local cur_unix_time = os.time(os.date("!*t"))
+ local cur_unix_time = os.time(os.date('!*t'))
local future_time = cur_unix_time + 999999
-- Set the file's access/update time to be
-- greater than the time at which it was created.
- local uv = require("luv")
+ local uv = require('luv')
uv.fs_utime('Xtest-overwrite-forced', future_time, future_time)
-- use async feed_command because nvim basically hangs on the prompt
- feed_command("w")
+ feed_command('w')
screen:expect([[
{2:WARNING: The file has been changed since}|
{2: reading it!!!} |
@@ -291,15 +306,15 @@ describe('fileio', function()
^ |
]])
- feed("n")
- feed("<cr>")
+ feed('n')
+ feed('<cr>')
screen:expect([[
^foobar |
{1:~ }|*2
|
]])
-- Use a screen test because the warning does not set v:errmsg.
- command("w!")
+ command('w!')
screen:expect([[
^foobar |
{1:~ }|*2
@@ -333,7 +348,7 @@ describe('tmpdir', function()
end
it('failure modes', function()
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
+ clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } })
assert_nolog('tempdir is not a directory', testlog)
assert_nolog('tempdir has invalid permissions', testlog)
@@ -344,9 +359,9 @@ describe('tmpdir', function()
-- "…/nvim.<user>/" is not a directory:
expect_exit(command, ':qall!')
rmdir(tmproot)
- write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it.
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
- matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
+ write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it.
+ clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } })
+ matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
-- Assert that broken tmpdir root was handled.
assert_log('tempdir root not a directory', testlog, 100)
@@ -355,9 +370,9 @@ describe('tmpdir', function()
os.remove(testlog)
os.remove(tmproot)
mkdir(tmproot)
- funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it.
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
- matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
+ funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it.
+ clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } })
+ matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
-- Assert that broken tmpdir root was handled.
assert_log('tempdir root has invalid permissions', testlog, 100)
end)
@@ -365,14 +380,14 @@ describe('tmpdir', function()
it('too long', function()
local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666))
mkdir(bigname)
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=bigname, } })
- matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
+ clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = bigname } })
+ matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
local len = (funcs.tempname()):len()
ok(len > 4 and len < 256, '4 < len < 256', tostring(len))
end)
it('disappeared #1432', function()
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
+ clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } })
assert_nolog('tempdir disappeared', testlog)
local function rm_tmpdir()
@@ -406,12 +421,13 @@ describe('tmpdir', function()
end)
it('$NVIM_APPNAME relative path', function()
- clear({ env={
- NVIM_APPNAME='a/b',
- NVIM_LOG_FILE=testlog,
- TMPDIR=os_tmpdir,
- } })
+ clear({
+ env = {
+ NVIM_APPNAME = 'a/b',
+ NVIM_LOG_FILE = testlog,
+ TMPDIR = os_tmpdir,
+ },
+ })
matches([=[.*[/\\]a%%b%.[^/\\]+]=], funcs.tempname())
end)
-
end)