neovim/test/functional/ex_cmds/write_spec.lua
Rui Abreu Ferreira 136374ec6f Remove old UNIX ifdef from buf_write()
When backupcopy=auto buf_write assumes backupcopy=yes when the file is a
hard/symbolic link. However this check was guarded by a UNIX ifdef. The
check itself is portable and the guard can be removed.

Added a couple tests to check the behaviour of bkc=auto and bkc=no
with a symbolic link.

Reported in #4525
2016-04-28 23:58:21 +01:00

39 lines
1.3 KiB
Lua

-- Specs for :write
local helpers = require('test.functional.helpers')
local eq, eval, clear, write_file, execute, source =
helpers.eq, helpers.eval, helpers.clear, helpers.write_file,
helpers.execute, helpers.source
describe(':write', function()
it('&backupcopy=auto preserves symlinks', function()
clear('set backupcopy=auto')
os.remove('test_bkc_file.txt')
os.remove('test_bkc_link.txt')
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()
clear('set backupcopy=no')
os.remove('test_bkc_file.txt')
os.remove('test_bkc_link.txt')
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)
end)