diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-09-17 01:28:35 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-09-17 01:28:35 -0400 |
commit | a447160a6ca43181158bce8117f2af37f4e9fc85 (patch) | |
tree | fb104bb7b753f26e9927b42f5b7bd39af61240b5 /test | |
parent | 8249e4ac72b54d00addb597a124d0f55566b2466 (diff) | |
parent | 8b3e5829e4902ba214ab3399e97e6a325c625739 (diff) | |
download | rneovim-a447160a6ca43181158bce8117f2af37f4e9fc85.tar.gz rneovim-a447160a6ca43181158bce8117f2af37f4e9fc85.tar.bz2 rneovim-a447160a6ca43181158bce8117f2af37f4e9fc85.zip |
Merge pull request #953 from splinterofchaos/patch235-exepath
vim-patch:7.4.235
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/os/fs_spec.lua | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index 67ca8f6c24..2d54dc6003 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -11,11 +11,16 @@ local cstr = helpers.cstr local to_cstr = helpers.to_cstr local OK = helpers.OK local FAIL = helpers.FAIL +local NULL = helpers.NULL require('lfs') require('bit') cimport('unistd.h') +cimport('./src/nvim/os/shell.h') +cimport('./src/nvim/option_defs.h') +cimport('./src/nvim/os/event.h') +cimport('./src/nvim/fileio.h') local fs = cimport('./src/nvim/os/os.h') cppimport('sys/stat.h') cppimport('sys/fcntl.h') @@ -24,6 +29,7 @@ cppimport('sys/errno.h') local len = 0 local buf = "" local directory = nil +local absolute_executable = nil local executable_name = nil local function assert_file_exists(filepath) @@ -43,7 +49,7 @@ describe('fs function', function() lfs.link('test.file', 'unit-test-directory/test_link.file', true) -- Since the tests are executed, they are called by an executable. We use -- that executable for several asserts. - local absolute_executable = arg[0] + absolute_executable = arg[0] -- Split absolute_executable into a directory and the actual file name for -- later usage. directory, executable_name = string.match(absolute_executable, '^(.*)/(.*)$') @@ -119,31 +125,57 @@ describe('fs function', function() describe('os_can_exe', function() local function os_can_exe(name) - return fs.os_can_exe((to_cstr(name))) + local buf = ffi.new('char *[1]') + buf[0] = NULL + local ok = fs.os_can_exe(to_cstr(name), buf) + + -- When os_can_exe returns true, it must set the path. + -- When it returns false, the path must be NULL. + if ok then + neq(NULL, buf[0]) + return internalize(buf[0]) + else + eq(NULL, buf[0]) + return nil + end + end + + local function cant_exe(name) + eq(nil, os_can_exe(name)) + end + + local function exe(name) + return os_can_exe(name) end it('returns false when given a directory', function() - eq(false, (os_can_exe('./unit-test-directory'))) + cant_exe('./unit-test-directory') end) it('returns false when given a regular file without executable bit set', function() - eq(false, (os_can_exe('unit-test-directory/test.file'))) + cant_exe('unit-test-directory/test.file') end) it('returns false when the given file does not exists', function() - eq(false, (os_can_exe('does-not-exist.file'))) + cant_exe('does-not-exist.file') end) - it('returns true when given an executable inside $PATH', function() - eq(true, (os_can_exe(executable_name))) + 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) end) - it('returns true when given an executable relative to the current dir', function() + it('returns the absolute path when given an executable relative to the current dir', function() local old_dir = lfs.currentdir() lfs.chdir(directory) local relative_executable = './' .. executable_name - eq(true, (os_can_exe(relative_executable))) + -- Don't test yet; we need to chdir back first. + local res = exe(relative_executable) lfs.chdir(old_dir) + eq(absolute_executable, res) end) end) |