diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-08-16 08:33:21 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-08-16 08:33:21 -0400 |
commit | 640bced2f8bf64098d52841947a3145554d41041 (patch) | |
tree | 1787f0df28059d27fe32885bc4b972384ff09c2e /test | |
parent | 19207762fd6dccd83b89c96bb1163b0d0440defb (diff) | |
parent | 8f4ada5a2a5c1bfe546cf7d67d3531551ff6026c (diff) | |
download | rneovim-640bced2f8bf64098d52841947a3145554d41041.tar.gz rneovim-640bced2f8bf64098d52841947a3145554d41041.tar.bz2 rneovim-640bced2f8bf64098d52841947a3145554d41041.zip |
Merge pull request #950 from Hinidu/os_fchown
Implement os_fchown and remove HAVE_FCHOWN
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/os/fs_spec.moon | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/os/fs_spec.moon b/test/unit/os/fs_spec.moon index 52f587d6f9..dd787e76cd 100644 --- a/test/unit/os/fs_spec.moon +++ b/test/unit/os/fs_spec.moon @@ -112,6 +112,12 @@ describe 'fs function', -> os_setperm = (filename, perm) -> fs.os_setperm (to_cstr filename), perm + os_fchown = (filename, user_id, group_id) -> + fd = ffi.C.open filename, 0 + res = fs.os_fchown fd, user_id, group_id + ffi.C.close fd + return res + os_file_is_readonly = (filename) -> fs.os_file_is_readonly (to_cstr filename) @@ -158,6 +164,43 @@ describe 'fs function', -> perm = ffi.C.kS_IXUSR eq FAIL, (os_setperm 'non-existing-file', perm) + describe 'os_fchown', -> + filename = 'unit-test-directory/test.file' + + it 'does not change owner and group if respective IDs are equal to -1', -> + uid = lfs.attributes filename, 'uid' + gid = lfs.attributes filename, 'gid' + eq 0, os_fchown filename, -1, -1 + eq uid, lfs.attributes filename, 'uid' + eq gid, lfs.attributes filename, 'gid' + + it 'owner of a file may change the group of the file + to any group of which that owner is a member', -> + -- Some systems may not have `id` utility. + if (os.execute('id -G &> /dev/null') == 0) + file_gid = lfs.attributes filename, 'gid' + + -- Gets ID of any group of which current user is a member except the + -- group that owns the file. + id_fd = io.popen('id -G') + new_gid = id_fd\read '*n' + if (new_gid == file_gid) + new_gid = id_fd\read '*n' + id_fd\close! + + -- User can be a member of only one group. + -- In that case we can not perform this test. + if new_gid + eq 0, (os_fchown filename, -1, new_gid) + eq new_gid, (lfs.attributes filename, 'gid') + + it 'returns nonzero if process has not enough permissions', -> + -- On Windows `os_fchown` always returns 0 + -- because `uv_fs_chown` is no-op on this platform. + if (ffi.os != 'Windows' and ffi.C.geteuid! != 0) + -- chown to root + neq 0, os_fchown filename, 0, 0 + describe 'os_file_is_readonly', -> it 'returns true if the file is readonly', -> perm = os_getperm 'unit-test-directory/test.file' |