mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00

dispatch.sr.ht is being deprecated, meaning that using sourcehut CI won't be possible (see https://github.com/neovim/neovim/issues/19609). Since Github Actions doesn't provide any BSD runners an external service is required and Cirrus CI seems like a good replacement for sourcehut. Initially experimented with using FreeBSD and OpenBSD virtual machines in GitHub Actions, but Cirrus has been a much better fit with better performance, logs and overall experience. Failing tests are automatically skipped on FreeBSD regardless if it's on CI or not. Ideally these tests should only be skipped in CI with the help of `isCI` helper function. Unfortunately, the tests don't recognize the environment variable CIRRUS_CI even if it's set manually. This workaround is good enough for the time being, but we might want to only skip tests when using the CI (or even better, fix the failing tests). Closes: https://github.com/neovim/neovim/issues/19609
138 lines
4.3 KiB
Lua
138 lines
4.3 KiB
Lua
local helpers = require('test.functional.helpers')(after_each)
|
|
local lfs = require('lfs')
|
|
local eq, eval, clear, write_file, source, insert =
|
|
helpers.eq, helpers.eval, helpers.clear, helpers.write_file,
|
|
helpers.source, helpers.insert
|
|
local pcall_err = helpers.pcall_err
|
|
local command = helpers.command
|
|
local feed_command = helpers.feed_command
|
|
local funcs = helpers.funcs
|
|
local meths = helpers.meths
|
|
local iswin = helpers.iswin
|
|
local uname = helpers.uname
|
|
|
|
local fname = 'Xtest-functional-ex_cmds-write'
|
|
local fname_bak = fname .. '~'
|
|
local fname_broken = fname_bak .. 'broken'
|
|
|
|
describe(':write', function()
|
|
local function cleanup()
|
|
os.remove('test_bkc_file.txt')
|
|
os.remove('test_bkc_link.txt')
|
|
os.remove('test_fifo')
|
|
os.remove(fname)
|
|
os.remove(fname_bak)
|
|
os.remove(fname_broken)
|
|
end
|
|
before_each(function()
|
|
clear()
|
|
cleanup()
|
|
end)
|
|
after_each(function()
|
|
cleanup()
|
|
end)
|
|
|
|
it('&backupcopy=auto preserves symlinks', function()
|
|
command('set backupcopy=auto')
|
|
write_file('test_bkc_file.txt', 'content0')
|
|
if iswin() then
|
|
command("silent !mklink test_bkc_link.txt test_bkc_file.txt")
|
|
else
|
|
command("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
|
|
end
|
|
if eval('v:shell_error') ~= 0 then
|
|
pending('Cannot create symlink')
|
|
end
|
|
source([[
|
|
edit test_bkc_link.txt
|
|
call setline(1, ['content1'])
|
|
write
|
|
]])
|
|
eq(eval("['content1']"), eval("readfile('test_bkc_file.txt')"))
|
|
eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')"))
|
|
end)
|
|
|
|
it('&backupcopy=no replaces symlink with new file', function()
|
|
if uname() == 'freebsd' then
|
|
pending('Failing FreeBSD test')
|
|
end
|
|
command('set backupcopy=no')
|
|
write_file('test_bkc_file.txt', 'content0')
|
|
if iswin() then
|
|
command("silent !mklink test_bkc_link.txt test_bkc_file.txt")
|
|
else
|
|
command("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
|
|
end
|
|
if eval('v:shell_error') ~= 0 then
|
|
pending('Cannot create symlink')
|
|
end
|
|
source([[
|
|
edit test_bkc_link.txt
|
|
call setline(1, ['content1'])
|
|
write
|
|
]])
|
|
eq(eval("['content0']"), eval("readfile('test_bkc_file.txt')"))
|
|
eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')"))
|
|
end)
|
|
|
|
it("appends FIFO file", function()
|
|
-- mkfifo creates read-only .lnk files on Windows
|
|
if iswin() or eval("executable('mkfifo')") == 0 then
|
|
pending('missing "mkfifo" command')
|
|
end
|
|
|
|
local text = "some fifo text from write_spec"
|
|
assert(os.execute("mkfifo test_fifo"))
|
|
insert(text)
|
|
|
|
-- Blocks until a consumer reads the FIFO.
|
|
feed_command("write >> test_fifo")
|
|
|
|
-- Read the FIFO, this will unblock the :write above.
|
|
local fifo = assert(io.open("test_fifo"))
|
|
eq(text.."\n", fifo:read("*all"))
|
|
fifo:close()
|
|
end)
|
|
|
|
it('errors out correctly', function()
|
|
if uname() == 'freebsd' then
|
|
pending('Failing FreeBSD test')
|
|
end
|
|
command('let $HOME=""')
|
|
eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~'))
|
|
-- Message from check_overwrite
|
|
if not iswin() then
|
|
eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
|
|
pcall_err(command, 'write .'))
|
|
end
|
|
meths.set_option('writeany', true)
|
|
-- Message from buf_write
|
|
eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .'))
|
|
funcs.mkdir(fname_bak)
|
|
meths.set_option('backupdir', '.')
|
|
meths.set_option('backup', true)
|
|
write_file(fname, 'content0')
|
|
command('edit ' .. fname)
|
|
funcs.setline(1, 'TTY')
|
|
eq('Vim(write):E510: Can\'t make backup file (add ! to override)',
|
|
pcall_err(command, 'write'))
|
|
meths.set_option('backup', false)
|
|
funcs.setfperm(fname, 'r--------')
|
|
eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)',
|
|
pcall_err(command, 'write'))
|
|
if iswin() then
|
|
eq(0, os.execute('del /q/f ' .. fname))
|
|
eq(0, os.execute('rd /q/s ' .. fname_bak))
|
|
else
|
|
eq(true, os.remove(fname))
|
|
eq(true, os.remove(fname_bak))
|
|
end
|
|
write_file(fname_bak, 'TTYX')
|
|
-- FIXME: exc_exec('write!') outputs 0 in Windows
|
|
if iswin() then return end
|
|
lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true)
|
|
eq('Vim(write):E166: Can\'t open linked file for writing',
|
|
pcall_err(command, 'write!'))
|
|
end)
|
|
end)
|