test: no longer define ad-hoc C headers

With the improved cimport helper, we can just load what we want.
This commit is contained in:
Nicolas Hillegeer
2014-04-28 14:17:06 +02:00
committed by Thiago de Arruda
parent d699ccfb0c
commit 9e04e81ac7
4 changed files with 9 additions and 71 deletions

View File

@@ -1,16 +1,7 @@
{:cimport, :internalize, :eq, :ffi, :lib, :cstr, :to_cstr} = require 'test.unit.helpers'
require 'lfs'
-- fs = cimport './src/os/os.h'
-- remove these statements once 'cimport' is working properly for misc1.h
env = lib
ffi.cdef [[
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);
long os_get_pid(void);
void os_get_hostname(char *hostname, size_t len);
]]
env = cimport './src/os/os.h'
NULL = ffi.cast 'void*', 0
@@ -86,7 +77,7 @@ describe 'env function', ->
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
-- 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

View File

@@ -2,30 +2,11 @@
require 'lfs'
require 'bit'
-- fs = cimport './src/os/os.h'
-- remove these statements once 'cimport' is working properly for misc1.h
fs = lib
ffi.cdef [[
enum OKFAIL {
OK = 1, FAIL = 0
};
int os_dirname(char_u *buf, int len);
bool os_isdir(char_u * name);
bool is_executable(char_u *name);
bool os_can_exe(char_u *name);
int32_t os_getperm(char_u *name);
int os_setperm(char_u *name, long perm);
bool os_file_exists(const char_u *name);
bool os_file_is_readonly(char *fname);
int os_file_is_writable(const char *name);
int os_rename(const char_u *path, const char_u *new_path);
int os_mkdir(const char *path, int32_t mode);
int os_rmdir(const char *path);
int os_remove(const char *path);
]]
fs = cimport './src/os/os.h'
-- import constants parsed by ffi
{:OK, :FAIL} = lib
-- TODO(aktau): define these constants "better"
FAIL = 0
OK = 1
cppimport 'sys/stat.h'
@@ -65,8 +46,6 @@ describe 'fs function', ->
eq FAIL, (os_dirname buf, (len-1))
describe 'path_full_dir_name', ->
ffi.cdef 'int path_full_dir_name(char *directory, char *buffer, int len);'
path_full_dir_name = (directory, buffer, len) ->
directory = to_cstr directory
fs.path_full_dir_name directory, buffer, len
@@ -262,7 +241,7 @@ describe 'fs function', ->
it 'fail if source file does not exist', ->
eq FAIL, (os_rename not_exist, test)
it 'can overwrite destination file if it exists', ->
other = 'unit-test-directory/other.file'
file = io.open other, 'w'

View File

@@ -1,22 +1,6 @@
{:cimport, :internalize, :eq, :ffi, :lib, :cstr} = require 'test.unit.helpers'
-- fs = cimport './src/os/os.h'
-- remove these statements once 'cimport' is working properly for misc1.h
users = lib
ffi.cdef [[
typedef struct growarray {
int ga_len;
int ga_maxlen;
int ga_itemsize;
int ga_growsize;
void *ga_data;
} garray_T;
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);
]]
users = cimport './src/os/os.h', 'unistd.h'
NULL = ffi.cast 'void*', 0
OK = 1

View File

@@ -1,17 +1,7 @@
{:cimport, :internalize, :eq, :neq, :ffi, :lib, :cstr, :to_cstr} = require 'test.unit.helpers'
require 'lfs'
path = lib
ffi.cdef [[
typedef enum file_comparison {
kEqualFiles = 1, kDifferentFiles = 2, kBothFilesMissing = 4, kOneFileMissing = 6, kEqualFileNames = 7
} FileComparison;
FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname);
char_u *path_tail(char_u *fname);
char_u *path_tail_with_sep(char_u *fname);
char_u *path_next_component(char_u *fname);
]]
path = cimport './src/path.h'
-- import constants parsed by ffi
{:kEqualFiles, :kDifferentFiles, :kBothFilesMissing, :kOneFileMissing, :kEqualFileNames} = path
@@ -120,8 +110,6 @@ describe 'more path function', ->
lfs.rmdir 'unit-test-directory'
describe 'vim_FullName', ->
ffi.cdef 'int vim_FullName(char *fname, char *buf, int len, int force);'
vim_FullName = (filename, buffer, length, force) ->
filename = to_cstr filename
path.vim_FullName filename, buffer, length, force
@@ -209,8 +197,6 @@ describe 'more path function', ->
eq OK, result
describe 'append_path', ->
ffi.cdef 'int append_path(char *path, char *to_append, int max_len);'
it 'joins given paths with a slash', ->
path1 = cstr 100, 'path1'
to_append = to_cstr 'path2'
@@ -247,8 +233,6 @@ describe 'more path function', ->
eq '/path2', (ffi.string path1)
describe 'path_is_absolute_path', ->
ffi.cdef 'int path_is_absolute_path(char *fname);'
path_is_absolute_path = (filename) ->
filename = to_cstr filename
path.path_is_absolute_path filename