diff options
author | Thomas Wienecke <wienecke.t@gmail.com> | 2014-03-04 15:03:46 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-05 15:01:19 -0300 |
commit | 1e5a6acebd9f4c5fec9f31a9b7863fc90167a648 (patch) | |
tree | ccd2e5a5b94eec1007d5f3af92c4cfa1fad6640e | |
parent | 71ff9337d9338864bb3ea178dd869b73ede72f4b (diff) | |
download | rneovim-1e5a6acebd9f4c5fec9f31a9b7863fc90167a648.tar.gz rneovim-1e5a6acebd9f4c5fec9f31a9b7863fc90167a648.tar.bz2 rneovim-1e5a6acebd9f4c5fec9f31a9b7863fc90167a648.zip |
Add unit tests for executable_file and mch_can_exe.
Caution: There is a pending test which should be implemented.
-rw-r--r-- | test/unit/os_unix.moon | 96 |
1 files changed, 80 insertions, 16 deletions
diff --git a/test/unit/os_unix.moon b/test/unit/os_unix.moon index 2e817673a4..1b4f56b929 100644 --- a/test/unit/os_unix.moon +++ b/test/unit/os_unix.moon @@ -1,26 +1,44 @@ -{:cimport, :eq, :ffi} = require 'test.unit.helpers' +{:cimport, :eq, :ffi, :lib, :cstr} = require 'test.unit.helpers' -cstr = ffi.typeof 'char[?]' -os = cimport './src/os_unix.h' +-- os = cimport './src/os_unix.h' +os = lib +ffi.cdef [[ +enum BOOLEAN { + TRUE = 1, FALSE = 0 +}; +int mch_isdir(char_u * name); +int executable_file(char_u *name); +int mch_can_exe(char_u *name); +]] + +{:TRUE, :FALSE} = lib describe 'os_unix function', -> - describe 'mch_isdir', -> - TRUE = 1 - FALSE = 0 + setup -> + lfs.mkdir 'unit-test-directory' + lfs.touch 'unit-test-directory/test.file' + + -- Since the tests are executed, they are called by an executable. We use + -- that to unit test several functions. + 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, '/') + string.match(absolute_executable, '^(.*)/(.*)$') + else + string.match(absolute_executable, '^(.*)\\(.*)$') + + package.path = package.path .. ';' .. directory - ffi.cdef('int mch_isdir(char * name);') + teardown -> + lfs.rmdir 'unit-test-directory' + describe 'mch_isdir', -> mch_isdir = (name) -> name = cstr (string.len name), name os.mch_isdir(name) - setup -> - lfs.mkdir 'empty-test-directory' - lfs.touch 'empty-test-directory/test.file' - - teardown -> - lfs.rmdir 'empty-test-directory' - it 'returns false if an empty string is given', -> eq FALSE, (mch_isdir '') @@ -36,5 +54,51 @@ describe 'os_unix function', -> it 'returns true if the parent directory is given', -> eq TRUE, (mch_isdir '..') - it 'returns true if an newly created directory is given', -> - eq TRUE, (mch_isdir 'empty-test-directory') + it 'returns true if an arbitrary directory is given', -> + eq TRUE, (mch_isdir 'unit-test-directory') + + describe 'executable_file', -> + executable_file = (name) -> + name = cstr (string.len name), name + os.executable_file name + + it 'returns false when given a directory', -> + eq FALSE, (executable_file 'unit-test-directory') + + it 'returns false when the given file does not exists', -> + eq FALSE, (executable_file 'does-not-exist.file') + + it 'returns true when given an executable regular file', -> + eq TRUE, (executable_file 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 + -- Windows. This test must probably differentiate between Windows and + -- other systems, which have an executable bit. + pending 'Test executable_file with a regular file which is not + executable. Need a solution which also works on Windows.' + + describe 'mch_can_exe', -> + mch_can_exe = (name) -> + name = cstr (string.len name), name + os.mch_can_exe name + + it 'returns false when given a directory', -> + eq FALSE, (mch_can_exe 'unit-test-directory') + + 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) + + it 'returns true when given an executable relative to the current dir', -> + old_dir = lfs.currentdir! + lfs.chdir directory + relative_executable = './' .. executable + eq TRUE, (mch_can_exe relative_executable) + lfs.chdir old_dir |