diff options
author | Thomas Wienecke <wienecke.t@gmail.com> | 2014-03-27 12:38:33 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-27 19:57:55 -0300 |
commit | 5762c4e528cbd6629319bf3958d1f6554b399b20 (patch) | |
tree | 3be91959012944534451ec84584ff4be84286b7c /test | |
parent | 3f7011ab9185b4968e89086f77b054161a900beb (diff) | |
download | rneovim-5762c4e528cbd6629319bf3958d1f6554b399b20.tar.gz rneovim-5762c4e528cbd6629319bf3958d1f6554b399b20.tar.bz2 rneovim-5762c4e528cbd6629319bf3958d1f6554b399b20.zip |
Rename mch_* functions to os_* in os module.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/os/env.moon | 48 | ||||
-rw-r--r-- | test/unit/os/fs.moon | 142 | ||||
-rw-r--r-- | test/unit/os/time.moon | 8 | ||||
-rw-r--r-- | test/unit/os/users.moon | 32 |
4 files changed, 115 insertions, 115 deletions
diff --git a/test/unit/os/env.moon b/test/unit/os/env.moon index 007a9beaff..1f1692859b 100644 --- a/test/unit/os/env.moon +++ b/test/unit/os/env.moon @@ -5,26 +5,26 @@ require 'lfs' -- remove these statements once 'cimport' is working properly for misc1.h env = lib ffi.cdef [[ -const char *mch_getenv(const char *name); -int mch_setenv(const char *name, const char *value, int override); -char *mch_getenvname_at_index(size_t index); +const char *os_getenv(const char *name); +int os_setenv(const char *name, const char *value, int override); +char *os_getenvname_at_index(size_t index); ]] NULL = ffi.cast 'void*', 0 describe 'env function', -> - mch_setenv = (name, value, override) -> - env.mch_setenv (to_cstr name), (to_cstr value), override + os_setenv = (name, value, override) -> + env.os_setenv (to_cstr name), (to_cstr value), override - mch_getenv = (name) -> - rval = env.mch_getenv (to_cstr name) + os_getenv = (name) -> + rval = env.os_getenv (to_cstr name) if rval != NULL ffi.string rval else NULL - describe 'mch_setenv', -> + describe 'os_setenv', -> OK = 0 @@ -32,48 +32,48 @@ describe 'env function', -> name = 'NEOVIM_UNIT_TEST_SETENV_1N' value = 'NEOVIM_UNIT_TEST_SETENV_1V' eq nil, os.getenv name - eq OK, (mch_setenv name, value, 1) + eq OK, (os_setenv name, value, 1) eq value, os.getenv name it "dosn't overwrite an env variable if overwrite is 0", -> name = 'NEOVIM_UNIT_TEST_SETENV_2N' value = 'NEOVIM_UNIT_TEST_SETENV_2V' value_updated = 'NEOVIM_UNIT_TEST_SETENV_2V_UPDATED' - eq OK, (mch_setenv name, value, 0) + eq OK, (os_setenv name, value, 0) eq value, os.getenv name - eq OK, (mch_setenv name, value_updated, 0) + eq OK, (os_setenv name, value_updated, 0) eq value, os.getenv name - describe 'mch_getenv', -> + describe 'os_getenv', -> it 'reads an env variable', -> name = 'NEOVIM_UNIT_TEST_GETENV_1N' value = 'NEOVIM_UNIT_TEST_GETENV_1V' - eq NULL, mch_getenv name - -- need to use mch_setenv, because lua dosn't have a setenv function - mch_setenv name, value, 1 - eq value, mch_getenv name + eq NULL, os_getenv name + -- need to use os_setenv, because lua dosn't have a setenv function + os_setenv name, value, 1 + eq value, os_getenv name it 'returns NULL if the env variable is not found', -> name = 'NEOVIM_UNIT_TEST_GETENV_NOTFOUND' - eq NULL, mch_getenv name + eq NULL, os_getenv name - describe 'mch_getenvname_at_index', -> + describe 'os_getenvname_at_index', -> it 'returns names of environment variables', -> test_name = 'NEOVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1N' test_value = 'NEOVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1V' - mch_setenv test_name, test_value, 1 + os_setenv test_name, test_value, 1 i = 0 names = {} found_name = false - name = env.mch_getenvname_at_index i + name = env.os_getenvname_at_index i while name != NULL table.insert names, ffi.string name if (ffi.string name) == test_name found_name = true i += 1 - name = env.mch_getenvname_at_index i + name = env.os_getenvname_at_index i eq true, (table.getn names) > 0 eq true, found_name @@ -81,12 +81,12 @@ describe 'env function', -> it 'returns NULL if the index is out of bounds', -> huge = ffi.new 'size_t', 10000 maxuint32 = ffi.new 'size_t', 4294967295 - eq NULL, env.mch_getenvname_at_index huge - eq NULL, env.mch_getenvname_at_index maxuint32 + eq NULL, env.os_getenvname_at_index huge + eq NULL, env.os_getenvname_at_index maxuint32 if ffi.abi '64bit' -- couldn't use a bigger number because it gets converted to -- double somewere, should be big enough anyway -- maxuint64 = ffi.new 'size_t', 18446744073709551615 maxuint64 = ffi.new 'size_t', 18446744073709000000 - eq NULL, env.mch_getenvname_at_index maxuint64 + eq NULL, env.os_getenvname_at_index maxuint64 diff --git a/test/unit/os/fs.moon b/test/unit/os/fs.moon index 30e6abb31c..5d88b5cdb8 100644 --- a/test/unit/os/fs.moon +++ b/test/unit/os/fs.moon @@ -12,12 +12,12 @@ enum OKFAIL { enum BOOLEAN { TRUE = 1, FALSE = 0 }; -int mch_dirname(char_u *buf, int len); -int mch_isdir(char_u * name); +int os_dirname(char_u *buf, int len); +int os_isdir(char_u * name); int is_executable(char_u *name); -int mch_can_exe(char_u *name); -long mch_getperm(char_u *name); -int mch_setperm(char_u *name, long perm); +int os_can_exe(char_u *name); +long os_getperm(char_u *name); +int os_setperm(char_u *name, long perm); int os_file_exists(const char_u *name); ]] @@ -44,9 +44,9 @@ describe 'fs function', -> os.remove 'unit-test-directory/test.file' lfs.rmdir 'unit-test-directory' - describe 'mch_dirname', -> - mch_dirname = (buf, len) -> - fs.mch_dirname buf, len + describe 'os_dirname', -> + os_dirname = (buf, len) -> + fs.os_dirname buf, len before_each -> export len = (string.len lfs.currentdir!) + 1 @@ -54,20 +54,20 @@ describe 'fs function', -> it 'returns OK and writes current directory into the buffer if it is large enough', -> - eq OK, (mch_dirname buf, len) + eq OK, (os_dirname buf, len) eq lfs.currentdir!, (ffi.string buf) -- What kind of other failing cases are possible? it 'returns FAIL if the buffer is too small', -> buf = cstr (len-1), '' - eq FAIL, (mch_dirname buf, (len-1)) + eq FAIL, (os_dirname buf, (len-1)) - describe 'mch_full_dir_name', -> - ffi.cdef 'int mch_full_dir_name(char *directory, char *buffer, int len);' + describe 'os_full_dir_name', -> + ffi.cdef 'int os_full_dir_name(char *directory, char *buffer, int len);' - mch_full_dir_name = (directory, buffer, len) -> + os_full_dir_name = (directory, buffer, len) -> directory = to_cstr directory - fs.mch_full_dir_name directory, buffer, len + fs.os_full_dir_name directory, buffer, len before_each -> -- Create empty string buffer which will contain the resulting path. @@ -75,7 +75,7 @@ describe 'fs function', -> export buffer = cstr len, '' it 'returns the absolute directory name of a given relative one', -> - result = mch_full_dir_name '..', buffer, len + result = os_full_dir_name '..', buffer, len eq OK, result old_dir = lfs.currentdir! lfs.chdir '..' @@ -84,23 +84,23 @@ describe 'fs function', -> eq expected, (ffi.string buffer) it 'returns the current directory name if the given string is empty', -> - eq OK, (mch_full_dir_name '', buffer, len) + eq OK, (os_full_dir_name '', buffer, len) eq lfs.currentdir!, (ffi.string buffer) it 'fails if the given directory does not exist', -> - eq FAIL, mch_full_dir_name('does_not_exist', buffer, len) + eq FAIL, os_full_dir_name('does_not_exist', buffer, len) it 'works with a normal relative dir', -> - result = mch_full_dir_name('unit-test-directory', buffer, len) + result = os_full_dir_name('unit-test-directory', buffer, len) eq lfs.currentdir! .. '/unit-test-directory', (ffi.string buffer) eq OK, result - describe 'mch_get_absolute_path', -> - ffi.cdef 'int mch_get_absolute_path(char *fname, char *buf, int len, int force);' + describe 'os_get_absolute_path', -> + ffi.cdef 'int os_get_absolute_path(char *fname, char *buf, int len, int force);' - mch_get_absolute_path = (filename, buffer, length, force) -> + os_get_absolute_path = (filename, buffer, length, force) -> filename = to_cstr filename - fs.mch_get_absolute_path filename, buffer, length, force + fs.os_get_absolute_path filename, buffer, length, force before_each -> -- Create empty string buffer which will contain the resulting path. @@ -109,12 +109,12 @@ describe 'fs function', -> it 'fails if given filename contains non-existing directory', -> force_expansion = 1 - result = mch_get_absolute_path 'non_existing_dir/test.file', buffer, len, force_expansion + result = os_get_absolute_path 'non_existing_dir/test.file', buffer, len, force_expansion eq FAIL, result it 'concatenates given filename if it does not contain a slash', -> force_expansion = 1 - result = mch_get_absolute_path 'test.file', buffer, len, force_expansion + result = os_get_absolute_path 'test.file', buffer, len, force_expansion expected = lfs.currentdir! .. '/test.file' eq expected, (ffi.string buffer) eq OK, result @@ -122,7 +122,7 @@ describe 'fs function', -> it 'concatenates given filename if it is a directory but does not contain a slash', -> force_expansion = 1 - result = mch_get_absolute_path '..', buffer, len, force_expansion + result = os_get_absolute_path '..', buffer, len, force_expansion expected = lfs.currentdir! .. '/..' eq expected, (ffi.string buffer) eq OK, result @@ -132,7 +132,7 @@ describe 'fs function', -> it 'enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', -> force_expansion = 1 - result = mch_get_absolute_path '../test.file', buffer, len, force_expansion + result = os_get_absolute_path '../test.file', buffer, len, force_expansion old_dir = lfs.currentdir! lfs.chdir '..' expected = lfs.currentdir! .. '/test.file' @@ -143,19 +143,19 @@ describe 'fs function', -> it 'just copies the path if it is already absolute and force=0', -> force_expansion = 0 absolute_path = '/absolute/path' - result = mch_get_absolute_path absolute_path, buffer, len, force_expansion + result = os_get_absolute_path absolute_path, buffer, len, force_expansion eq absolute_path, (ffi.string buffer) eq OK, result it 'fails when the path is relative to HOME', -> force_expansion = 1 absolute_path = '~/home.file' - result = mch_get_absolute_path absolute_path, buffer, len, force_expansion + result = os_get_absolute_path absolute_path, buffer, len, force_expansion eq FAIL, result it 'works with some "normal" relative path with directories', -> force_expansion = 1 - result = mch_get_absolute_path 'unit-test-directory/test.file', buffer, len, force_expansion + result = os_get_absolute_path 'unit-test-directory/test.file', buffer, len, force_expansion eq OK, result eq lfs.currentdir! .. '/unit-test-directory/test.file', (ffi.string buffer) @@ -164,7 +164,7 @@ describe 'fs function', -> filename = to_cstr 'unit-test-directory/test.file' -- Don't use the wrapper here but pass a cstring directly to the c -- function. - result = fs.mch_get_absolute_path filename, buffer, len, force_expansion + result = fs.os_get_absolute_path filename, buffer, len, force_expansion eq lfs.currentdir! .. '/unit-test-directory/test.file', (ffi.string buffer) eq 'unit-test-directory/test.file', (ffi.string filename) eq OK, result @@ -207,80 +207,80 @@ describe 'fs function', -> eq OK, (fs.append_path path, to_append, 7) eq '/path2', (ffi.string path) - describe 'mch_is_absolute_path', -> - ffi.cdef 'int mch_is_absolute_path(char *fname);' + describe 'os_is_absolute_path', -> + ffi.cdef 'int os_is_absolute_path(char *fname);' - mch_is_absolute_path = (filename) -> + os_is_absolute_path = (filename) -> filename = to_cstr filename - fs.mch_is_absolute_path filename + fs.os_is_absolute_path filename it 'returns true if filename starts with a slash', -> - eq OK, mch_is_absolute_path '/some/directory/' + eq OK, os_is_absolute_path '/some/directory/' it 'returns true if filename starts with a tilde', -> - eq OK, mch_is_absolute_path '~/in/my/home~/directory' + eq OK, os_is_absolute_path '~/in/my/home~/directory' it 'returns false if filename starts not with slash nor tilde', -> - eq FAIL, mch_is_absolute_path 'not/in/my/home~/directory' + eq FAIL, os_is_absolute_path 'not/in/my/home~/directory' - describe 'mch_isdir', -> - mch_isdir = (name) -> - fs.mch_isdir (to_cstr name) + describe 'os_isdir', -> + os_isdir = (name) -> + fs.os_isdir (to_cstr name) it 'returns false if an empty string is given', -> - eq FALSE, (mch_isdir '') + eq FALSE, (os_isdir '') it 'returns false if a nonexisting directory is given', -> - eq FALSE, (mch_isdir 'non-existing-directory') + eq FALSE, (os_isdir 'non-existing-directory') it 'returns false if a nonexisting absolute directory is given', -> - eq FALSE, (mch_isdir '/non-existing-directory') + eq FALSE, (os_isdir '/non-existing-directory') it 'returns false if an existing file is given', -> - eq FALSE, (mch_isdir 'unit-test-directory/test.file') + eq FALSE, (os_isdir 'unit-test-directory/test.file') it 'returns true if the current directory is given', -> - eq TRUE, (mch_isdir '.') + eq TRUE, (os_isdir '.') it 'returns true if the parent directory is given', -> - eq TRUE, (mch_isdir '..') + eq TRUE, (os_isdir '..') it 'returns true if an arbitrary directory is given', -> - eq TRUE, (mch_isdir 'unit-test-directory') + eq TRUE, (os_isdir 'unit-test-directory') it 'returns true if an absolute directory is given', -> - eq TRUE, (mch_isdir directory) + eq TRUE, (os_isdir directory) - describe 'mch_can_exe', -> - mch_can_exe = (name) -> - fs.mch_can_exe (to_cstr name) + describe 'os_can_exe', -> + os_can_exe = (name) -> + fs.os_can_exe (to_cstr name) it 'returns false when given a directory', -> - eq FALSE, (mch_can_exe './unit-test-directory') + eq FALSE, (os_can_exe './unit-test-directory') it 'returns false when given a regular file without executable bit set', -> - eq FALSE, (mch_can_exe 'unit-test-directory/test.file') + eq FALSE, (os_can_exe 'unit-test-directory/test.file') it 'returns false when the given file does not exists', -> - eq FALSE, (mch_can_exe 'does-not-exist.file') + eq FALSE, (os_can_exe 'does-not-exist.file') it 'returns true when given an executable inside $PATH', -> - eq TRUE, (mch_can_exe executable_name) + eq TRUE, (os_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_name - eq TRUE, (mch_can_exe relative_executable) + eq TRUE, (os_can_exe relative_executable) lfs.chdir old_dir describe 'file permissions', -> - mch_getperm = (filename) -> - perm = fs.mch_getperm (to_cstr filename) + os_getperm = (filename) -> + perm = fs.os_getperm (to_cstr filename) tonumber perm - mch_setperm = (filename, perm) -> - fs.mch_setperm (to_cstr filename), perm + os_setperm = (filename, perm) -> + fs.os_setperm (to_cstr filename), perm bit_set = (number, check_bit) -> if 0 == (bit.band number, check_bit) then false else true @@ -291,36 +291,36 @@ describe 'fs function', -> unset_bit = (number, to_unset) -> return bit.band number, (bit.bnot to_unset) - describe 'mch_getperm', -> + describe 'os_getperm', -> it 'returns -1 when the given file does not exist', -> - eq -1, (mch_getperm 'non-existing-file') + eq -1, (os_getperm 'non-existing-file') it 'returns a perm > 0 when given an existing file', -> - assert.is_true (mch_getperm 'unit-test-directory') > 0 + assert.is_true (os_getperm 'unit-test-directory') > 0 it 'returns S_IRUSR when the file is readable', -> - perm = mch_getperm 'unit-test-directory' + perm = os_getperm 'unit-test-directory' assert.is_true (bit_set perm, ffi.C.kS_IRUSR) - describe 'mch_setperm', -> + describe 'os_setperm', -> it 'can set and unset the executable bit of a file', -> - perm = mch_getperm 'unit-test-directory/test.file' + perm = os_getperm 'unit-test-directory/test.file' perm = unset_bit perm, ffi.C.kS_IXUSR - eq OK, (mch_setperm 'unit-test-directory/test.file', perm) + eq OK, (os_setperm 'unit-test-directory/test.file', perm) - perm = mch_getperm 'unit-test-directory/test.file' + perm = os_getperm 'unit-test-directory/test.file' assert.is_false (bit_set perm, ffi.C.kS_IXUSR) perm = set_bit perm, ffi.C.kS_IXUSR - eq OK, mch_setperm 'unit-test-directory/test.file', perm + eq OK, os_setperm 'unit-test-directory/test.file', perm - perm = mch_getperm 'unit-test-directory/test.file' + perm = os_getperm 'unit-test-directory/test.file' assert.is_true (bit_set perm, ffi.C.kS_IXUSR) it 'fails if given file does not exist', -> perm = ffi.C.kS_IXUSR - eq FAIL, (mch_setperm 'non-existing-file', perm) + eq FAIL, (os_setperm 'non-existing-file', perm) describe 'os_file_exists', -> os_file_exists = (filename) -> diff --git a/test/unit/os/time.moon b/test/unit/os/time.moon index e963f6e253..465630b1da 100644 --- a/test/unit/os/time.moon +++ b/test/unit/os/time.moon @@ -7,12 +7,12 @@ describe 'time function', -> setup -> time.time_init! - describe 'mch_delay', -> - mch_delay = (ms) -> - time.mch_delay ms, false + describe 'os_delay', -> + os_delay = (ms) -> + time.os_delay ms, false it 'sleeps at least the number of requested milliseconds', -> curtime = lua_time! - mch_delay 1000 + os_delay 1000 ellapsed = lua_time! - curtime eq true, ellapsed >= 1 and ellapsed <=2 diff --git a/test/unit/os/users.moon b/test/unit/os/users.moon index 76f51c94f2..bfb52e50e6 100644 --- a/test/unit/os/users.moon +++ b/test/unit/os/users.moon @@ -11,10 +11,10 @@ typedef struct growarray { int ga_growsize; void *ga_data; } garray_T; -int mch_get_usernames(garray_T *usernames); -int mch_get_user_name(char *s, size_t len); -int mch_get_uname(int uid, char *s, size_t len); -char *mch_get_user_directory(const char *name); +int os_get_usernames(garray_T *usernames); +int os_get_user_name(char *s, size_t len); +int os_get_uname(int uid, char *s, size_t len); +char *os_get_user_directory(const char *name); int getuid(void); ]] @@ -37,14 +37,14 @@ describe 'users function', -> -- will probably not work on windows current_username = os.getenv 'USER' - describe 'mch_get_usernames', -> + describe 'os_get_usernames', -> it 'returns FAIL if called with NULL', -> - eq FAIL, users.mch_get_usernames NULL + eq FAIL, users.os_get_usernames NULL it 'fills the names garray with os usernames and returns OK', -> ga_users = garray_new! - eq OK, users.mch_get_usernames ga_users + eq OK, users.os_get_usernames ga_users user_count = garray_get_len ga_users assert.is_true user_count > 0 current_username_found = false @@ -54,37 +54,37 @@ describe 'users function', -> current_username_found = true assert.is_true current_username_found - describe 'mch_get_user_name', -> + describe 'os_get_user_name', -> it 'should write the username into the buffer and return OK', -> name_out = ffi.new 'char[100]' - eq OK, users.mch_get_user_name(name_out, 100) + eq OK, users.os_get_user_name(name_out, 100) eq current_username, ffi.string name_out - describe 'mch_get_uname', -> + describe 'os_get_uname', -> it 'should write the username into the buffer and return OK', -> name_out = ffi.new 'char[100]' user_id = lib.getuid! - eq OK, users.mch_get_uname(user_id, name_out, 100) + eq OK, users.os_get_uname(user_id, name_out, 100) eq current_username, ffi.string name_out it 'should FAIL if the userid is not found', -> name_out = ffi.new 'char[100]' -- hoping nobody has this uid user_id = 2342 - eq FAIL, users.mch_get_uname(user_id, name_out, 100) + eq FAIL, users.os_get_uname(user_id, name_out, 100) eq '2342', ffi.string name_out - describe 'mch_get_user_directory', -> + describe 'os_get_user_directory', -> it 'should return NULL if called with NULL', -> - eq NULL, users.mch_get_user_directory NULL + eq NULL, users.os_get_user_directory NULL it 'should return $HOME for the current user', -> home = os.getenv('HOME') - eq home, ffi.string (users.mch_get_user_directory current_username) + eq home, ffi.string (users.os_get_user_directory current_username) it 'should return NULL if the user is not found', -> - eq NULL, users.mch_get_user_directory 'neovim_user_not_found_test' + eq NULL, users.os_get_user_directory 'neovim_user_not_found_test' |