aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-08-11 21:00:56 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-08-17 01:14:13 -0400
commitd5cd15e67f8a4cfdc6a29d39efbce2697578783c (patch)
tree105fe18a13e1290fb501360df3033cc7809b7d06
parent14d2a90db984c1a0360727c4d9b8337a689fccec (diff)
downloadrneovim-d5cd15e67f8a4cfdc6a29d39efbce2697578783c.tar.gz
rneovim-d5cd15e67f8a4cfdc6a29d39efbce2697578783c.tar.bz2
rneovim-d5cd15e67f8a4cfdc6a29d39efbce2697578783c.zip
test: more cases for os_file_is_readonly()
-rw-r--r--test/unit/os/fs_spec.lua41
1 files changed, 36 insertions, 5 deletions
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 9cca3ca244..c5723d20e1 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -314,10 +314,8 @@ describe('fs function', function()
end)
end
- -- On Windows `os_fchown` always returns 0
- -- because `uv_fs_chown` is no-op on this platform.
if (ffi.os == 'Windows' or ffi.C.geteuid() == 0) then
- pending('skipped (os_fchown is no-op on Windows)', function() end)
+ pending('skipped (uv_fs_chown is no-op on Windows)', function() end)
else
it('returns nonzero if process has not enough permissions', function()
-- chown to root
@@ -327,18 +325,51 @@ describe('fs function', function()
end)
describe('os_file_is_readonly', function()
- it('returns true if the file is readonly', function()
+ -- pending('returns ? if the file does not exist', function() end)
+ -- pending('returns ? if the path is a directory', function() end)
+ -- pending('returns ? if the file is executable', function() end)
+
+ it('returns false if the file is non-read, non-write', function()
+ local perm = os_getperm('unit-test-directory/test.file')
+ perm = unset_bit(perm, ffi.C.kS_IWUSR)
+ perm = unset_bit(perm, ffi.C.kS_IWGRP)
+ perm = unset_bit(perm, ffi.C.kS_IWOTH)
+ perm = unset_bit(perm, ffi.C.kS_IRUSR)
+ perm = unset_bit(perm, ffi.C.kS_IRGRP)
+ perm = unset_bit(perm, ffi.C.kS_IROTH)
+
+ eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
+ eq(1, os_file_is_writable('unit-test-directory/test.file'))
+ eq(false, os_file_is_readonly('unit-test-directory/test.file'))
+ end)
+
+ it('returns false if the file is write-only', function()
+ local perm = os_getperm('unit-test-directory/test.file')
+ perm = set_bit(perm, ffi.C.kS_IWUSR)
+ perm = set_bit(perm, ffi.C.kS_IWGRP)
+ perm = set_bit(perm, ffi.C.kS_IWOTH)
+ perm = unset_bit(perm, ffi.C.kS_IRUSR)
+ perm = unset_bit(perm, ffi.C.kS_IRGRP)
+ perm = unset_bit(perm, ffi.C.kS_IROTH)
+
+ eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
+ eq(1, os_file_is_writable('unit-test-directory/test.file'))
+ eq(false, os_file_is_readonly('unit-test-directory/test.file'))
+ end)
+
+ it('returns true if the file is read-only', function()
local perm = os_getperm('unit-test-directory/test.file')
local perm_orig = perm
perm = unset_bit(perm, ffi.C.kS_IWUSR)
perm = unset_bit(perm, ffi.C.kS_IWGRP)
perm = unset_bit(perm, ffi.C.kS_IWOTH)
+
eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
eq(true, os_file_is_readonly('unit-test-directory/test.file'))
eq(OK, (os_setperm('unit-test-directory/test.file', perm_orig)))
end)
- it('returns false if the file is writable', function()
+ it('returns false if the file is read-write', function()
eq(false, os_file_is_readonly('unit-test-directory/test.file'))
end)
end)