diff options
Diffstat (limited to 'test/unit/os/fs_spec.lua')
-rw-r--r-- | test/unit/os/fs_spec.lua | 292 |
1 files changed, 155 insertions, 137 deletions
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index 7e7eddb6fc..ddb438eb3d 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -1,7 +1,8 @@ local lfs = require('lfs') local bit = require('bit') -local helpers = require('test.unit.helpers') +local helpers = require('test.unit.helpers')(after_each) +local itp = helpers.gen_itp(it) local cimport = helpers.cimport local cppimport = helpers.cppimport @@ -15,18 +16,18 @@ local to_cstr = helpers.to_cstr local OK = helpers.OK local FAIL = helpers.FAIL local NULL = helpers.NULL + local NODE_NORMAL = 0 local NODE_WRITABLE = 1 -cimport('unistd.h') cimport('./src/nvim/os/shell.h') cimport('./src/nvim/option_defs.h') cimport('./src/nvim/main.h') cimport('./src/nvim/fileio.h') -local fs = cimport('./src/nvim/os/os.h') +local fs = cimport('./src/nvim/os/os.h', './src/nvim/path.h') cppimport('sys/stat.h') cppimport('fcntl.h') -cppimport('uv-errno.h') +cppimport('uv.h') local s = '' for i = 0, 255 do @@ -34,7 +35,6 @@ for i = 0, 255 do end local fcontents = s:rep(16) -local buffer = "" local directory = nil local absolute_executable = nil local executable_name = nil @@ -64,28 +64,27 @@ local function os_getperm(filename) return tonumber(perm) end -describe('fs function', function() - local orig_test_file_perm +describe('fs.c', function() + local function os_isdir(name) + return fs.os_isdir(to_cstr(name)) + end - setup(function() + before_each(function() lfs.mkdir('unit-test-directory'); io.open('unit-test-directory/test.file', 'w').close() - orig_test_file_perm = os_getperm('unit-test-directory/test.file') io.open('unit-test-directory/test_2.file', 'w').close() lfs.link('test.file', 'unit-test-directory/test_link.file', true) lfs.link('non_existing_file.file', 'unit-test-directory/test_broken_link.file', true) - -- Since the tests are executed, they are called by an executable. We use - -- that executable for several asserts. + -- The tests are invoked with an absolute path to `busted` executable. absolute_executable = arg[0] - -- Split absolute_executable into a directory and the actual file name for - -- later usage. + -- Split the absolute_executable path into a directory and filename. directory, executable_name = string.match(absolute_executable, '^(.*)/(.*)$') end) - teardown(function() + after_each(function() os.remove('unit-test-directory/test.file') os.remove('unit-test-directory/test_2.file') os.remove('unit-test-directory/test_link.file') @@ -95,63 +94,68 @@ describe('fs function', function() end) describe('os_dirname', function() - local length - - local function os_dirname(buf, len) - return fs.os_dirname(buf, len) - end - - before_each(function() - length = (string.len(lfs.currentdir())) + 1 - buffer = cstr(length, '') + itp('returns OK and writes current directory to the buffer', function() + local length = string.len(lfs.currentdir()) + 1 + local buf = cstr(length, '') + eq(OK, fs.os_dirname(buf, length)) + eq(lfs.currentdir(), ffi.string(buf)) end) - it('returns OK and writes current directory into the buffer if it is large\n enough', function() - eq(OK, (os_dirname(buffer, length))) - eq(lfs.currentdir(), (ffi.string(buffer))) + itp('returns FAIL if the buffer is too small', function() + local length = string.len(lfs.currentdir()) + 1 + local buf = cstr(length - 1, '') + eq(FAIL, fs.os_dirname(buf, length - 1)) end) + end) - -- What kind of other failing cases are possible? - it('returns FAIL if the buffer is too small', function() - local buf = cstr((length - 1), '') - eq(FAIL, (os_dirname(buf, (length - 1)))) + describe('os_chdir', function() + itp('fails with path="~"', function() + eq(false, os_isdir('~')) -- sanity check: no literal "~" directory. + local length = 4096 + local expected_cwd = cstr(length, '') + local cwd = cstr(length, '') + eq(OK, fs.os_dirname(expected_cwd, length)) + + -- os_chdir returns 0 for success, not OK (1). + neq(0, fs.os_chdir('~')) -- fail + neq(0, fs.os_chdir('~/')) -- fail + + eq(OK, fs.os_dirname(cwd, length)) + -- CWD did not change. + eq(ffi.string(expected_cwd), ffi.string(cwd)) end) end) - local function os_isdir(name) - return fs.os_isdir((to_cstr(name))) - end - describe('os_isdir', function() - it('returns false if an empty string is given', function() + itp('returns false if an empty string is given', function() eq(false, (os_isdir(''))) end) - it('returns false if a nonexisting directory is given', function() + itp('returns false if a nonexisting directory is given', function() eq(false, (os_isdir('non-existing-directory'))) end) - it('returns false if a nonexisting absolute directory is given', function() + itp('returns false if a nonexisting absolute directory is given', function() eq(false, (os_isdir('/non-existing-directory'))) end) - it('returns false if an existing file is given', function() + itp('returns false if an existing file is given', function() eq(false, (os_isdir('unit-test-directory/test.file'))) end) - it('returns true if the current directory is given', function() + itp('returns true if the current directory is given', function() eq(true, (os_isdir('.'))) end) - it('returns true if the parent directory is given', function() + itp('returns true if the parent directory is given', function() eq(true, (os_isdir('..'))) end) - it('returns true if an arbitrary directory is given', function() + itp('returns true if an arbitrary directory is given', function() eq(true, (os_isdir('unit-test-directory'))) end) - it('returns true if an absolute directory is given', function() + itp('returns true if an absolute directory is given', function() eq(true, (os_isdir(directory))) end) end) @@ -181,33 +185,30 @@ describe('fs function', function() return os_can_exe(name) end - it('returns false when given a directory', function() + itp('returns false when given a directory', function() cant_exe('./unit-test-directory') end) - it('returns false when given a regular file without executable bit set', function() + itp('returns false when given a regular file without executable bit set', function() cant_exe('unit-test-directory/test.file') end) - it('returns false when the given file does not exists', function() + itp('returns false when the given file does not exists', function() cant_exe('does-not-exist.file') end) - it('returns the absolute path when given an executable inside $PATH', function() - -- Since executable_name does not start with "./", the path will be - -- selected from $PATH. Make sure the ends match, ignore the directories. - local _, busted = string.match(absolute_executable, '^(.*)/(.*)$') - local _, name = string.match(exe(executable_name), '^(.*)/(.*)$') - eq(busted, name) + itp('returns the absolute path when given an executable inside $PATH', function() + local fullpath = exe('ls') + eq(1, fs.path_is_absolute(to_cstr(fullpath))) end) - it('returns the absolute path when given an executable relative to the current dir', function() + itp('returns the absolute path when given an executable relative to the current dir', function() local old_dir = lfs.currentdir() lfs.chdir(directory) - -- Rely on currentdir to resolve symlinks, if any. Testing against - -- the absolute path taken from arg[0] may result in failure where + -- Rely on currentdir to resolve symlinks, if any. Testing against + -- the absolute path taken from arg[0] may result in failure where -- the path has a symlink in it. local canonical = lfs.currentdir() .. '/' .. executable_name local expected = exe(canonical) @@ -221,10 +222,6 @@ describe('fs function', function() end) describe('file permissions', function() - before_each(function() - os_setperm('unit-test-directory/test.file', orig_test_file_perm) - end) - local function os_fchown(filename, user_id, group_id) local fd = ffi.C.open(filename, 0) local res = fs.os_fchown(fd, user_id, group_id) @@ -245,22 +242,22 @@ describe('fs function', function() end describe('os_getperm', function() - it('returns UV_ENOENT when the given file does not exist', function() + itp('returns UV_ENOENT when the given file does not exist', function() eq(ffi.C.UV_ENOENT, (os_getperm('non-existing-file'))) end) - it('returns a perm > 0 when given an existing file', function() + itp('returns a perm > 0 when given an existing file', function() assert.is_true((os_getperm('unit-test-directory')) > 0) end) - it('returns S_IRUSR when the file is readable', function() + itp('returns S_IRUSR when the file is readable', function() local perm = os_getperm('unit-test-directory') assert.is_true((bit_set(perm, ffi.C.kS_IRUSR))) end) end) describe('os_setperm', function() - it('can set and unset the executable bit of a file', function() + itp('can set and unset the executable bit of a file', function() local perm = os_getperm('unit-test-directory/test.file') perm = unset_bit(perm, ffi.C.kS_IXUSR) eq(OK, (os_setperm('unit-test-directory/test.file', perm))) @@ -272,7 +269,7 @@ describe('fs function', function() assert.is_true((bit_set(perm, ffi.C.kS_IXUSR))) end) - it('fails if given file does not exist', function() + itp('fails if given file does not exist', function() local perm = ffi.C.kS_IXUSR eq(FAIL, (os_setperm('non-existing-file', perm))) end) @@ -280,7 +277,7 @@ describe('fs function', function() describe('os_fchown', function() local filename = 'unit-test-directory/test.file' - it('does not change owner and group if respective IDs are equal to -1', function() + itp('does not change owner and group if respective IDs are equal to -1', function() local uid = lfs.attributes(filename, 'uid') local gid = lfs.attributes(filename, 'gid') eq(0, os_fchown(filename, -1, -1)) @@ -292,7 +289,7 @@ describe('fs function', function() if (os.execute('id -G > /dev/null 2>&1') ~= 0) then pending('skipped (missing `id` utility)', function() end) else - it('owner of a file may change the group of the file to any group of which that owner is a member', function() + itp('owner of a file may change the group of the file to any group of which that owner is a member', function() local file_gid = lfs.attributes(filename, 'gid') -- Gets ID of any group of which current user is a member except the @@ -316,7 +313,7 @@ describe('fs function', function() if (ffi.os == 'Windows' or ffi.C.geteuid() == 0) then pending('skipped (uv_fs_chown is no-op on Windows)', function() end) else - it('returns nonzero if process has not enough permissions', function() + itp('returns nonzero if process has not enough permissions', function() -- chown to root neq(0, os_fchown(filename, 0, 0)) end) @@ -325,7 +322,7 @@ describe('fs function', function() describe('os_file_is_readable', function() - it('returns false if the file is not readable', function() + itp('returns false if the file is not readable', function() local perm = os_getperm('unit-test-directory/test.file') perm = unset_bit(perm, ffi.C.kS_IRUSR) perm = unset_bit(perm, ffi.C.kS_IRGRP) @@ -334,19 +331,19 @@ describe('fs function', function() eq(false, os_file_is_readable('unit-test-directory/test.file')) end) - it('returns false if the file does not exist', function() + itp('returns false if the file does not exist', function() eq(false, os_file_is_readable( 'unit-test-directory/what_are_you_smoking.gif')) end) - it('returns true if the file is readable', function() + itp('returns true if the file is readable', function() eq(true, os_file_is_readable( 'unit-test-directory/test.file')) end) end) describe('os_file_is_writable', function() - it('returns 0 if the file is readonly', function() + itp('returns 0 if the file is readonly', 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) @@ -355,11 +352,11 @@ describe('fs function', function() eq(0, os_file_is_writable('unit-test-directory/test.file')) end) - it('returns 1 if the file is writable', function() + itp('returns 1 if the file is writable', function() eq(1, os_file_is_writable('unit-test-directory/test.file')) end) - it('returns 2 when given a folder with rights to write into', function() + itp('returns 2 when given a folder with rights to write into', function() eq(2, os_file_is_writable('unit-test-directory')) end) end) @@ -393,7 +390,7 @@ describe('fs function', function() buf = ffi.new('char[?]', size + 1, ('\0'):rep(size)) end local eof = ffi.new('bool[?]', 1, {true}) - local ret2 = fs.os_read(fd, eof, buf, size) + local ret2 = fs.os_read(fd, eof, buf, size, false) local ret1 = eof[0] local ret3 = '' if buf ~= nil then @@ -411,7 +408,7 @@ describe('fs function', function() end local iov = ffi.new('struct iovec[?]', #sizes, bufs) local eof = ffi.new('bool[?]', 1, {true}) - local ret2 = fs.os_readv(fd, eof, iov, #sizes) + local ret2 = fs.os_readv(fd, eof, iov, #sizes, false) local ret1 = eof[0] local ret3 = {} for i = 1,#sizes do @@ -421,23 +418,23 @@ describe('fs function', function() return ret1, ret2, ret3 end local function os_write(fd, data) - return fs.os_write(fd, data, data and #data or 0) + return fs.os_write(fd, data, data and #data or 0, false) end describe('os_path_exists', function() - it('returns false when given a non-existing file', function() + itp('returns false when given a non-existing file', function() eq(false, (os_path_exists('non-existing-file'))) end) - it('returns true when given an existing file', function() + itp('returns true when given an existing file', function() eq(true, (os_path_exists('unit-test-directory/test.file'))) end) - it('returns false when given a broken symlink', function() + itp('returns false when given a broken symlink', function() eq(false, (os_path_exists('unit-test-directory/test_broken_link.file'))) end) - it('returns true when given a directory', function() + itp('returns true when given a directory', function() eq(true, (os_path_exists('unit-test-directory'))) end) end) @@ -446,18 +443,18 @@ describe('fs function', function() local test = 'unit-test-directory/test.file' local not_exist = 'unit-test-directory/not_exist.file' - it('can rename file if destination file does not exist', function() + itp('can rename file if destination file does not exist', function() eq(OK, (os_rename(test, not_exist))) eq(false, (os_path_exists(test))) eq(true, (os_path_exists(not_exist))) eq(OK, (os_rename(not_exist, test))) -- restore test file end) - it('fail if source file does not exist', function() + itp('fail if source file does not exist', function() eq(FAIL, (os_rename(not_exist, test))) end) - it('can overwrite destination file if it exists', function() + itp('can overwrite destination file if it exists', function() local other = 'unit-test-directory/other.file' local file = io.open(other, 'w') file:write('other') @@ -482,11 +479,11 @@ describe('fs function', function() os.remove('unit-test-directory/test_remove.file') end) - it('returns non-zero when given a non-existing file', function() + itp('returns non-zero when given a non-existing file', function() neq(0, (os_remove('non-existing-file'))) end) - it('removes the given file and returns 0', function() + itp('removes the given file and returns 0', function() local f = 'unit-test-directory/test_remove.file' assert_file_exists(f) eq(0, (os_remove(f))) @@ -494,6 +491,22 @@ describe('fs function', function() end) end) + describe('os_dup', function() + itp('returns new file descriptor', function() + local dup0 = fs.os_dup(0) + local dup1 = fs.os_dup(1) + local dup2 = fs.os_dup(2) + local tbl = {[0]=true, [1]=true, [2]=true, + [tonumber(dup0)]=true, [tonumber(dup1)]=true, + [tonumber(dup2)]=true} + local i = 0 + for _, _ in pairs(tbl) do + i = i + 1 + end + eq(i, 6) -- All fds must be unique + end) + end) + describe('os_open', function() local new_file = 'test_new_file' local existing_file = 'unit-test-directory/test_existing.file' @@ -507,30 +520,30 @@ describe('fs function', function() os.remove(new_file) end) - it('returns UV_ENOENT for O_RDWR on a non-existing file', function() + itp('returns UV_ENOENT for O_RDWR on a non-existing file', function() eq(ffi.C.UV_ENOENT, (os_open('non-existing-file', ffi.C.kO_RDWR, 0))) end) - it('returns non-negative for O_CREAT on a non-existing file which then can be closed', function() + itp('returns non-negative for O_CREAT on a non-existing file which then can be closed', function() assert_file_does_not_exist(new_file) local fd = os_open(new_file, ffi.C.kO_CREAT, 0) assert.is_true(0 <= fd) eq(0, os_close(fd)) end) - it('returns non-negative for O_CREAT on a existing file which then can be closed', function() + itp('returns non-negative for O_CREAT on a existing file which then can be closed', function() assert_file_exists(existing_file) local fd = os_open(existing_file, ffi.C.kO_CREAT, 0) assert.is_true(0 <= fd) eq(0, os_close(fd)) end) - it('returns UV_EEXIST for O_CREAT|O_EXCL on a existing file', function() + itp('returns UV_EEXIST for O_CREAT|O_EXCL on a existing file', function() assert_file_exists(existing_file) eq(ffi.C.kUV_EEXIST, (os_open(existing_file, (bit.bor(ffi.C.kO_CREAT, ffi.C.kO_EXCL)), 0))) end) - it('sets `rwx` permissions for O_CREAT 700 which then can be closed', function() + itp('sets `rwx` permissions for O_CREAT 700 which then can be closed', function() assert_file_does_not_exist(new_file) --create the file local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("700", 8)) @@ -539,7 +552,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('sets `rw` permissions for O_CREAT 600 which then can be closed', function() + itp('sets `rw` permissions for O_CREAT 600 which then can be closed', function() assert_file_does_not_exist(new_file) --create the file local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("600", 8)) @@ -548,7 +561,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('returns a non-negative file descriptor for an existing file which then can be closed', function() + itp('returns a non-negative file descriptor for an existing file which then can be closed', function() local fd = os_open(existing_file, ffi.C.kO_RDWR, 0) assert.is_true(0 <= fd) eq(0, os_close(fd)) @@ -556,7 +569,7 @@ describe('fs function', function() end) describe('os_close', function() - it('returns EBADF for negative file descriptors', function() + itp('returns EBADF for negative file descriptors', function() eq(ffi.C.UV_EBADF, os_close(-1)) eq(ffi.C.UV_EBADF, os_close(-1000)) end) @@ -575,7 +588,7 @@ describe('fs function', function() os.remove(file) end) - it('can read zero bytes from a file', function() + itp('can read zero bytes from a file', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, 0, ''}, {os_read(fd, nil)}) @@ -583,7 +596,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can read from a file multiple times', function() + itp('can read from a file multiple times', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, 2, '\000\001'}, {os_read(fd, 2)}) @@ -591,7 +604,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can read the whole file at once and then report eof', function() + itp('can read the whole file at once and then report eof', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, #fcontents, fcontents}, {os_read(fd, #fcontents)}) @@ -599,7 +612,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can read the whole file in two calls, one partially', function() + itp('can read the whole file in two calls, one partially', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, #fcontents * 3/4, fcontents:sub(1, #fcontents * 3/4)}, @@ -629,7 +642,7 @@ describe('fs function', function() os.remove(file) end) - it('can read zero bytes from a file', function() + itp('can read zero bytes from a file', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, 0, {}}, {os_readv(fd, {})}) @@ -637,7 +650,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can read from a file multiple times to a differently-sized buffers', function() + itp('can read from a file multiple times to a differently-sized buffers', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, 2, {'\000\001'}}, {os_readv(fd, {2})}) @@ -645,7 +658,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can read the whole file at once and then report eof', function() + itp('can read the whole file at once and then report eof', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, @@ -662,7 +675,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can read the whole file in two calls, one partially', function() + itp('can read the whole file in two calls, one partially', function() local fd = os_open(file, ffi.C.kO_RDONLY, 0) ok(fd >= 0) eq({false, #fcontents * 3/4, {fcontents:sub(1, #fcontents * 3/4)}}, @@ -689,7 +702,7 @@ describe('fs function', function() os.remove(file) end) - it('can write zero bytes to a file', function() + itp('can write zero bytes to a file', function() local fd = os_open(file, ffi.C.kO_WRONLY, 0) ok(fd >= 0) eq(0, os_write(fd, '')) @@ -698,7 +711,7 @@ describe('fs function', function() eq(0, os_close(fd)) end) - it('can write some data to a file', function() + itp('can write some data to a file', function() local fd = os_open(file, ffi.C.kO_WRONLY, 0) ok(fd >= 0) eq(3, os_write(fd, 'abc')) @@ -713,11 +726,11 @@ describe('fs function', function() os.remove('non-existing-file') end) - it('returns NODE_NORMAL for non-existing file', function() + itp('returns NODE_NORMAL for non-existing file', function() eq(NODE_NORMAL, fs.os_nodetype(to_cstr('non-existing-file'))) end) - it('returns NODE_WRITABLE for /dev/stderr', function() + itp('returns NODE_WRITABLE for /dev/stderr', function() eq(NODE_WRITABLE, fs.os_nodetype(to_cstr('/dev/stderr'))) end) end) @@ -743,12 +756,12 @@ describe('fs function', function() end describe('os_mkdir', function() - it('returns non-zero when given an already existing directory', function() + itp('returns non-zero when given an already existing directory', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR neq(0, (os_mkdir('unit-test-directory', mode))) end) - it('creates a directory and returns 0', function() + itp('creates a directory and returns 0', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR eq(false, (os_isdir('unit-test-directory/new-dir'))) eq(0, (os_mkdir('unit-test-directory/new-dir', mode))) @@ -758,14 +771,14 @@ describe('fs function', function() end) describe('os_mkdir_recurse', function() - it('returns zero when given an already existing directory', function() + itp('returns zero when given an already existing directory', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse('unit-test-directory', mode) eq(0, ret) eq(nil, failed_str) end) - it('fails to create a directory where there is a file', function() + itp('fails to create a directory where there is a file', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse( 'unit-test-directory/test.file', mode) @@ -773,7 +786,7 @@ describe('fs function', function() eq('unit-test-directory/test.file', failed_str) end) - it('fails to create a directory where there is a file in path', function() + itp('fails to create a directory where there is a file in path', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse( 'unit-test-directory/test.file/test', mode) @@ -781,7 +794,7 @@ describe('fs function', function() eq('unit-test-directory/test.file', failed_str) end) - it('succeeds to create a directory', function() + itp('succeeds to create a directory', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse', mode) @@ -792,7 +805,7 @@ describe('fs function', function() eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) - it('succeeds to create a directory ending with ///', function() + itp('succeeds to create a directory ending with ///', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse///', mode) @@ -803,7 +816,7 @@ describe('fs function', function() eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) - it('succeeds to create a directory ending with /', function() + itp('succeeds to create a directory ending with /', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse/', mode) @@ -814,7 +827,7 @@ describe('fs function', function() eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) - it('succeeds to create a directory tree', function() + itp('succeeds to create a directory tree', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR local ret, failed_str = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse/1/2/3', mode) @@ -833,11 +846,11 @@ describe('fs function', function() end) describe('os_rmdir', function() - it('returns non_zero when given a non-existing directory', function() + itp('returns non_zero when given a non-existing directory', function() neq(0, (os_rmdir('non-existing-directory'))) end) - it('removes the given directory and returns 0', function() + itp('removes the given directory and returns 0', function() lfs.mkdir('unit-test-directory/new-dir') eq(0, os_rmdir('unit-test-directory/new-dir')) eq(false, (os_isdir('unit-test-directory/new-dir'))) @@ -865,19 +878,24 @@ describe('fs function', function() end describe('os_fileinfo', function() - it('returns false if given a non-existing file', function() + itp('returns false if path=NULL', function() + local file_info = file_info_new() + assert.is_false((fs.os_fileinfo(nil, file_info))) + end) + + itp('returns false if given a non-existing file', function() local file_info = file_info_new() assert.is_false((fs.os_fileinfo('/non-existent', file_info))) end) - it('returns true if given an existing file and fills file_info', function() + itp('returns true if given an existing file and fills file_info', function() local file_info = file_info_new() local path = 'unit-test-directory/test.file' assert.is_true((fs.os_fileinfo(path, file_info))) assert.is_true((is_file_info_filled(file_info))) end) - it('returns the file info of the linked file, not the link', function() + itp('returns the file info of the linked file, not the link', function() local file_info = file_info_new() local path = 'unit-test-directory/test_link.file' assert.is_true((fs.os_fileinfo(path, file_info))) @@ -888,19 +906,19 @@ describe('fs function', function() end) describe('os_fileinfo_link', function() - it('returns false if given a non-existing file', function() + itp('returns false if given a non-existing file', function() local file_info = file_info_new() assert.is_false((fs.os_fileinfo_link('/non-existent', file_info))) end) - it('returns true if given an existing file and fills file_info', function() + itp('returns true if given an existing file and fills file_info', function() local file_info = file_info_new() local path = 'unit-test-directory/test.file' assert.is_true((fs.os_fileinfo_link(path, file_info))) assert.is_true((is_file_info_filled(file_info))) end) - it('returns the file info of the link, not the linked file', function() + itp('returns the file info of the link, not the linked file', function() local file_info = file_info_new() local path = 'unit-test-directory/test_link.file' assert.is_true((fs.os_fileinfo_link(path, file_info))) @@ -911,12 +929,12 @@ describe('fs function', function() end) describe('os_fileinfo_fd', function() - it('returns false if given an invalid file descriptor', function() + itp('returns false if given an invalid file descriptor', function() local file_info = file_info_new() assert.is_false((fs.os_fileinfo_fd(-1, file_info))) end) - it('returns true if given a file descriptor and fills file_info', function() + itp('returns true if given a file descriptor and fills file_info', function() local file_info = file_info_new() local path = 'unit-test-directory/test.file' local fd = ffi.C.open(path, 0) @@ -927,7 +945,7 @@ describe('fs function', function() end) describe('os_fileinfo_id_equal', function() - it('returns false if file infos represent different files', function() + itp('returns false if file infos represent different files', function() local file_info_1 = file_info_new() local file_info_2 = file_info_new() local path_1 = 'unit-test-directory/test.file' @@ -937,7 +955,7 @@ describe('fs function', function() assert.is_false((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) end) - it('returns true if file infos represent the same file', function() + itp('returns true if file infos represent the same file', function() local file_info_1 = file_info_new() local file_info_2 = file_info_new() local path = 'unit-test-directory/test.file' @@ -946,7 +964,7 @@ describe('fs function', function() assert.is_true((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) end) - it('returns true if file infos represent the same file (symlink)', function() + itp('returns true if file infos represent the same file (symlink)', function() local file_info_1 = file_info_new() local file_info_2 = file_info_new() local path_1 = 'unit-test-directory/test.file' @@ -958,7 +976,7 @@ describe('fs function', function() end) describe('os_fileinfo_id', function() - it('extracts ino/dev from file_info into file_id', function() + itp('extracts ino/dev from file_info into file_id', function() local file_info = file_info_new() local file_id = file_id_new() local path = 'unit-test-directory/test.file' @@ -970,7 +988,7 @@ describe('fs function', function() end) describe('os_fileinfo_inode', function() - it('returns the inode from file_info', function() + itp('returns the inode from file_info', function() local file_info = file_info_new() local path = 'unit-test-directory/test.file' assert.is_true((fs.os_fileinfo(path, file_info))) @@ -980,7 +998,7 @@ describe('fs function', function() end) describe('os_fileinfo_size', function() - it('returns the correct size of a file', function() + itp('returns the correct size of a file', function() local path = 'unit-test-directory/test.file' local file = io.open(path, 'w') file:write('some bytes to get filesize != 0') @@ -994,7 +1012,7 @@ describe('fs function', function() end) describe('os_fileinfo_hardlinks', function() - it('returns the correct number of hardlinks', function() + itp('returns the correct number of hardlinks', function() local path = 'unit-test-directory/test.file' local path_link = 'unit-test-directory/test_hlink.file' local file_info = file_info_new() @@ -1007,7 +1025,7 @@ describe('fs function', function() end) describe('os_fileinfo_blocksize', function() - it('returns the correct blocksize of a file', function() + itp('returns the correct blocksize of a file', function() local path = 'unit-test-directory/test.file' -- there is a bug in luafilesystem where -- `lfs.attributes path, 'blksize'` returns the worng value: @@ -1028,12 +1046,12 @@ describe('fs function', function() end) describe('os_fileid', function() - it('returns false if given an non-existing file', function() + itp('returns false if given an non-existing file', function() local file_id = file_id_new() assert.is_false((fs.os_fileid('/non-existent', file_id))) end) - it('returns true if given an existing file and fills file_id', function() + itp('returns true if given an existing file and fills file_id', function() local file_id = file_id_new() local path = 'unit-test-directory/test.file' assert.is_true((fs.os_fileid(path, file_id))) @@ -1043,14 +1061,14 @@ describe('fs function', function() end) describe('os_fileid_equal', function() - it('returns true if two FileIDs are equal', function() + itp('returns true if two FileIDs are equal', function() local file_id = file_id_new() local path = 'unit-test-directory/test.file' assert.is_true((fs.os_fileid(path, file_id))) assert.is_true((fs.os_fileid_equal(file_id, file_id))) end) - it('returns false if two FileIDs are not equal', function() + itp('returns false if two FileIDs are not equal', function() local file_id_1 = file_id_new() local file_id_2 = file_id_new() local path_1 = 'unit-test-directory/test.file' @@ -1062,7 +1080,7 @@ describe('fs function', function() end) describe('os_fileid_equal_fileinfo', function() - it('returns true if file_id and file_info represent the same file', function() + itp('returns true if file_id and file_info represent the same file', function() local file_id = file_id_new() local file_info = file_info_new() local path = 'unit-test-directory/test.file' @@ -1071,7 +1089,7 @@ describe('fs function', function() assert.is_true((fs.os_fileid_equal_fileinfo(file_id, file_info))) end) - it('returns false if file_id and file_info represent different files', function() + itp('returns false if file_id and file_info represent different files', function() local file_id = file_id_new() local file_info = file_info_new() local path_1 = 'unit-test-directory/test.file' |