diff options
author | ZyX <kp-pav@yandex.ru> | 2017-03-11 16:02:47 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-11 23:23:49 +0300 |
commit | e2a578f40dbd4836330402a44844c7ef8a0df5c5 (patch) | |
tree | ab2b04b6d0228e7d5a4ef6d611971f063a17be17 /test/unit/tempfile_spec.lua | |
parent | 9400466282918396c814ef456d0f65dca51b8889 (diff) | |
download | rneovim-e2a578f40dbd4836330402a44844c7ef8a0df5c5.tar.gz rneovim-e2a578f40dbd4836330402a44844c7ef8a0df5c5.tar.bz2 rneovim-e2a578f40dbd4836330402a44844c7ef8a0df5c5.zip |
unittests: Do not import libnvim or headers in main process
Slows down unit tests much, but gets rid of as much preserved state as possible.
Diffstat (limited to 'test/unit/tempfile_spec.lua')
-rw-r--r-- | test/unit/tempfile_spec.lua | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index f435c950e9..27bd8729f9 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -1,20 +1,25 @@ -local lfs = require 'lfs' -local helpers = require 'test.unit.helpers' +local lfs = require('lfs') +local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) -local os = helpers.cimport './src/nvim/os/os.h' -local tempfile = helpers.cimport './src/nvim/fileio.h' +local eq = helpers.eq +local neq = helpers.neq +local cimport = helpers.cimport +local deferred_call = helpers.deferred_call +local separate_cleanup = helpers.separate_cleanup + +local lib = cimport('./src/nvim/os/os.h', './src/nvim/fileio.h') describe('tempfile related functions', function() - before_each(function() - tempfile.vim_deltempdir() - end) - after_each(function() - tempfile.vim_deltempdir() + before_each(deferred_call(function() + lib.vim_deltempdir() + end)) + separate_cleanup(function() + lib.vim_deltempdir() end) local vim_gettempdir = function() - return helpers.ffi.string(tempfile.vim_gettempdir()) + return helpers.ffi.string(lib.vim_gettempdir()) end describe('vim_gettempdir', function() @@ -23,7 +28,7 @@ describe('tempfile related functions', function() assert.True(dir ~= nil and dir:len() > 0) -- os_file_is_writable returns 2 for a directory which we have rights -- to write into. - assert.equals(os.os_file_is_writable(helpers.to_cstr(dir)), 2) + eq(lib.os_file_is_writable(helpers.to_cstr(dir)), 2) for entry in lfs.dir(dir) do assert.True(entry == '.' or entry == '..') end @@ -32,25 +37,25 @@ describe('tempfile related functions', function() itp('returns the same directory on each call', function() local dir1 = vim_gettempdir() local dir2 = vim_gettempdir() - assert.equals(dir1, dir2) + eq(dir1, dir2) end) end) describe('vim_tempname', function() local vim_tempname = function() - return helpers.ffi.string(tempfile.vim_tempname()) + return helpers.ffi.string(lib.vim_tempname()) end itp('generate name of non-existing file', function() local file = vim_tempname() assert.truthy(file) - assert.False(os.os_path_exists(file)) + assert.False(lib.os_path_exists(file)) end) itp('generate different names on each call', function() local fst = vim_tempname() local snd = vim_tempname() - assert.not_equals(fst, snd) + neq(fst, snd) end) itp('generate file name in Neovim own temp directory', function() |