2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2017-04-02 17:04:10 -07:00
|
|
|
local lfs = require('lfs')
|
2016-10-21 13:03:01 -07:00
|
|
|
local eq, eval, clear, write_file, execute, source, insert =
|
|
|
|
helpers.eq, helpers.eval, helpers.clear, helpers.write_file,
|
|
|
|
helpers.execute, helpers.source, helpers.insert
|
2017-04-02 17:04:10 -07:00
|
|
|
local redir_exec = helpers.redir_exec
|
|
|
|
local exc_exec = helpers.exc_exec
|
|
|
|
local command = helpers.command
|
|
|
|
local funcs = helpers.funcs
|
|
|
|
local meths = helpers.meths
|
2016-04-15 05:57:29 -07:00
|
|
|
|
2016-08-15 16:42:12 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
|
|
|
|
2017-04-02 17:04:10 -07:00
|
|
|
local fname = 'Xtest-functional-ex_cmds-write'
|
|
|
|
local fname_bak = fname .. '~'
|
|
|
|
local fname_broken = fname_bak .. 'broken'
|
|
|
|
|
2016-04-15 05:57:29 -07:00
|
|
|
describe(':write', function()
|
2016-10-21 13:03:01 -07:00
|
|
|
local function cleanup()
|
2016-04-15 05:57:29 -07:00
|
|
|
os.remove('test_bkc_file.txt')
|
|
|
|
os.remove('test_bkc_link.txt')
|
2016-10-21 13:03:01 -07:00
|
|
|
os.remove('test_fifo')
|
2017-04-02 17:04:10 -07:00
|
|
|
os.remove(fname)
|
|
|
|
os.remove(fname_bak)
|
|
|
|
os.remove(fname_broken)
|
2016-10-21 13:03:01 -07:00
|
|
|
end
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
cleanup()
|
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
cleanup()
|
2016-06-06 18:54:35 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('&backupcopy=auto preserves symlinks', function()
|
2016-10-21 13:03:01 -07:00
|
|
|
execute('set backupcopy=auto')
|
2016-04-15 05:57:29 -07:00
|
|
|
write_file('test_bkc_file.txt', 'content0')
|
|
|
|
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
|
|
|
|
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()
|
2016-10-21 13:03:01 -07:00
|
|
|
execute('set backupcopy=no')
|
2016-04-15 05:57:29 -07:00
|
|
|
write_file('test_bkc_file.txt', 'content0')
|
|
|
|
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
|
|
|
|
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)
|
2016-10-21 13:03:01 -07:00
|
|
|
|
|
|
|
it("appends FIFO file", function()
|
|
|
|
if eval("executable('mkfifo')") == 0 then
|
|
|
|
pending('missing "mkfifo" command', function()end)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local text = "some fifo text from write_spec"
|
|
|
|
assert(os.execute("mkfifo test_fifo"))
|
|
|
|
insert(text)
|
|
|
|
|
|
|
|
-- Blocks until a consumer reads the FIFO.
|
|
|
|
execute("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)
|
2017-04-02 17:04:10 -07:00
|
|
|
|
|
|
|
it('errors out correctly', function()
|
|
|
|
command('let $HOME=""')
|
|
|
|
eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~'))
|
|
|
|
-- Message from check_overwrite
|
|
|
|
eq(('\nE17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
|
|
|
|
redir_exec('write .'))
|
|
|
|
meths.set_option('writeany', true)
|
|
|
|
-- Message from buf_write
|
|
|
|
eq(('\nE502: "." is a directory'),
|
|
|
|
redir_exec('write .'))
|
|
|
|
funcs.mkdir(fname_bak)
|
|
|
|
meths.set_option('backupdir', '.')
|
|
|
|
meths.set_option('backup', true)
|
|
|
|
write_file(fname, 'content0')
|
|
|
|
eq(0, exc_exec('edit ' .. fname))
|
|
|
|
funcs.setline(1, 'TTY')
|
|
|
|
eq('Vim(write):E510: Can\'t make backup file (add ! to override)',
|
|
|
|
exc_exec('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)',
|
|
|
|
exc_exec('write'))
|
|
|
|
os.remove(fname)
|
|
|
|
os.remove(fname_bak)
|
|
|
|
write_file(fname_bak, 'TTYX')
|
|
|
|
lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true)
|
|
|
|
eq('Vim(write):E166: Can\'t open linked file for writing',
|
|
|
|
exc_exec('write!'))
|
|
|
|
end)
|
2016-04-15 05:57:29 -07:00
|
|
|
end)
|