diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-07-16 17:07:58 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-07-16 17:07:58 -0400 |
commit | 0897277af8ef283e5a6f28d69cf21a3d22e5b8b2 (patch) | |
tree | 47a2797793b037e5badc28a7332c3a4ec314466c /test | |
parent | 90a206d3321dcf8b1ad362501cada5e80135891c (diff) | |
parent | 7c6079f6f0d0fc59dd747c2ecd9e1e1ca1e0e66d (diff) | |
download | rneovim-0897277af8ef283e5a6f28d69cf21a3d22e5b8b2.tar.gz rneovim-0897277af8ef283e5a6f28d69cf21a3d22e5b8b2.tar.bz2 rneovim-0897277af8ef283e5a6f28d69cf21a3d22e5b8b2.zip |
Merge pull request #941 from aktau/improve-luajit-ffi-preproc
refactor includes + improve testing infrastructure
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/helpers.moon | 12 | ||||
-rw-r--r-- | test/unit/os/fs_spec.moon | 31 | ||||
-rw-r--r-- | test/unit/path_spec.moon | 37 | ||||
-rw-r--r-- | test/unit/preprocess.moon | 2 |
4 files changed, 51 insertions, 31 deletions
diff --git a/test/unit/helpers.moon b/test/unit/helpers.moon index 84dfeb20e9..438f36811c 100644 --- a/test/unit/helpers.moon +++ b/test/unit/helpers.moon @@ -97,6 +97,17 @@ cstr = ffi.typeof 'char[?]' to_cstr = (string) -> cstr (string.len string) + 1, string +export vim_init_called +-- initialize some global variables, this is still necessary to unit test +-- functions that rely on global state. +vim_init = -> + if vim_init_called ~= nil + return + -- import os_unix.h for mch_early_init(), which initializes some globals + os = cimport './src/nvim/os_unix.h' + os.mch_early_init! + vim_init_called = true + return { cimport: cimport cppimport: cppimport @@ -107,4 +118,5 @@ return { lib: libnvim cstr: cstr to_cstr: to_cstr + vim_init: vim_init } diff --git a/test/unit/os/fs_spec.moon b/test/unit/os/fs_spec.moon index a1445aeb0c..6d87cb95df 100644 --- a/test/unit/os/fs_spec.moon +++ b/test/unit/os/fs_spec.moon @@ -57,37 +57,6 @@ describe 'fs function', -> buf = cstr (len-1), '' eq FAIL, (os_dirname buf, (len-1)) - describe 'path_full_dir_name', -> - path_full_dir_name = (directory, buffer, len) -> - directory = to_cstr directory - fs.path_full_dir_name directory, buffer, len - - before_each -> - -- Create empty string buffer which will contain the resulting path. - export len = (string.len lfs.currentdir!) + 22 - export buffer = cstr len, '' - - it 'returns the absolute directory name of a given relative one', -> - result = path_full_dir_name '..', buffer, len - eq OK, result - old_dir = lfs.currentdir! - lfs.chdir '..' - expected = lfs.currentdir! - lfs.chdir old_dir - eq expected, (ffi.string buffer) - - it 'returns the current directory name if the given string is empty', -> - eq OK, (path_full_dir_name '', buffer, len) - eq lfs.currentdir!, (ffi.string buffer) - - it 'fails if the given directory does not exist', -> - eq FAIL, path_full_dir_name('does_not_exist', buffer, len) - - it 'works with a normal relative dir', -> - result = path_full_dir_name('unit-test-directory', buffer, len) - eq lfs.currentdir! .. '/unit-test-directory', (ffi.string buffer) - eq OK, result - os_isdir = (name) -> fs.os_isdir (to_cstr name) diff --git a/test/unit/path_spec.moon b/test/unit/path_spec.moon index 762bad09a2..4a4170e463 100644 --- a/test/unit/path_spec.moon +++ b/test/unit/path_spec.moon @@ -10,6 +10,43 @@ OK = 1 FAIL = 0 describe 'path function', -> + describe 'path_full_dir_name', -> + setup -> + lfs.mkdir 'unit-test-directory' + + teardown -> + lfs.rmdir 'unit-test-directory' + + path_full_dir_name = (directory, buffer, len) -> + directory = to_cstr directory + path.path_full_dir_name directory, buffer, len + + before_each -> + -- Create empty string buffer which will contain the resulting path. + export len = (string.len lfs.currentdir!) + 22 + export buffer = cstr len, '' + + it 'returns the absolute directory name of a given relative one', -> + result = path_full_dir_name '..', buffer, len + eq OK, result + old_dir = lfs.currentdir! + lfs.chdir '..' + expected = lfs.currentdir! + lfs.chdir old_dir + eq expected, (ffi.string buffer) + + it 'returns the current directory name if the given string is empty', -> + eq OK, (path_full_dir_name '', buffer, len) + eq lfs.currentdir!, (ffi.string buffer) + + it 'fails if the given directory does not exist', -> + eq FAIL, path_full_dir_name('does_not_exist', buffer, len) + + it 'works with a normal relative dir', -> + result = path_full_dir_name('unit-test-directory', buffer, len) + eq lfs.currentdir! .. '/unit-test-directory', (ffi.string buffer) + eq OK, result + describe 'path_full_compare', -> path_full_compare = (s1, s2, cn) -> diff --git a/test/unit/preprocess.moon b/test/unit/preprocess.moon index aa74b8ce24..cb734da2f7 100644 --- a/test/unit/preprocess.moon +++ b/test/unit/preprocess.moon @@ -85,6 +85,8 @@ class Gcc '-D "__asm(ARGS)="', '-D "__asm__(ARGS)="', '-D "__inline__="', + '-D "EXTERN=extern"', + '-D "INIT(...)="', '-D_GNU_SOURCE', '-DINCLUDE_GENERATED_DECLARATIONS' } |