aboutsummaryrefslogtreecommitdiff
path: root/test/functional/core/fileio_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/core/fileio_spec.lua')
-rw-r--r--test/functional/core/fileio_spec.lua124
1 files changed, 117 insertions, 7 deletions
diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua
index a4d22685e8..bbf2202f0d 100644
--- a/test/functional/core/fileio_spec.lua
+++ b/test/functional/core/fileio_spec.lua
@@ -1,3 +1,4 @@
+local lfs = require('lfs')
local helpers = require('test.functional.helpers')(after_each)
local assert_log = helpers.assert_log
@@ -5,6 +6,7 @@ local assert_nolog = helpers.assert_nolog
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
+local neq = helpers.neq
local ok = helpers.ok
local feed = helpers.feed
local funcs = helpers.funcs
@@ -19,22 +21,28 @@ local read_file = helpers.read_file
local tmpname = helpers.tmpname
local trim = helpers.trim
local currentdir = helpers.funcs.getcwd
-local iswin = helpers.iswin
local assert_alive = helpers.assert_alive
+local check_close = helpers.check_close
local expect_exit = helpers.expect_exit
local write_file = helpers.write_file
+local Screen = require('test.functional.ui.screen')
+local feed_command = helpers.feed_command
+local skip = helpers.skip
+local is_os = helpers.is_os
+local is_ci = helpers.is_ci
describe('fileio', function()
before_each(function()
end)
after_each(function()
- expect_exit(command, ':qall!')
+ check_close()
os.remove('Xtest_startup_shada')
os.remove('Xtest_startup_file1')
os.remove('Xtest_startup_file1~')
os.remove('Xtest_startup_file2')
os.remove('Xtest_тест.md')
os.remove('Xtest-u8-int-max')
+ os.remove('Xtest-overwrite-forced')
rmdir('Xtest_startup_swapdir')
rmdir('Xtest_backupdir')
end)
@@ -83,6 +91,7 @@ describe('fileio', function()
end)
it('backup #9709', function()
+ skip(is_ci('cirrus'))
clear({ args={ '-i', 'Xtest_startup_shada',
'--cmd', 'set directory=Xtest_startup_swapdir' } })
@@ -102,6 +111,7 @@ describe('fileio', function()
end)
it('backup with full path #11214', function()
+ skip(is_ci('cirrus'))
clear()
mkdir('Xtest_backupdir')
command('set backup')
@@ -114,7 +124,7 @@ describe('fileio', function()
-- Backup filename = fullpath, separators replaced with "%".
local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1',
- iswin() and '[:/\\]' or '/', '%%') .. '~'
+ 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'))
@@ -122,6 +132,53 @@ describe('fileio', function()
eq('foo', foo_contents);
end)
+ it('backup symlinked files #11349', function()
+ skip(is_ci('cirrus'))
+ clear()
+
+ local initial_content = 'foo'
+ local link_file_name = 'Xtest_startup_file2'
+ local backup_file_name = link_file_name .. '~'
+
+ write_file('Xtest_startup_file1', initial_content, false)
+ lfs.link('Xtest_startup_file1', link_file_name, true)
+ command('set backup')
+ command('set backupcopy=yes')
+ command('edit ' .. link_file_name)
+ feed('Abar<esc>')
+ 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")
+ 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()
+
+ local initial_content = 'foo'
+ local backup_dir = 'Xtest_backupdir'
+ local sep = helpers.get_pathsep()
+ local link_file_name = 'Xtest_startup_file2'
+ local backup_file_name = backup_dir .. sep .. link_file_name .. '~'
+
+ write_file('Xtest_startup_file1', initial_content, false)
+ lfs.link('Xtest_startup_file1', link_file_name, true)
+ mkdir(backup_dir)
+ command('set backup')
+ command('set backupcopy=yes')
+ command('set backupdir=.__this_does_not_exist__,' .. backup_dir)
+ command('edit ' .. link_file_name)
+ feed('Abar<esc>')
+ 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")
+ eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents')
+ end)
+
it('readfile() on multibyte filename #10586', function()
clear()
local text = {
@@ -144,6 +201,61 @@ describe('fileio', function()
command('edit ++enc=utf32 Xtest-u8-int-max')
assert_alive()
end)
+
+ it(':w! does not show "file has been changed" warning', function()
+ clear()
+ write_file("Xtest-overwrite-forced", 'foobar')
+ command('set nofixendofline')
+ 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}
+ })
+ screen:attach()
+ command("set shortmess-=F")
+
+ command("e Xtest-overwrite-forced")
+ screen:expect([[
+ ^foobar |
+ {1:~ }|
+ {1:~ }|
+ "Xtest-overwrite-forced" [noeol] 1L, 6B |
+ ]])
+
+ -- Get current unix time.
+ 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")
+ uv.fs_utime('Xtest-overwrite-forced', future_time, future_time)
+ -- use async feed_command because nvim basically hangs on the prompt
+ feed_command("w")
+ screen:expect([[
+ {2:WARNING: The file has been changed since}|
+ {2: reading it!!!} |
+ {3:Do you really want to write to it (y/n)^?}|
+ |
+ ]])
+
+ feed("n")
+ feed("<cr>")
+ screen:expect([[
+ ^foobar |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ -- Use a screen test because the warning does not set v:errmsg.
+ command("w!")
+ screen:expect([[
+ ^foobar |
+ {1:~ }|
+ {1:~ }|
+ <erwrite-forced" [noeol] 1L, 6B written |
+ ]])
+ end)
end)
describe('tmpdir', function()
@@ -159,7 +271,7 @@ describe('tmpdir', function()
end)
after_each(function()
- expect_exit(command, ':qall!')
+ check_close()
os.remove(testlog)
end)
@@ -188,9 +300,7 @@ describe('tmpdir', function()
end)
-- "…/nvim.<user>/" has wrong permissions:
- if iswin() then
- return -- TODO(justinmk): need setfperm/getfperm on Windows. #8244
- end
+ skip(is_os('win'), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244')
os.remove(testlog)
os.remove(tmproot)
mkdir(tmproot)