mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 18:41:48 +00:00
Move mch_can_exe, executable_file to os/fs.c.
* Rename executable_file to is_executable.
This commit is contained in:
committed by
Thiago de Arruda
parent
1468c12fd1
commit
d5b223afe2
@@ -7,7 +7,7 @@ enum BOOLEAN {
|
||||
TRUE = 1, FALSE = 0
|
||||
};
|
||||
int mch_isdir(char_u * name);
|
||||
int executable_file(char_u *name);
|
||||
int is_executable(char_u *name);
|
||||
int mch_can_exe(char_u *name);
|
||||
]]
|
||||
|
||||
@@ -22,15 +22,13 @@ describe 'os_unix function', ->
|
||||
-- that executable for several asserts.
|
||||
export absolute_executable = arg[0]
|
||||
|
||||
-- Split absolute_executable into a directory and the actual file name and
|
||||
-- append the directory to $PATH.
|
||||
export directory, executable = if (string.find absolute_executable, '/')
|
||||
-- Split absolute_executable into a directory and the actual file name for
|
||||
-- later usage.
|
||||
export directory, executable_name = if (string.find absolute_executable, '/')
|
||||
string.match(absolute_executable, '^(.*)/(.*)$')
|
||||
else
|
||||
string.match(absolute_executable, '^(.*)\\(.*)$')
|
||||
|
||||
package.path = package.path .. ';' .. directory
|
||||
|
||||
teardown ->
|
||||
lfs.rmdir 'unit-test-directory'
|
||||
|
||||
@@ -57,25 +55,25 @@ describe 'os_unix function', ->
|
||||
it 'returns true if an arbitrary directory is given', ->
|
||||
eq TRUE, (mch_isdir 'unit-test-directory')
|
||||
|
||||
describe 'executable_file', ->
|
||||
executable_file = (name) ->
|
||||
describe 'is_executable', ->
|
||||
is_executable = (name) ->
|
||||
name = cstr (string.len name), name
|
||||
os.executable_file name
|
||||
os.is_executable name
|
||||
|
||||
it 'returns false when given a directory', ->
|
||||
eq FALSE, (executable_file 'unit-test-directory')
|
||||
eq FALSE, (is_executable 'unit-test-directory')
|
||||
|
||||
it 'returns false when the given file does not exists', ->
|
||||
eq FALSE, (executable_file 'does-not-exist.file')
|
||||
eq FALSE, (is_executable 'does-not-exist.file')
|
||||
|
||||
it 'returns true when given an executable regular file', ->
|
||||
eq TRUE, (executable_file absolute_executable)
|
||||
eq TRUE, (is_executable absolute_executable)
|
||||
|
||||
it 'returns false when given a regular file without executable bit set', ->
|
||||
-- This is a critical test since Windows does not have any executable
|
||||
-- bit. Thus executable_file returns TRUE on every regular file on
|
||||
-- bit. Thus is_executable returns TRUE on every regular file on
|
||||
-- Windows and this test will fail.
|
||||
eq FALSE, (executable_file 'unit-test-directory/test.file')
|
||||
eq FALSE, (is_executable 'unit-test-directory/test.file')
|
||||
|
||||
describe 'mch_can_exe', ->
|
||||
mch_can_exe = (name) ->
|
||||
@@ -83,23 +81,17 @@ describe 'os_unix function', ->
|
||||
os.mch_can_exe name
|
||||
|
||||
it 'returns false when given a directory', ->
|
||||
eq FALSE, (mch_can_exe 'unit-test-directory')
|
||||
eq FALSE, (mch_can_exe './unit-test-directory')
|
||||
|
||||
it 'returns false when the given file does not exists', ->
|
||||
eq FALSE, (mch_can_exe 'does-not-exist.file')
|
||||
|
||||
it 'returns true when given an executable in the current directory', ->
|
||||
old_dir = lfs.currentdir!
|
||||
lfs.chdir directory
|
||||
eq TRUE, (mch_can_exe executable)
|
||||
lfs.chdir old_dir
|
||||
|
||||
it 'returns true when given an executable inside $PATH', ->
|
||||
eq TRUE, (mch_can_exe executable)
|
||||
eq TRUE, (mch_can_exe executable_name)
|
||||
|
||||
it 'returns true when given an executable relative to the current dir', ->
|
||||
old_dir = lfs.currentdir!
|
||||
lfs.chdir directory
|
||||
relative_executable = './' .. executable
|
||||
relative_executable = './' .. executable_name
|
||||
eq TRUE, (mch_can_exe relative_executable)
|
||||
lfs.chdir old_dir
|
||||
|
||||
Reference in New Issue
Block a user